Exemple #1
0
 public function __construct()
 {
     $routes = [['name' => '<config> <output_file> [--strip]', 'short_description' => "Generate class cache based on <config> file into <output_file>.", 'handler' => [$this, 'generateDump']]];
     parent::__construct('Cache dumper', 1.0, $routes, Console::getInstance());
     $this->removeRoute('autocomplete');
     $this->removeRoute('help');
     $this->removeRoute('version');
 }
 /**
  * Initialize the application from single config
  *
  * @param array|Traversable $config Application config
  * @param Console $console Console adapter to use within the application
  * @param Dispatcher $dispatcher Configured dispatcher mapping routes to callables
  */
 public function __construct($config, Console $console, Dispatcher $dispatcher = null)
 {
     if (!isset($config['name']) || !isset($config['version']) || !isset($config['routes'])) {
         throw new \InvalidArgumentException('Config must contains not empty fields: name, version, routes');
     }
     if (!is_array($config['routes']) && !$config['routes'] instanceof Traversable) {
         throw new \InvalidArgumentException('Config must be provided as an array or Traversable object');
     }
     parent::__construct($config['name'], $config['version'], $config['routes'], $console, $dispatcher);
     if (isset($config['service_manager']) && is_array($config['service_manager'])) {
         $sm = new ServiceManager(new Config($config['service_manager']));
         $sm->setService('ApplicationConfig', $config);
         $this->setServiceLocator($sm);
         $this->getDispatcher()->setServiceLocator($sm);
     }
 }
Exemple #3
0
 /**
  * Overwritten constructor to simplify application instantiation
  *
  * @param string $routes
  * @param ConsoleInterface $console
  * @param Dispatcher $dispatcher
  */
 public function __construct($routes, ConsoleInterface $console, Translator $translator = null, Dispatcher $dispatcher = null)
 {
     if ($translator) {
         $this->translator = $translator;
         $routes = $this->translateRoutes($routes);
     }
     // call parent constructor
     parent::__construct(self::NAME . ' - ' . self::SLOGAN, self::VERSION, $routes, $console, $dispatcher);
     // initialize routes
     $routes = array();
     // get all routes except standard version route
     foreach ($this->routeCollection->getRouteNames() as $routeName) {
         if ($routeName == 'version') {
             continue;
         }
         $routes[$routeName] = $this->routeCollection->getRoute($routeName);
     }
     // create new RouteCollection instance and add routes to it
     $this->routeCollection = new RouteCollection();
     $this->setRoutes($routes);
     // change banner and footer
     $this->setBanner(array($this, 'writeApplicationBanner'));
     $this->setFooter(array($this, 'writeApplicationFooter'));
 }
 /**
  * @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);
<?php

/**
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
 * @copyright Copyright (c) 2015 Matthew Weier O'Phinney (https://mwop.net)
 */
require __DIR__ . '/../vendor/autoload.php';
use Zend\Console\Console;
use ZF\Console\Application;
use ZF\Console\Dispatcher;
$version = '@package_version@';
// Reset version if not rewritten (which happens when using
// a phar)
$version = $version === '@' . 'package_version' . '@' ? 'dev-master' : $version;
$application = new Application('Component Installer', $version, include __DIR__ . '/../config/routes.php', Console::getInstance(), new Dispatcher());
$exit = $application->run();
exit($exit);
Exemple #7
0
}], ['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);
 /**
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $command = $route->getMatchedParam('command', null);
     $this->application->showUsageMessage($command);
     return 0;
 }
Exemple #9
0
 protected function setupAutocompleteCommand(RouteCollection $routeCollection, Dispatcher $dispatcher)
 {
     if ($dispatcher instanceof AppDispatcher) {
         return parent::setupAutocompleteCommand($routeCollection, $dispatcher);
     }
 }
Exemple #10
-1
 /**
  * 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);
 }