-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a better Single File Application example #20424
base: 7.2
Are you sure you want to change the base?
Conversation
The original example didn't work because it didn't return the integer value. I expanded the example to something that's marginally useful (and more real-world).
I also add a filename and instructions for running it. I don't understand the second part of the page, where the command can be registered. Is that for bin/console? Or if you want to have your own set of commands, like bin/my-files, where you would have file-counter and others, like bin/console has? |
This PR contains too many commits. You should be able to rebase it on |
I switched back to |
Now run it with | ||
|
||
php bin/file-counter.php | ||
|
||
php bin/file-counter.php --all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now run it with | |
php bin/file-counter.php | |
php bin/file-counter.php --all | |
Now run it with: | |
.. code-block:: bash | |
php bin/file-counter.php | |
or | |
.. code-block:: bash | |
php bin/file-counter.php --all |
// output arguments and options | ||
$dir = realpath($input->getArgument('dir')); | ||
$all = $input->getOption('all'); | ||
$finder = (new Symfony\Component\Finder\Finder()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a use statement
; | ||
$count = iterator_count($finder); | ||
$output->writeln( "$dir has $count " . | ||
($all ? "files" : "files in source control")); | ||
return SingleCommandApplication::SUCCESS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; | |
$count = iterator_count($finder); | |
$output->writeln( "$dir has $count " . | |
($all ? "files" : "files in source control")); | |
return SingleCommandApplication::SUCCESS; | |
; | |
$count = iterator_count($finder); | |
$output->writeln("$dir has $count " . ($all ? "files" : "files in source control")); | |
return SingleCommandApplication::SUCCESS; |
<?php // bin/file-counter.php | ||
require __DIR__.'/../vendor/autoload.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<?php // bin/file-counter.php | |
require __DIR__.'/../vendor/autoload.php'; | |
// bin/file-counter.php | |
<?php | |
require __DIR__.'/../vendor/autoload.php'; |
The original example didn't work because it was expecting a return value. This example is a bit more real-world.