If no arguments are provided, pulls them from $argv, stripping the
script argument first.
If the argument list is empty, displays a usage message.
If arguments are provided, but no routes match, displays a usage message
and returns a status of 1.
Otherwise, attempts to dispatch the matched command, returning the
execution status.
/** * @group 7 */ public function testHandlersConfiguredViaRoutesDoNotOverwriteThoseAlreadyInDispatcher() { $phpunit = $this; $dispatcher = new Dispatcher(); $dispatcher->map('test', function ($route, $console) use($phpunit) { $phpunit->assertEquals('test', $route->getName()); return 2; }); $routes = [['name' => 'test', 'route' => 'test', 'description' => 'Test handler capabilities', 'short_description' => 'Test handler capabilities', 'handler' => function ($route, $console) use($phpunit) { $phpunit->fail('Handler from route configuration was invoked when it should not be'); return 3; }]]; $application = new Application('ZFConsoleApplication', $this->version, $routes, $this->console, $dispatcher); $this->assertEquals(2, $application->run(['test'])); }
#!/usr/bin/env php <?php /** * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com) */ use Zend\Console\Console; use ZF\Console\Application; use ZF\Deploy\SelfUpdate; switch (true) { case file_exists(__DIR__ . '/../vendor/autoload.php'): // Installed standalone require __DIR__ . '/../vendor/autoload.php'; break; case file_exists(__DIR__ . '/../../../autoload.php'): // Installed as a Composer dependency require __DIR__ . '/../../../autoload.php'; break; case file_exists('vendor/autoload.php'): // As a Composer dependency, relative to CWD require 'vendor/autoload.php'; break; default: throw new RuntimeException('Unable to locate Composer autoloader; please run "composer install".'); } define('VERSION', '1.0.3-dev'); $routes = (include __DIR__ . '/../config/routes.php'); $application = new Application('ZFDeploy', VERSION, $routes, Console::getInstance()); $application->getDispatcher()->map('self-update', new SelfUpdate(VERSION)); $exit = $application->run(); exit($exit);
}], ['name' => 'create-asset-symlinks', 'description' => 'Symlink assets installed by npm into the public tree.', 'short_description' => 'Symlink assets.', 'handler' => function ($route, $console) use($container) { $handler = $container->get(MwopConsole\CreateAssetSymlinks::class); return $handler($route, $console); }], ['name' => 'feed-generator', 'route' => '[--outputDir=] [--baseUri=]', 'description' => 'Generate feeds (RSS and Atom) for the blog, including all tags.', 'short_description' => 'Generate blog feeds.', 'options_descriptions' => ['--outputDir' => 'Directory to which to write the feeds (defaults to data/feeds)', '--baseUri' => 'Base URI for the site (defaults to https://mwop.net)'], 'defaults' => ['outputDir' => 'data/feeds', 'baseUri' => 'https://mwop.net'], 'handler' => function ($route, $console) use($container) { $handler = $container->get(Blog\Console\FeedGenerator::class); return $handler($route, $console); }], ['name' => 'generate-search-data', 'route' => '[--path=]', 'description' => 'Generate site search data based on blog posts.', 'short_description' => 'Generate site search data.', 'options_descriptions' => ['--path' => 'Base path of the application; posts are expected at $path/data/blog/ ' . 'and search terms will be written to $path/public/js/search_terms.json'], 'defaults' => ['path' => realpath(getcwd())], 'handler' => function ($route, $console) use($container) { $handler = $container->get(Blog\Console\GenerateSearchData::class); return $handler($route, $console); }], ['name' => 'github-links', 'route' => '[--output=] [--template=]', 'description' => 'Fetch GitHub activity stream and generate links for the home page.', 'short_description' => 'Fetch GitHub activity stream.', 'options_descriptions' => ['--output' => 'Output file to which to write links', '--template' => 'Template string to use when generating link output'], 'defaults' => ['output' => 'data/github-links.mustache'], 'handler' => function ($route, $console) use($container) { $handler = $container->get(Github\Console\Fetch::class); return $handler($route, $console); }], ['name' => 'homepage-feeds', 'route' => '', 'description' => 'Fetch feed data for homepage activity stream.', 'short_description' => 'Fetch homepage feed data.', 'defaults' => ['path' => realpath(getcwd())], 'handler' => function ($route, $console) use($container) { $handler = $container->get(MwopConsole\FeedAggregator::class); return $handler($route, $console); }], ['name' => 'prep-offline-pages', 'route' => '[--serviceWorker=]', 'description' => 'Prepare the offline pages list for the service-worker.js file.', 'short_description' => 'Prep offline page cache list', 'options_descriptions' => ['--serviceWorker' => 'Path to the service-worker.js file'], 'defaults' => ['serviceWorker' => realpath(getcwd()) . '/public/service-worker.js'], 'handler' => function ($route, $console) use($container) { $handler = $container->get(MwopConsole\PrepOfflinePages::class); return $handler($route, $console); }], ['name' => 'seed-blog-db', 'route' => '[--path=] [--dbPath=] [--postsPath=] [--authorsPath=]', 'description' => 'Re-create the blog post database from the post entities.', 'short_description' => 'Generate and seed the blog post database.', 'options_descriptions' => ['--path' => 'Base path of the application; defaults to current working dir', '--dbPath' => 'Path to the database file, relative to the --path; defaults to data/posts.db', '--postsPath' => 'Path to the blog posts, relative to the --path; defaults to data/blog', '--authorsPath' => 'Path to the author metadata files, relative to the --path; ' . 'defaults to data/blog/authors'], 'defaults' => ['path' => realpath(getcwd()), 'postsPath' => 'data/blog/', 'authorsPath' => 'data/blog/authors', 'dbPath' => 'data/posts.db'], 'handler' => function ($route, $console) use($container) { $handler = $container->get(Blog\Console\SeedBlogDatabase::class); return $handler($route, $console); }], ['name' => 'tag-cloud', 'route' => '[--output=]', 'description' => 'Generate a Mustache template containing the tag cloud for the blog.', 'short_description' => 'Generate tag cloud.', 'options_descriptions' => ['--output' => 'Output file to which to write the tag cloud'], 'defaults' => ['output' => 'data/tag-cloud.mustache'], 'handler' => function ($route, $console) use($container) { $handler = $container->get(Blog\Console\TagCloud::class); return $handler($route, $console); }], ['name' => 'use-dist-templates', 'route' => '[--path=]', 'description' => 'Enable usage of distribution templates (optimizing CSS and JS).', 'short_description' => 'Use dist templates.', 'options_descriptions' => ['--path' => 'Base path of the application; templates are expected at $path/templates/'], 'defaults' => ['path' => realpath(getcwd())], 'handler' => function ($route, $console) use($container) { $handler = $container->get(MwopConsole\UseDistTemplates::class); return $handler($route, $console); }]]; $app = new Application('mwop.net', VERSION, $routes, Console::getInstance()); $exit = $app->run(); exit($exit);
/** * Run the application * * Make sure that banner and footer are not shown for autoload command * * @param array $args * @return int */ public function run(array $args = null) { global $argv; if (isset($argv[1]) && $argv[1] == 'autocomplete' && !isset($argv[2])) { $this->setBanner(function () { return 0; }); $this->setFooter(function () { return 0; }); } return parent::run($args); }