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; }
/** * @param WorkerEvent $e */ public function onLogJobProcessStart(WorkerEvent $e) { $job = $e->getJob(); $name = $job->getMetadata('name'); if (null === $name) { $name = get_class($job); } $this->console->write(sprintf('Processing job %s...', $name)); }
public function getConsoleBanner(ConsoleAdapterInterface $console) { $console->writeLine(); $console->writeLine(str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT), Color::GREEN); $console->write('=', Color::GREEN); $console->write(str_pad('' . Module::NAME, $console->getWidth() - 3, ' ', STR_PAD_BOTH)); $console->writeLine('=', Color::GREEN); $console->writeLine(str_pad('', $console->getWidth() - 1, '=', STR_PAD_RIGHT), Color::GREEN); $console->writeLine(); return 'Usage:'; }
/** * 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); }
/** * @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(); }
/** * Send an error message to the console * * @param string $msg * @return ConsoleModel */ public function __invoke($msg) { $this->console->write(' Oops ', Color::NORMAL, Color::RED); $this->console->write(' '); if (is_array($msg)) { foreach ($msg as $msgBlock) { $this->console->write(current($msgBlock), key($msgBlock)); } } else { $this->console->write($msg); } $this->console->writeLine(); $this->getController()->consoleFooter('an error occured', false); }
/** * Send an error message to the console * * @param string $msg * @return ConsoleModel */ public function __invoke($msg, $badge = ' Go ') { $this->console->writeLine(); $this->console->writeLine(str_pad('', $this->width - 1, '=', STR_PAD_RIGHT), Color::GREEN); $this->console->write('=', Color::GREEN); $this->console->write(str_pad('' . Module::NAME, $this->width - 3, ' ', STR_PAD_BOTH)); $this->console->writeLine('=', Color::GREEN); $this->console->writeLine(str_pad('', $this->width - 1, '=', STR_PAD_RIGHT), Color::GREEN); $this->console->writeLine(); $this->console->write($badge, Color::NORMAL, Color::YELLOW); $this->console->write(' '); $this->console->writeLine($msg . ' ...'); $this->console->writeLine(); }
/** * @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)'); }
/** * 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'); }
private function marshalEntries(array $feedInfo, Console $console) : Collection { $feedUrl = $feedInfo['url']; $logo = $feedInfo['favicon'] ?? 'https://mwop.net/images/favicon/favicon-16x16.png'; $siteName = $feedInfo['sitename'] ?? ''; $siteUrl = $feedInfo['siteurl'] ?? '#'; $filters = $feedInfo['filters'] ?? []; $each = $feedInfo['each'] ?? function ($item) { }; $message = sprintf(' Retrieving %s... ', $feedUrl); $length = strlen($message); $console->write($message, Color::BLUE); try { $feed = preg_match('#^https?://#', $feedUrl) ? $this->getFeedFromRemoteUrl($feedUrl) : $this->getFeedFromLocalFile($feedUrl); } catch (\Throwable $e) { $this->reportException($e, $console); $this->writeLine('[ FAIL ]', Color::RED); return new Collection([]); } $entries = Collection::create($feed)->filterChain($filters)->slice(5)->each($each)->map(function ($entry) use($logo, $siteName, $siteUrl) { return ['title' => $entry->getTitle(), 'link' => $entry->getLink(), 'date-created' => $entry->getDateCreated(), 'favicon' => $logo, 'sitename' => $siteName, 'siteurl' => $siteUrl]; }); $this->reportComplete($console, $length); return $entries; }
/** * 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(); }
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; }
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); }
/** * Determine if composer should be executed, and, if so, execute it. * * @param bool $useVendor * @param bool $useComposer * @param string $tmpDir * @return false|null */ protected function executeComposer($useVendor, $useComposer, $tmpDir) { if ($useVendor || !$useComposer) { return; } $composer = $this->getComposerExecutable($tmpDir); $command = sprintf('%s install --no-dev --prefer-dist --optimize-autoloader 2>&1', $composer); if ($composer !== 'composer') { $command = $this->prependPhpBinaryPath($command); } $this->console->write('Executing ', Color::BLUE); $this->console->writeLine($command); $curDir = getcwd(); chdir($tmpDir); $result = exec($command, $output, $exitCode); chdir($curDir); if ($this->downloadedComposer) { @unlink($this->downloadedComposer); unset($this->downloadedComposer); } if ($exitCode !== 0) { $this->exitCode = self::ERROR_COMPOSER_ERROR; return $this->reportError('Composer error during install command (exit code: ' . $exitCode . ') ' . implode('; ', $output)); } }
/** * This method is called every time a Check has been performed. If this method * returns false, the Runner will not perform any additional checks and stop * its run. * * @param CheckInterface $check A Check instance that has just finished running * @param ResultInterface $result Result for that particular check instance * @param bool $alias The alias being targeted by the check * @return bool|void Return false to prevent from running additional Checks */ public function onAfterRun(CheckInterface $check, ResultInterface $result, $alias = null) { $descr = ' ' . $check->getLabel(); if ($message = $result->getMessage()) { $descr .= ': ' . $result->getMessage(); } if ($this->displayData && ($data = $result->getData())) { $descr .= PHP_EOL . str_repeat('-', $this->width - 7); $data = $result->getData(); if (is_object($data) && $data instanceof \Exception) { $descr .= PHP_EOL . get_class($data) . PHP_EOL . $data->getMessage() . $data->getTraceAsString(); } else { $descr .= PHP_EOL . @var_export($result->getData(), true); } $descr .= PHP_EOL . str_repeat('-', $this->width - 7); } // Draw status line if ($result instanceof Success) { $this->console->write(' OK ', Color::WHITE, Color::GREEN); $this->console->writeLine($this->strColPad($descr, $this->width - 7, ' '), Color::GREEN); } elseif ($result instanceof Failure) { $this->console->write(' FAIL ', Color::WHITE, Color::RED); $this->console->writeLine($this->strColPad($descr, $this->width - 7, ' '), Color::RED); } elseif ($result instanceof Warning) { $this->console->write(' WARN ', Color::NORMAL, Color::YELLOW); $this->console->writeLine($this->strColPad($descr, $this->width - 7, ' '), Color::YELLOW); } elseif ($result instanceof Skip) { $this->console->write(' SKIP ', Color::NORMAL, Color::YELLOW); $this->console->writeLine($this->strColPad($descr, $this->width - 7, ' '), Color::YELLOW); } else { $this->console->write(' ???? ', Color::NORMAL, Color::YELLOW); $this->console->writeLine($this->strColPad($descr, $this->width - 7, ' '), Color::YELLOW); } }
/** * Send an error message to the console * * @param string $msg * @return ConsoleModel */ public function __invoke($msg, $success = true) { if ($success) { $line1 = ' OK '; $line2 = ' (' . $msg . ')'; $bgColor = Color::GREEN; } else { $line1 = ' FAIL '; $line2 = ' (' . $msg . ')'; $bgColor = Color::RED; } $this->console->writeLine(); $this->console->write($line1, Color::NORMAL, $bgColor); $this->console->write(' '); $this->console->writeLine(str_pad($line2, $this->width - 8, ' ', STR_PAD_RIGHT), Color::NORMAL, $bgColor); $this->console->writeLine(); }
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; }
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); } }
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; }
/** * This method is called every time a Check has been performed. * * @param CheckInterface $check A Check instance that has just finished running * @param ResultInterface $result Result for that particular check instance * @param bool $alias The alias being targeted by the check * @return bool|void Return false to prevent from running additional Checks */ public function onAfterRun(CheckInterface $check, ResultInterface $result, $alias = null) { // Draw a symbol if ($result instanceof Success) { $this->console->write('.', Color::GREEN); } elseif ($result instanceof Failure) { $this->console->write('F', Color::WHITE, Color::RED); } elseif ($result instanceof Warning) { $this->console->write('!', Color::YELLOW); } elseif ($result instanceof Skip) { $this->console->write('S', Color::YELLOW); } else { $this->console->write('?', Color::YELLOW); } $this->pos++; // Check if we need to move to the next line if ($this->gutter > 0 && $this->pos > $this->width - $this->gutter) { $this->console->write(str_pad(str_pad($this->iter, $this->countLength, ' ', STR_PAD_LEFT) . ' / ' . $this->total . ' (' . str_pad(round($this->iter / $this->total * 100), 3, ' ', STR_PAD_LEFT) . '%)', $this->gutter, ' ', STR_PAD_LEFT)); $this->pos = 1; } $this->iter++; }
/** * 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; }
public function onFinish(RunEvent $e) { /* @var $results \ZFTool\Diagnostics\Result\Collection */ $results = $e->getResults(); // Display information that the test has been aborted. if ($this->stopped) { $this->console->writeLine('Diagnostics aborted because of a failure.', Color::RED); } // Display a summary line if ($results->getFailureCount() == 0 && $results->getWarningCount() == 0 && $results->getUnknownCount() == 0) { $this->console->write(' OK ', Color::NORMAL, Color::GREEN); $this->console->write(' '); $this->console->writeLine(str_pad(' (' . $this->total . ' diagnostic tests)', $this->width - 8, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::GREEN); } elseif ($results->getFailureCount() == 0) { $line = ' (' . $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful tests'; if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown test results'; } $line .= ')'; $this->console->write(' WARN ', Color::NORMAL, Color::YELLOW); $this->console->write(' '); $this->console->writeLine(str_pad($line, $this->width - 8, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::YELLOW); } else { $line = ' (' . $results->getFailureCount() . ' failures, '; $line .= $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful tests'; if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown test results'; } $line .= ')'; $this->console->write(' FAIL ', Color::NORMAL, Color::RED); $this->console->write(' '); $this->console->writeLine(str_pad($line, $this->width - 8, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::RED); } $this->console->writeLine(); }
/** * 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'); }
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); }
/** * Generate a Classmap help */ public function classmapHelp() { // output header $this->consoleHeader('Generate a Classmap for a directory / module', ' Help '); $this->console->writeLine(' zf.php generate classmap <directory> [<destination>]', Color::GREEN); $this->console->writeLine(); $this->console->writeLine(' Parameters:'); $this->console->writeLine(); $this->console->write(' <directory> ', Color::CYAN); $this->console->writeLine('Directory to scan for PHP classes (use "." to use current directory).', Color::NORMAL); $this->console->write(' [<destination>] ', Color::CYAN); $this->console->writeLine('(Optional) File name for class map file or - for standard output.', Color::NORMAL); $this->console->writeLine(' Defaults to autoload_classmap.php inside <directory>.', Color::NORMAL); // output footer $this->consoleFooter('requested help was successfully displayed'); }
/** * Set configuration by key help */ public function setHelp() { // output header $this->consoleHeader('Set a single config value (to change scalar values in local configuration file)', ' Help '); $this->console->writeLine(' zf.php config set <config_name> <config_value> [<path>]', Color::GREEN); $this->console->writeLine(); $this->console->writeLine(' Parameters:'); $this->console->writeLine(); $this->console->write(' <config_name> ', Color::CYAN); $this->console->writeLine('Configuration key, i.e. db.host.', Color::NORMAL); $this->console->write(' <config_value> ', Color::CYAN); $this->console->writeLine('Configuration value, i.e. localhost.', Color::NORMAL); $this->console->write(' [<path>] ', Color::CYAN); $this->console->writeLine('(Optional) path to a ZF2 application.', Color::NORMAL); // output footer $this->consoleFooter('requested help was successfully displayed'); }
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; }
/** * Show ZF2 actions help */ public function actionsHelp() { // output header $this->consoleHeader('Show all actions for a controller in a module', ' Help '); $this->console->writeLine(' zf.php actions <module_name> <controller_name> [<path>]', Color::GREEN); $this->console->writeLine(); $this->console->writeLine(' Parameters:'); $this->console->writeLine(); $this->console->write(' <module_name> ', Color::CYAN); $this->console->writeLine('Name of module.', Color::NORMAL); $this->console->write(' <controller_name> ', Color::CYAN); $this->console->writeLine('Name of controller.', Color::NORMAL); $this->console->write(' [<path>] ', Color::CYAN); $this->console->writeLine('(Optional) path to a ZF2 application.', Color::NORMAL); // output footer $this->consoleFooter('requested help was successfully displayed'); }
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; }
/** * {@inheritdoc} */ public function getConsoleUsage(AdapterInterface $console) { $console->write(__NAMESPACE__ . ' Command Line Interface', ColorInterface::BLUE); $console->write(' Version ', ColorInterface::GREEN); $console->writeLine($this->version, ColorInterface::RED); $console->writeLine(); $console->writeLine('Usage:', ColorInterface::YELLOW); $console->writeLine('ZFLabs-orm-fixture <commands> [--options]', ColorInterface::WHITE); $console->writeLine(); $console->writeLine('Options:', ColorInterface::YELLOW); $console->write(' --purge', ColorInterface::GREEN); $console->write(' '); $console->writeLine('Remove all previous records.', ColorInterface::WHITE); $console->writeLine('Commands:', ColorInterface::YELLOW); $console->write(' load', ColorInterface::GREEN); $console->write(' '); $console->writeLine('Loads all fixtures.', ColorInterface::WHITE); $console->write(' check', ColorInterface::GREEN); $console->write(' '); $console->writeLine('Shows all fixtures to load.', ColorInterface::WHITE); $console->writeLine(); return $console; }