Inheritance: extends Zend\Console\RouteMatcher\DefaultRouteMatcher
Esempio n. 1
0
 public function __invoke(Route $route, Console $console) : int
 {
     $console->writeLine('Aggregating feed data...', Color::GREEN);
     file_put_contents($this->generateFilename($route->getMatchedParam('path')), $this->generateContent($this->getEntries($console)));
     $console->writeLine('[DONE]', Color::GREEN);
     return 0;
 }
Esempio n. 2
0
 public function __invoke(Route $route, Console $console) : int
 {
     $basePath = $route->getMatchedParam('path');
     $path = realpath($basePath) . '/data/blog';
     $cache = realpath($basePath) . '/data/cache/posts';
     $baseUri = new Uri('https://mwop.net');
     $middleware = $this->blogMiddleware;
     $console->writeLine('Generating static cache for blog posts', Color::GREEN);
     // Prepare final handler for middleware
     $failed = false;
     $done = function ($req, $res, $err = null) use(&$failed) {
         $failed = $err ? true : false;
     };
     $parser = new Parser(null, new CommonMarkParser());
     foreach (new MarkdownFileFilter($path) as $fileInfo) {
         $document = $parser->parse(file_get_contents($fileInfo->getPathname()));
         $metadata = $document->getYAML();
         $message = '    ' . $metadata['id'];
         $length = strlen($message);
         $width = $console->getWidth();
         $console->write($message, Color::BLUE);
         $canonical = $baseUri->withPath(sprintf('/blog/%s.html', $metadata['id']));
         $request = (new Request(new PsrRequest([], [], $canonical, 'GET')))->withUri($canonical)->withAttribute('id', $metadata['id']);
         $failed = false;
         $response = $middleware($request, new Response(), $done);
         if (!$failed) {
             $this->cacheResponse($metadata['id'], $cache, $response->getBody());
         }
         $this->reportComplete($console, $width, $length, !$failed);
     }
     $console->writeLine('ALL DONE', Color::GREEN);
     return 0;
 }
 /**
  * @param Route $route
  */
 protected function setAdjectivesFromRoute(Route $route)
 {
     $adjectives = $route->getMatchedParam('adjectives');
     if (!empty($adjectives)) {
         Haikunator::$ADJECTIVES = $this->getValuesFromFileIfExists($adjectives);
     }
 }
Esempio n. 4
0
 public function __invoke(Route $route, Console $console) : int
 {
     $basePath = $route->getMatchedParam('path');
     $postsPath = $route->getMatchedParam('postsPath');
     $authorsPath = $route->getMatchedParam('authorsPath');
     $dbPath = $route->getMatchedParam('dbPath');
     $message = 'Generating blog post database';
     $length = strlen($message);
     $width = $console->getWidth();
     $console->write($message, Color::BLUE);
     $pdo = $this->createDatabase($dbPath, $console);
     $path = sprintf('%s/%s', realpath($basePath), ltrim($postsPath));
     $trim = strlen(realpath($basePath)) + 1;
     $parser = new Parser(null, new CommonMarkParser());
     $statements = [];
     foreach (new MarkdownFileFilter($path) as $fileInfo) {
         $path = $fileInfo->getPathname();
         $document = $parser->parse(file_get_contents($path));
         $metadata = $document->getYAML();
         $html = $document->getContent();
         $parts = explode($this->postDelimiter, $html, 2);
         $body = $parts[0];
         $extended = isset($parts[1]) ? $parts[1] : '';
         $author = $this->getAuthor($metadata['author'], $authorsPath);
         $template = empty($statements) ? $this->initial : $this->item;
         $statements[] = sprintf($template, $pdo->quote($metadata['id']), $pdo->quote(substr($path, $trim)), (new DateTime($metadata['created']))->getTimestamp(), (new DateTime($metadata['updated']))->getTimestamp(), $pdo->quote($metadata['title']), $pdo->quote($author['id']), $metadata['draft'] ? 1 : 0, $metadata['public'] ? 1 : 0, $pdo->quote($body), $pdo->quote(sprintf('|%s|', implode('|', $metadata['tags']))));
     }
     $pdo->exec(implode("\n", $statements));
     return $this->reportSuccess($console, $width, $length);
 }
Esempio n. 5
0
 /**
  * Tag a new ZF2 LTS release.
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $opts = $route->getMatches();
     $minor = $opts['version'];
     $patchfiles = $opts['patchfile'];
     $this->verbose = $opts['verbose'] || $opts['v'];
     $currentVersion = $this->detectVersion($minor, $console);
     // checkout release-$minor branch based on release-$currentVersion
     if (0 !== $this->exec(sprintf('%s checkout -b release-%s release-%s', $this->git, $minor, $currentVersion), $console)) {
         $console->writeLine(sprintf('[ERROR] Could not create new branch release-%s based on tag release-%s!', $minor, $currentVersion), Color::WHITE, Color::RED);
         return 1;
     }
     // apply patchfile
     foreach ($patchfiles as $patchfile) {
         if (0 !== $this->exec(sprintf('%s am < %s', $this->git, $patchfile), $console)) {
             $console->writeLine(sprintf('[ERROR] Could not cleanly apply patchfile "%s"!', $patchfile), Color::WHITE, Color::RED);
             return 1;
         }
     }
     // Create message for release
     $message = $this->getCommitMessages($currentVersion);
     if (false === $message) {
         $console->writeLine('[ERROR] Could not retrieve patch messages!', Color::WHITE, Color::RED);
         return 1;
     }
     $nextVersion = $this->incrementVersion($currentVersion);
     $message = sprintf("Zend Framework %s\n\n%s", $nextVersion, $message);
     $console->writeLine('[DONE] Please verify the patch, and then execute:', Color::GREEN);
     $console->writeLine(sprintf('    git tag -s -m "%s" release-%s', $message, $nextVersion));
 }
Esempio n. 6
0
 /**
  * @param \ZF\Console\Route $route
  * @param ConsoleWriter $consoleWriter
  * @return Environment
  */
 protected function loadEnvironment(Route $route, ConsoleWriter $consoleWriter)
 {
     $configPath = $route->getMatchedParam('config-file', getcwd() . DIRECTORY_SEPARATOR . 'processing.config.php');
     $additionalConfig = $route->getMatchedParam('config', json_encode([]));
     $additionalConfig = json_decode($additionalConfig, true);
     if (is_null($additionalConfig)) {
         $consoleWriter->writeError("Provided config is not a valid json string");
         $consoleWriter->writeError(json_last_error_msg());
         return self::MESSAGE_PROCESSING_FAILED;
     }
     if (file_exists($configPath)) {
         $config = (include $configPath);
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } elseif (file_exists($configPath . '.dist')) {
         $config = (include $configPath . '.dist');
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } else {
         $consoleWriter->writeInfo('No config file specified.');
         if (empty($additionalConfig)) {
             $consoleWriter->writeInfo('Falling back to default config');
         } else {
             $consoleWriter->writeInfo('Using config from argument');
         }
         return $additionalConfig;
     }
     $config = ArrayUtils::merge($config, $additionalConfig);
     $env = Environment::setUp($config);
     $env->getEventStore()->getActionEventDispatcher()->attachListenerAggregate(new PersistedEventsConsoleWriter($consoleWriter));
     return $env;
 }
Esempio n. 7
0
 public static function run(Route $route, AdapterInterface $console, $container)
 {
     $error = 0;
     $oldPath = $route->getMatchedParam("old", "/tmp/bench/current.json");
     $newPath = $route->getMatchedParam("new", "./athletic_output.json");
     $old = json_decode(file_get_contents($oldPath), true);
     $new = json_decode(file_get_contents($newPath), true);
     $comparator = $container->get(ComparatorService::class);
     foreach ($new as $group => $values) {
         if (!array_key_exists($group, $old)) {
             continue;
         }
         $newAvg = (double) $values['trigger']['avg'];
         $oldAvg = (double) $old[$group]['trigger']['avg'];
         $perct = $comparator->perctDecrease($newAvg, $oldAvg);
         if ($perct >= 5) {
             $error = 1;
             $console->writeLine("{$group} +{$perct}%", ColorInterface::RED);
         } elseif ($perct < -10) {
             $console->writeLine("{$group} {$perct}%", ColorInterface::GREEN);
         } else {
             $console->writeLine("{$group} {$perct}%", ColorInterface::NORMAL);
         }
     }
     return $error;
 }
Esempio n. 8
0
 public function __invoke(Route $route, AdapterInterface $console)
 {
     $params = $this->request->getContent();
     $type = $params[1] ?? null;
     $path = $params[2] ?? null;
     $zeusUrl = $params[3] ?? null;
     $opts = $route->getMatches();
     $verbose = $opts['verbose'] || $opts['v'];
     //$quiet = $opts['quiet'] || $opts['q'];
     if (!file_exists($path)) {
         $console->writeLine("Path {$path} not found.", ColorInterface::RED);
         return;
     }
     $this->apiClient->getZendClient()->setUri($zeusUrl);
     foreach (glob($path . '/*.kharon') as $filename) {
         if ($verbose) {
             $console->writeLine("Sending {$filename} ...", ColorInterface::BLUE);
         }
         $data = file_get_contents($filename);
         $this->send($data, sprintf('/v1/%s/collect', $type));
         unlink($filename);
     }
     if ($verbose) {
         $console->writeLine('Done.', ColorInterface::GREEN);
     }
 }
 /**
  * @dataProvider staticParamDataProvider
  */
 public function testStaticParams($name, array $value)
 {
     $map = [[$name, null, $value]];
     $this->route->expects($this->any())->method('getMatchedParam')->willReturnMap($map);
     $this->command->__invoke($this->route, $this->console);
     $this->assertEquals($value, Haikunator::${strtoupper($name)});
 }
Esempio n. 10
0
 /**
  * Release components.
  *
  * Uses the version, exclude, basePath, and verbose (or "v") flags provided
  * with the route to tag the next maintenance release of all components
  * (with the exception of those in the exclude list).
  *
  * Changes directory to the basePath prior to tagging each component.
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $opts = $route->getMatches();
     $minor = $opts['version'];
     $version = $minor;
     $exclude = $opts['exclude'];
     $path = $opts['basePath'];
     $this->verbose = $opts['verbose'] || $opts['v'];
     $this->emit(sprintf("Using git: %s\n", $this->git), $console, Color::BLUE);
     chdir($path);
     foreach ($this->components as $component) {
         if (in_array($component, $exclude, true)) {
             $this->emit(sprintf("[SKIP] %s\n", $component), $console, Color::GREEN);
             continue;
         }
         $this->emit(sprintf("[START] %s\n", $component), $console, Color::GREEN);
         if (!is_dir($component)) {
             $console->writeLine(sprintf('[ERROR] Component directory for "%s" does not exist!', $component), Color::WHITE, Color::RED);
             continue;
         }
         chdir($component);
         $version = $this->tagComponent($component, $minor, $version, $console);
         chdir($path);
         $this->emit(sprintf('[DONE] %s tagged at version %s', $component, $version), $console, Color::GREEN);
     }
     $console->writeLine('');
     $console->writeLine('[DONE] Please verify tags and push the following tag:', Color::GREEN);
     $console->writeLine('       release-' . $version);
     return 0;
 }
 /**
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $path = $route->getMatchedParam('path', realpath(getcwd()));
     $installPath = $this->createComponentInstallerDirectory($path);
     if (false === $installPath) {
         $console->writeLine(sprintf('Unable to create component-installer directory in selected path (%s); aborting', $path), Color::RED);
         return 1;
     }
     $copied = copy(realpath(__DIR__ . '/../ComponentInstaller.php'), sprintf('%s/ComponentInstaller.php', $installPath));
     if (false === $copied) {
         $console->writeLine(sprintf('Unable to copy ComponentInstaller.php to %s/component-installer/; aborting', $path), Color::RED);
         return 1;
     }
     $composer = $this->getComposer($path);
     if (false === $composer || empty($composer)) {
         $console->writeLine(sprintf('Unable to read/parse %s/composer.json; aborting', $path), Color::RED);
         return 1;
     }
     $composer = $this->injectAutoloadEntry($composer);
     $composer = $this->injectScripts($composer);
     if (false === $this->writeComposer($composer, $path)) {
         $console->writeLine(sprintf('Unable to write updated %s/composer.json; aborting', $path), Color::RED);
         return 1;
     }
     $console->writeLine('ComponentInstaller installed!', Color::GREEN);
     return 0;
 }
Esempio n. 12
0
 /**
  * @param string $route
  * @param array $constraints
  * @param array $defaults
  * @param array $aliases
  * @param null|array $filters
  * @param null|array $validators
  */
 public function addRouteSpec(array $spec)
 {
     if (!isset($spec['name'])) {
         throw new InvalidArgumentException('Route specification is missing a route name');
     }
     $name = $spec['name'];
     if (!isset($spec['route'])) {
         $spec['route'] = $spec['name'];
     }
     $routeString = $this->prependRouteWithCommand($name, $spec['route'], array_key_exists('prepend_command_to_route', $spec) ? $spec['prepend_command_to_route'] : true);
     $constraints = isset($spec['constraints']) && is_array($spec['constraints']) ? $spec['constraints'] : array();
     $defaults = isset($spec['defaults']) && is_array($spec['defaults']) ? $spec['defaults'] : array();
     $aliases = isset($spec['aliases']) && is_array($spec['aliases']) ? $spec['aliases'] : array();
     $filters = isset($spec['filters']) && is_array($spec['filters']) ? $spec['filters'] : null;
     $validators = isset($spec['validators']) && is_array($spec['validators']) ? $spec['validators'] : null;
     $description = isset($spec['description']) && is_string($spec['description']) ? $spec['description'] : '';
     $shortDescription = isset($spec['short_description']) && is_string($spec['short_description']) ? $spec['short_description'] : '';
     $optionsDescription = isset($spec['options_descriptions']) && is_array($spec['options_descriptions']) ? $spec['options_descriptions'] : array();
     $filters = $this->prepareFilters($filters);
     $validators = $this->prepareValidators($validators);
     $route = new Route($name, $routeString, $constraints, $defaults, $aliases, $filters, $validators);
     $route->setDescription($description);
     $route->setShortDescription($shortDescription);
     $route->setOptionsDescription($optionsDescription);
     $this->addRoute($route);
     return $this;
 }
Esempio n. 13
0
 /**
  * Perform all operations
  *
  * Facade method that accepts incoming CLI arguments, parses them, and
  * determines what workflows to execute.
  *
  * @param  Route   $route
  * @param  Console $console
  * @return int     Exit status
  */
 public function __invoke(Route $route, Console $console)
 {
     $this->resetStateForExecution($console);
     $opts = (object) $route->getMatches();
     if (!$this->validatePackage($opts->package, $opts)) {
         return $this->exitCode;
     }
     if (!$this->validateApplicationPath($opts->target, $opts)) {
         return $this->exitCode;
     }
     if (!$this->validateModules($opts->modules, $opts->target)) {
         return $this->exitCode;
     }
     $console->writeLine(sprintf('Creating package "%s"...', $opts->package), Color::BLUE);
     $tmpDir = $this->createTmpDir();
     if (false === $tmpDir) {
         return $this->exitCode;
     }
     $tmpDir = $this->prepareZpk($tmpDir, basename($opts->package, '.' . $opts->format), $opts->version, $opts->format, $opts->deploymentxml, $opts->zpkdata, $opts->appConfigPath);
     if (false === $tmpDir) {
         return $this->exitCode;
     }
     $this->cloneApplication($opts->target, $tmpDir, $opts->gitignore, $opts->vendor, $opts->modules, $opts->configs);
     $this->copyModules($opts->modules, $opts->target, $tmpDir);
     if (false === $this->executeComposer($opts->vendor, $opts->composer, $tmpDir)) {
         return $this->exitCode;
     }
     $this->removeTestDir($tmpDir . '/vendor');
     if (false === $this->createPackage($opts->package, $tmpDir, $opts->format)) {
         return $this->exitCode;
     }
     self::recursiveDelete($opts->format === 'zpk' ? dirname($tmpDir) : $tmpDir);
     $this->console->writeLine(sprintf('[DONE] Package %s successfully created (%d bytes)', $opts->package, filesize($opts->package)), Color::GREEN);
     return self::INFO_NO_ERROR;
 }
Esempio n. 14
0
 /**
  *  Test path param
  */
 public function testPathParamExistingPath()
 {
     $paramValueMap = [['workingPath', null, '/tmp']];
     $this->route->method('getMatchedParam')->will($this->returnValueMap($paramValueMap));
     $task = new WorkingPath();
     $result = $task($this->route, $this->console, $this->parameters);
     $this->assertEquals(0, $result);
     $this->assertEquals('/tmp', $this->parameters->workingPath);
 }
Esempio n. 15
0
 /**
  * Rewrite the patchfile.
  *
  * - --patchfile - original patch
  * - --target - filename to save new patch to
  * - --component - component for which the patch was written
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $opts = $route->getMatches();
     $patchfile = $opts['patchfile'];
     $target = $opts['target'];
     $component = $opts['component'];
     if ($component === 'zend-i18n-resources') {
         return $this->rewriteResources($patchfile, $target, $console);
     }
     return $this->rewrite($component, $patchfile, $target, $console);
 }
Esempio n. 16
0
 public function __invoke(Route $route, Console $console) : int
 {
     $serviceWorker = $route->getMatchedParam('serviceWorker');
     $console->writeLine('Updating service worker default offline pages');
     $paths = $this->defaultPaths;
     foreach ($this->generatePaths() as $path) {
         $paths[] = $path;
     }
     $this->updateServiceWorker($serviceWorker, $paths);
     $console->writeLine('[DONE]');
     return 0;
 }
Esempio n. 17
0
 /**
  * Start command processing.
  *
  * @param Route   $route
  * @param Console $console
  *
  * @return mixed
  */
 public function __invoke(Route $route, Console $console)
 {
     $this->route = $route;
     $this->console = $console;
     $this->path = realpath($this->route->getMatchedParam('path', getcwd()));
     if (!is_dir($this->path)) {
         $this->wlError('Invalid directory provided!');
         exit(2);
     }
     $this->path = str_replace(DIRECTORY_SEPARATOR, '/', $this->path);
     return $this->processCommand();
 }
Esempio n. 18
0
 public function __invoke(Route $route, Console $console) : int
 {
     $path = $route->getMatchedParam('path');
     $console->writeLine('Enabling dist templates... ', Color::BLUE);
     foreach ($this->distFileMap as $source => $target) {
         $source = sprintf('%s/%s', $path, $source);
         $target = sprintf('%s/%s', $path, $target);
         copy($source, $target);
     }
     $console->write('[DONE] ', Color::GREEN);
     $console->writeLine('Enabling dist templates');
     return 0;
 }
Esempio n. 19
0
 public function __invoke(Route $route, Console $console) : int
 {
     $message = 'Creating tag cloud';
     $length = strlen($message);
     $width = $console->getWidth();
     $console->write($message, Color::BLUE);
     if (!$route->matchedParam('output')) {
         return $this->reportError($console, $width, $length, 'Missing output file');
     }
     $output = $route->getMatchedParam('output');
     $cloud = $this->mapper->fetchTagCloud();
     $markup = sprintf("<h4>Tag Cloud</h4>\n<div class=\"cloud\">%s</div>", $cloud->render());
     file_put_contents($output, $markup);
     return $this->reportSuccess($console, $width, $length);
 }
Esempio n. 20
0
 /**
  * Handle the incoming console request
  */
 public function __invoke(Route $route, Console $console) : int
 {
     if (!$route->matchedParam('output')) {
         return $this->reportError($console, $width, $length, 'Missing output file');
     }
     $message = 'Retrieving Github activity links';
     $length = strlen($message);
     $width = $console->getWidth();
     $console->write($message, Color::BLUE);
     try {
         $data = $this->reader->read();
     } catch (Throwable $e) {
         return $this->reportError($console, $width, $length, $e);
     }
     file_put_contents($route->getMatchedParam('output'), $this->createContentFromData($data, $route->getMatchedParam('template', $this->outputTemplateString)));
     return $this->reportSuccess($console, $width, $length);
 }
Esempio n. 21
0
 public function __invoke(Route $route, Console $console) : int
 {
     $console->write('Clearing static cache... ');
     $rdi = new RecursiveDirectoryIterator(sprintf(self::PATH_TEMPLATE, $route->getMatchedParam('path')));
     $rii = new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::CHILD_FIRST | RecursiveIteratorIterator::LEAVES_ONLY);
     foreach ($rii as $file) {
         if (!$file instanceof SplFileInfo || $file->isDir()) {
             continue;
         }
         if ($file->getFilename() === '.placeholder') {
             continue;
         }
         unlink($file->getRealPath());
     }
     $console->writeLine('[DONE]');
     return 0;
 }
Esempio n. 22
0
 /**
  *  Test removeFactory param
  */
 public function testRemoveFactoryParam()
 {
     $paramValueMap = [['removeFactory', null, true]];
     $this->route->method('getMatchedParam')->will($this->returnValueMap($paramValueMap));
     $task = new Params();
     $result = $task($this->route, $this->console, $this->parameters);
     $this->assertEquals(0, $result);
     $this->assertTrue($this->parameters->paramRemoveFactory);
 }
Esempio n. 23
0
 public function __invoke(Route $route, Console $console) : int
 {
     $basePath = $route->getMatchedParam('path');
     $path = realpath($basePath) . '/data/blog';
     $console->writeLine('Generating search metadata', Color::BLUE);
     $documents = [];
     $parser = new Parser();
     foreach (new MarkdownFileFilter($path) as $fileInfo) {
         $document = $parser->parse(file_get_contents($fileInfo->getPathname()), false);
         $metadata = $document->getYAML();
         $content = $document->getContent();
         $documents[] = ['id' => sprintf('/blog/%s.html', $metadata['id']), 'tags' => implode(' ', $metadata['tags']), 'title' => $metadata['title'], 'content' => $content];
     }
     file_put_contents(realpath($basePath) . '/public/js/search_terms.json', json_encode(['docs' => $documents], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
     $console->write('[DONE]', Color::GREEN);
     $console->writeLine(' Generating search metadata');
     return 0;
 }
Esempio n. 24
0
 public function generateDump(Route $route, AdapterInterface $console)
 {
     $configFile = $route->getMatchedParam('config');
     $outputFile = $route->getMatchedParam('output_file');
     $strip = (bool) $route->getMatchedParam('strip');
     $console->writeLine("Generating class cache from {$configFile} into {$outputFile}");
     if (!file_exists($configFile)) {
         throw new RuntimeException("Configuration file does not exist: {$configFile}");
     }
     $classes = (include $configFile);
     if (!is_array($classes)) {
         throw new RuntimeException("Configuration file does not contain array of class names");
     }
     if (!file_exists(dirname($outputFile))) {
         mkdir(dirname($outputFile), 0777, true);
     }
     $dumper = new ClassDumper();
     $cache = $dumper->dump($classes, $strip);
     file_put_contents($outputFile, "<?php\n" . $cache);
 }
Esempio n. 25
0
 public function __invoke(Route $route, Console $console) : int
 {
     $this->console = $console;
     $outputDir = $route->getMatchedParam('outputDir');
     $baseUri = $route->getMatchedParam('baseUri');
     $this->console->writeLine('Generating base feeds');
     $this->generateFeeds($outputDir . '/', $baseUri, 'Blog entries :: phly, boy, phly', 'blog', 'blog.feed', [], $this->mapper->fetchAll());
     $cloud = $this->mapper->fetchTagCloud();
     $tags = array_map(function ($item) {
         return $item->getTitle();
     }, iterator_to_array($cloud->getItemList()));
     foreach ($tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         $this->console->writeLine('Generating feeds for tag ' . $tag);
         $this->generateFeeds(sprintf('%s/%s.', $outputDir, $tag), $baseUri, sprintf('Tag: %s :: phly, boy, phly', $tag), 'blog.tag', 'blog.tag.feed', ['tag' => $tag], $this->mapper->fetchAllByTag($tag));
     }
     return 0;
 }
Esempio n. 26
0
 /**
  *  Test path param
  */
 public function testPathParamExistingPath()
 {
     $paramValueMap = array(array('path', null, '/tmp'));
     $this->route->method('getMatchedParam')->will($this->returnValueMap($paramValueMap));
     $task = new ProjectPath();
     $result = $task($this->route, $this->console, $this->parameters);
     $this->assertEquals(0, $result);
     $this->assertEquals('/tmp', $this->parameters->projectPath);
     $this->assertEquals('/tmp/module', $this->parameters->projectModuleDir);
     $this->assertEquals('/tmp/config', $this->parameters->projectConfigDir);
 }
Esempio n. 27
0
 public function dispatch(Route $route, ConsoleAdapter $console)
 {
     $name = $route->getName();
     if (!isset($this->commandMap[$name])) {
         $console->writeLine('');
         $console->writeLine(sprintf('Unhandled command "%s" invoked', $name), Color::WHITE, Color::RED);
         $console->writeLine('');
         $console->writeLine('The command does not have a registered handler.');
         return 1;
     }
     $callable = $this->commandMap[$name];
     if (!is_callable($callable) && is_string($callable)) {
         $callable = new $callable();
         if (!is_callable($callable)) {
             throw new RuntimeException(sprintf('Invalid command class specified for "%s"; class must be invokable', $name));
         }
         $this->commandMap[$name] = $callable;
     }
     $return = $this->container->call($callable, [$route, $console, $this->container]);
     return (int) $return;
 }
Esempio n. 28
0
 /**
  * Get the route parameters from the router config array
  *
  * @param  string                    $name
  * @return \ZF\Console\Route|boolean
  */
 protected function getRoute($name)
 {
     foreach ($this->routes as $spec) {
         if ($spec['name'] === $name) {
             $name = $spec['name'];
             $routeString = $spec['route'];
             $constraints = isset($spec['constraints']) && is_array($spec['constraints']) ? $spec['constraints'] : array();
             $defaults = isset($spec['defaults']) && is_array($spec['defaults']) ? $spec['defaults'] : array();
             $aliases = isset($spec['aliases']) && is_array($spec['aliases']) ? $spec['aliases'] : array();
             $filters = isset($spec['filters']) && is_array($spec['filters']) ? $spec['filters'] : null;
             $validators = isset($spec['validators']) && is_array($spec['validators']) ? $spec['validators'] : null;
             $description = isset($spec['description']) && is_string($spec['description']) ? $spec['description'] : '';
             $shortDescription = isset($spec['short_description']) && is_string($spec['short_description']) ? $spec['short_description'] : '';
             $optionsDescription = isset($spec['options_descriptions']) && is_array($spec['options_descriptions']) ? $spec['options_descriptions'] : array();
             $route = new Route($name, $routeString, $constraints, $defaults, $aliases, $filters, $validators);
             $route->setDescription($description);
             $route->setShortDescription($shortDescription);
             $route->setOptionsDescription($optionsDescription);
             return $route;
         }
     }
     return false;
 }
Esempio n. 29
0
 /**
  * Create a new local branch and bump the changelog version entry.
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $opts = $route->getMatches();
     $version = $opts['version'];
     $base = $opts['base'];
     $this->verbose = $opts['verbose'] || $opts['v'];
     // checkout version/bump branch based on $base
     if (0 !== $this->exec(sprintf('%s checkout -b version/bump %s', $this->git, $base), $console)) {
         $console->writeLine(sprintf('[ERROR] Could not create new version/bump branch based on branch %s!', $base), Color::WHITE, Color::RED);
         return 1;
     }
     // Update CHANGELOG.md file
     $this->updateChangelog($version);
     // Commit version bump
     $this->commitVersionBump($version, $console);
     $message = sprintf('[DONE] Please verify and merge the branch back to %s', $base);
     if ($base === 'master') {
         $message .= ' as well as develop';
     }
     $console->writeLine($message, Color::GREEN);
     $console->writeLine('Once done merging, remove this branch using:');
     $console->writeLine('    git branch -d version/bump');
     return 0;
 }
Esempio n. 30
0
 /**
  * Dispatches route
  *
  * @param Route $route
  * @param ConsoleAdapter $console
  * @throws RuntimeException
  * @return number
  */
 public function dispatch(Route $route, ConsoleAdapter $console)
 {
     $name = $route->getName();
     if (!isset($this->commandMap[$name])) {
         $console->writeLine('');
         $console->writeLine(sprintf('Unhandled command "%s" invoked', $name), Color::WHITE, Color::RED);
         $console->writeLine('');
         $console->writeLine('The command does not have a registered handler.');
         return 1;
     }
     $callable = $this->commandMap[$name];
     if (!is_callable($callable) && is_string($callable)) {
         $callable = new $callable();
         if (!is_callable($callable)) {
             throw new RuntimeException(sprintf('Invalid command class specified for "%s"; class must be invokable', $name));
         }
         $this->commandMap[$name] = $callable;
     }
     if ($this->getServiceLocator() !== null && $callable instanceof ServiceLocatorAwareInterface && $callable->getServiceLocator() === null) {
         $callable->setServiceLocator($this->getServiceLocator());
     }
     $return = call_user_func($callable, $route, $console);
     return (int) $return;
 }