Пример #1
0
 public function getConsoleBanner(Console $console)
 {
     $version = `git describe`;
     $name = 'YAWIK ' . trim($version);
     $width = $console->getWidth();
     return sprintf("==%1\$s==\n%2\$s%3\$s\n**%1\$s**\n", str_repeat('-', $width - 4), str_repeat(' ', floor(($width - strlen($name)) / 2)), $name);
 }
Пример #2
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);
     }
 }
Пример #3
0
 /**
  * List the components
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     array_walk($this->components, function ($component) use($console) {
         $console->writeLine($component);
     });
     return 0;
 }
Пример #4
0
 /**
  * Terminates line if the inline logging is started
  *
  * @return void
  */
 private function terminateLine()
 {
     if ($this->isInline) {
         $this->isInline = false;
         $this->console->writeLine('');
     }
 }
Пример #5
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;
 }
Пример #6
0
 protected function showResultTest($message, $bool, Console &$console)
 {
     // Print status
     $console->write($message);
     $bool ? $console->write('[OK]', ColorInterface::GREEN) : $console->write('[NOT OK]', ColorInterface::RED);
     $console->writeLine();
     return $bool;
 }
 public function __invoke(Route $route, ConsoleAdapter $console)
 {
     $params = $this->getParamsFromRoute($route);
     $params = $this->filterNullParams($params);
     $this->setNounsFromRoute($route);
     $this->setAdjectivesFromRoute($route);
     $console->writeLine($this->haikunator->__invoke($params));
 }
Пример #8
0
 /**
  * Report success
  *
  * @param \Zend\Console\Adapter\AdapterInterface $console
  * @param int $width
  * @param int $length
  * @return int
  */
 private function reportSuccess($console, $width, $length)
 {
     if ($length + 8 > $width) {
         $console->writeLine('');
         $length = 0;
     }
     $spaces = $width - $length - 8;
     $spaces = $spaces > 0 ? $spaces : 0;
     $console->writeLine(str_repeat('.', $spaces) . '[ DONE ]', Color::GREEN);
     return 0;
 }
Пример #9
0
 /**
  * Handle an exception
  *
  * On completion, exits with a non-zero status code.
  *
  * @param Exception $exception
  */
 public function __invoke(Exception $exception)
 {
     $message = $this->createMessage($exception);
     $this->console->writeLine('Application exception: ', Color::RED);
     $this->console->write($message);
     $this->console->writeLine('');
     // Exceptions always indicate an error status; however, most have a
     // code of zero; set it to 1 in such cases.
     $exitCode = $exception->getCode();
     $exitCode = $exitCode ?: 1;
     exit($exitCode);
 }
Пример #10
0
 public function __invoke(Route $route, Console $console) : int
 {
     $console->writeLine('Creating asset symlinks... ', Color::BLUE);
     foreach ($this->symlinkMap as $target => $link) {
         if (!file_exists($link)) {
             symlink($target, $link);
         }
     }
     $console->write('[DONE] ', Color::GREEN);
     $console->writeLine('Creating asset symlinks');
     return 0;
 }
Пример #11
0
 /**
  * @param ConsoleAdapter $console
  * @param array $line
  *
  * @return void
  */
 private function drawLine(ConsoleAdapter $console, array $line)
 {
     $remainingLength = $this->getWidth();
     foreach ($line as $dots) {
         $bgColor = isset($dots[1]) ? $dots[1] : self::BACKGROUND;
         $color = isset($dots[2]) ? $dots[2] : null;
         $remainingLength -= $dots[0] * static::DOT_WIDTH_MULTIPLIER;
         $console->write(str_repeat(' ', $dots[0] * static::DOT_WIDTH_MULTIPLIER), $color, $bgColor);
     }
     $console->write(str_repeat(' ', $remainingLength), null, self::BACKGROUND);
     $console->writeLine();
 }
Пример #12
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;
 }
Пример #13
0
 /**
  * Report success
  */
 private function reportComplete(Console $console, int $width, int $length, bool $success = true)
 {
     if ($length + 8 > $width) {
         $console->writeLine('');
         $length = 0;
     }
     $message = $success ? '[ DONE ]' : '[ FAIL ]';
     $spaces = $width - $length - 8;
     $spaces = $spaces > 0 ? $spaces : 0;
     $color = $success ? Color::GREEN : Color::RED;
     $console->writeLine(str_repeat('.', $spaces) . $message, $color);
 }
Пример #14
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;
 }
Пример #15
0
 /**
  * Perform a self-update on the phar file
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $manifest = UpdateManifest::loadFile(self::MANIFEST_FILE);
     $manager = new UpdateManager($manifest);
     if (!$manager->update($this->version, true, true)) {
         $console->writeLine('No updates available.', Color::YELLOW);
         return 0;
     }
     $version = new Version($this->version);
     $update = $manifest->findRecent($version);
     $console->write('Updated to version ');
     $console->writeLine($update->getVersion(), Color::GREEN);
     return 0;
 }
Пример #16
0
 /**
  * Create a view helper help
  */
 public function viewHelperHelp()
 {
     // output header
     $this->consoleHeader('Create a new view helper within an module', ' Help ');
     $this->console->writeLine('       zf.php create view-helper <helper_name> <module_name> [<path>] [options]', Color::GREEN);
     $this->console->writeLine();
     $this->console->writeLine('       Parameters:');
     $this->console->writeLine();
     $this->console->write('       <helper_name>      ', Color::CYAN);
     $this->console->writeLine('Name of view helper to be created.', Color::NORMAL);
     $this->console->write('       <module_name>      ', Color::CYAN);
     $this->console->writeLine('Module in which view helper should be created.', Color::NORMAL);
     $this->console->write('       [<path>]           ', Color::CYAN);
     $this->console->writeLine('(Optional) path to a ZF2 application.', Color::NORMAL);
     $this->console->write('       --factory|-f       ', Color::CYAN);
     $this->console->writeLine('Create a factory for the view helper.', Color::NORMAL);
     $this->console->write('       --ignore|-i        ', Color::CYAN);
     $this->console->writeLine('Ignore coding conventions.', Color::NORMAL);
     $this->console->write('       --config|-c        ', Color::CYAN);
     $this->console->writeLine('Prevent that module configuration is updated.', Color::NORMAL);
     $this->console->write('       --apidocs|-a       ', Color::CYAN);
     $this->console->writeLine('Prevent the api doc block generation.', Color::NORMAL);
     // output footer
     $this->consoleFooter('requested help was successfully displayed');
 }
Пример #17
0
 public function writeNotice($msg)
 {
     if ($this->quit || !$this->verbose) {
         return;
     }
     $this->console->writeLine($msg);
 }
Пример #18
0
 protected function removeMigration(MigrationInterface $migration)
 {
     $this->console->writeLine(sprintf(' -  Uninstall "%s" migration...', $migration->getName()), ColorInterface::YELLOW);
     $migration->tearDown();
     $this->forgetMigration($migration);
     $this->console->writeLine(sprintf('    "%s" migration successfully uninstalled.', $migration->getName()), ColorInterface::CYAN);
 }
Пример #19
0
 /**
  * Show message indicating inability to match a route.
  *
  * @param array $args
  */
 protected function showUnmatchedRouteMessage(array $args)
 {
     $this->console->write('Unrecognized command: ', Color::RED);
     $this->console->writeLine(implode(' ', $args));
     $this->console->writeLine('');
     $this->showUsageMessage();
 }
Пример #20
0
    public function testOnLogJobProcessDone_SendsOutputToConsole()
    {
        $this->console->expects($this->once())->method('writeLine')
            ->with('Done!');

        $this->listener->onLogJobProcessDone($this->event);
    }
 /**
  * @param SqlInterface $query
  * @return void
  */
 public function execute(SqlInterface $query)
 {
     $time = microtime(true);
     $adapterPlatform = $this->adapter->getPlatform();
     if ($query instanceof ZendCreateTable) {
         $this->console->write('    > create table ' . $adapterPlatform->quoteIdentifier($query->getRawState(ZendCreateTable::TABLE)) . '...');
     } elseif ($query instanceof ZendAlterTable) {
         $this->console->write('    > alter table ' . $adapterPlatform->quoteIdentifier($query->getRawState(ZendAlterTable::TABLE)) . '...');
     } elseif ($query instanceof TruncateTable) {
         $this->console->write('    > truncate table ' . $adapterPlatform->quoteIdentifier($query->getRawState(TruncateTable::TABLE)) . '...');
     } elseif ($query instanceof DropTable) {
         $this->console->write('    > drop table ' . $adapterPlatform->quoteIdentifier($query->getRawState(DropTable::TABLE)) . '...');
     } elseif ($query instanceof Insert) {
         $this->console->write('    > insert into ' . $adapterPlatform->quoteIdentifier($query->getRawState('table')) . '...');
     } elseif ($query instanceof Update) {
         $this->console->write('    > update table ' . $adapterPlatform->quoteIdentifier($query->getRawState('table')) . '...');
     } elseif ($query instanceof Delete) {
         $this->console->write('    > delete from ' . $adapterPlatform->quoteIdentifier($query->getRawState('table')) . '...');
     } else {
         throw new InvalidArgumentException(sprintf('Parameter of a method %s must be a executable Sql statement that modifies a table.', __METHOD__));
     }
     $platform = new Platform($this->adapter);
     $platform->setSubject($query);
     if (defined('ANELEGAN_DB_DEBUG') && ANELEGAN_DB_DEBUG) {
         $this->console->write(PHP_EOL . $platform->getSqlString($this->adapter->getPlatform()) . PHP_EOL);
     } else {
         $this->adapter->query($platform->getSqlString(), Adapter::QUERY_MODE_EXECUTE);
     }
     $this->console->writeLine(' done (time: ' . sprintf('%.3f', microtime(true) - $time) . 's)');
 }
Пример #22
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;
 }
Пример #23
0
 /**
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $console->writeLine('Rolling back to a previous installed version...', Color::GREEN);
     $updater = new Updater();
     try {
         $result = $updater->rollback();
         if (!$result) {
             $console->writeLine('Rollback failed!', Color::RED);
             return 1;
         }
     } catch (Exception $e) {
         $console->writeLine('[ERROR] Could not rollback', Color::RED);
         return 1;
     }
     $console->writeLine('Rollback complete!', Color::GREEN);
     return 0;
 }
Пример #24
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;
 }
Пример #25
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);
 }
Пример #26
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;
 }
Пример #27
0
 public function roomSetTopicAction()
 {
     $room = $this->params('room');
     $topic = $this->params('topic');
     $from = $this->params('from', $this->from);
     try {
         $this->hipchat->set_room_topic($room, $topic, $from);
         $this->console->writeLine(sprintf('Room "%s" has topic "%s"', $room, $topic), Color::GREEN);
     } catch (Exception $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     }
 }
 /**
  * @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;
 }
Пример #29
0
 public function matchAction()
 {
     /** @var Request $request */
     $request = $this->getRequest();
     $method = strtoupper($request->getParam('method'));
     $url = $request->getParam('url');
     $match = $this->routeMatcher->match($method, $url);
     if (null !== $match) {
         $route = $this->routeCollection->getRoute($match);
         $this->console->writeLine(sprintf('A match was found for %s "%s"', $method, $url), ColorInterface::GREEN);
         $this->console->write('        Name:  ');
         $this->console->writeLine($route->getName(), ColorInterface::LIGHT_WHITE);
         $this->console->write('         URL:  ');
         $this->console->writeLine($route->getUrl(), ColorInterface::LIGHT_WHITE);
         $this->console->write('  Controller:  ');
         $this->console->writeLine($route->getController(), ColorInterface::LIGHT_WHITE);
         $this->console->write('      Action:  ');
         $this->console->writeLine($route->getAction(), ColorInterface::LIGHT_WHITE);
     } else {
         $this->console->writeLine(sprintf('No match found for %s "%s"', $method, $url), ColorInterface::RED);
     }
 }
Пример #30
0
 /**
  * Show ZF2 version help
  */
 public function zfHelp()
 {
     // output header
     $this->consoleHeader('ZF2 library installation', ' Help ');
     $this->console->writeLine('       zf.php install <path> [<version>]', Color::GREEN);
     $this->console->writeLine();
     $this->console->writeLine('       Parameters:');
     $this->console->writeLine();
     $this->console->write('       <path>      ', Color::CYAN);
     $this->console->writeLine('Path where to install the ZF2 library.', Color::NORMAL);
     $this->console->write('       [<version>] ', Color::CYAN);
     $this->console->writeLine('(Optional) Version to install, defaults to the last version available.', Color::NORMAL);
     // output footer
     $this->consoleFooter('requested help was successfully displayed');
 }