/** * Handles the "puli plugin --list" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handleList(Args $args, IO $io) { $pluginClasses = $this->manager->getPluginClasses(); if (!$pluginClasses) { $io->writeLine('No plugin classes. Use "puli plugin --install <class>" to install a plugin class.'); return 0; } foreach ($pluginClasses as $pluginClass) { $io->writeLine("<c1>{$pluginClass}</c1>"); } return 0; }
/** * Handles the "upgrade" command. * * @param Args $args The console arguments * @param IO $io The I/O * * @return int The status code */ public function handle(Args $args, IO $io) { $moduleFile = $this->moduleFileManager->getModuleFile(); $originVersion = $moduleFile->getVersion(); $targetVersion = $args->getArgument('version'); if (version_compare($originVersion, $targetVersion, '=')) { $io->writeLine(sprintf('Your puli.json is already at version %s.', $targetVersion)); return 0; } $this->moduleFileManager->migrate($targetVersion); $io->writeLine(sprintf('Migrated your puli.json from version %s to version %s.', $originVersion, $targetVersion)); return 0; }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new PuliStrategy(); $updateStrategy->setStability($this->getStability($args)); // false: disable signed releases, otherwise the updater will look for // a *.pubkey file for the PHAR $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); return 0; } $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); return 0; }
public function handleDatabaseUpdate(Args $args, IO $io, Command $command) { $tool = new SchemaTool($this->app['entyMgr']); $tool->updateSchema($this->app['entyMgr']->getMetadataFactory()->getAllMetadata()); $io->writeLine("<info>Database schema updated.</info>"); return 0; }
/** * Handles the "config <key>" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handleShow(Args $args, IO $io) { $raw = !$args->isOptionSet('parsed'); $value = $this->manager->getConfigKey($args->getArgument('key'), null, true, $raw); $io->writeLine(StringUtil::formatValue($value, false)); return 0; }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('puli/cli'); $updateStrategy->setStability($this->getStability($args)); $updateStrategy->setPharName('puli.phar'); $updateStrategy->setCurrentLocalVersion(PuliApplicationConfig::VERSION); $updater = new Updater(); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); } else { $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); } return 0; }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('puli/cli'); $updateStrategy->setStability($this->getStability($args)); $updateStrategy->setPharName('puli.phar'); $updateStrategy->setCurrentLocalVersion(PuliApplicationConfig::VERSION); // false: disable signed releases, otherwise the updater will look for // a *.pubkey file for the PHAR $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); return 0; } $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); return 0; }
/** * @param PostDispatchEvent $postDispatchEvent */ public function onPostDispatchEvent(PostDispatchEvent $postDispatchEvent) { if ($this->postDispatchHandler) { call_user_func($this->postDispatchHandler, $postDispatchEvent->event(), $this->io); } else { $this->io->writeLine('<c1>' . $this->eventToString($postDispatchEvent->event()) . '</c1> success!!'); $this->io->writeLine(''); } }
private function scopeFile($path, $prefix, IO $io) { $fileContent = file_get_contents($path); try { $scoppedContent = $this->scoper->addNamespacePrefix($fileContent, $prefix); $this->filesystem->dumpFile($path, $scoppedContent); $io->writeLine(sprintf('Scoping %s. . . Success', $path)); } catch (ParsingException $exception) { $io->errorLine(sprintf('Scoping %s. . . Fail', $path)); } }
/** * handle. * * @param Args $args * @param IO $io * * @return int */ public function handle(Args $args, IO $io) { $configFileExist = true; $overwrite = is_string($args->getOption('force')); try { $this->configurationLoader->setRootDirectory($args->getOption('config')); $configuration = $this->configurationLoader->loadConfiguration(); } catch (ConfigurationLoadingException $e) { $configFileExist = false; } if (!$configFileExist || $overwrite) { $configuration = ['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200, 'metric_uuid' => null, 'service_uuid' => null]], 'hogosha_portal' => ['username' => '', 'password' => '', 'base_uri' => 'http://localhost:8000/api/', 'metric_update' => false, 'incident_update' => false, 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', 'default_resolved_incident_message' => 'The service %service_name% is back to normal']]; // Dump configuration $content = $this->configurationDumper->dumpConfiguration($configuration); $this->filesystem->dumpFile($this->configurationLoader->getConfigurationFilepath(), $content); $io->writeLine('<info>Creating monitor file</info>'); } else { $io->writeLine(sprintf('<info>You already have a configuration file in</info> "%s"', $this->configurationLoader->getConfigurationFilepath())); } }
private function doWriteLine($message, $type) { switch ($type) { case self::OUTPUT_PLAIN: $this->io->writeLine($this->io->removeFormat($message)); break; case self::OUTPUT_RAW: $this->io->writeLineRaw($message); break; default: $this->io->writeLine($message); break; } }
public function handleList(Args $args, IO $io) { $table = new Table(PuliTableStyle::borderless()); $servers = $this->serverManager->getServers(); if ($servers->isEmpty()) { $io->writeLine('No servers. Use "puli server --add <name> <document-root>" to add a server.'); return 0; } $table->setHeaderRow(array('Server Name', 'Installer', 'Location', 'URL Format')); foreach ($servers as $server) { $table->addRow(array('<u>' . $server->getName() . '</u>', $server->getInstallerName(), '<c2>' . $server->getDocumentRoot() . '</c2>', '<c1>' . $server->getUrlFormat() . '</c1>')); } $table->render($io); return 0; }
/** * Handles the "ls" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); $resources = $this->repo->find($path); if (!count($resources)) { $io->errorLine("No resources found for path {$path}"); return 1; } foreach ($resources as $resource) { if ($resource instanceof BodyResource) { $io->writeLine($resource->getBody()); } } return 0; }
public function handle(Args $args, IO $io, Command $command) { $tabular = Tabular::getInstance(); $dom = new \DOMDocument('1.0'); $dom->load($args->getArgument('xml')); $tableDom = $tabular->tabulate($dom, $args->getArgument('definition')); if ($args->getOption('debug')) { $io->writeLine($tableDom->saveXml()); } $rows = $tableDom->toArray(); $table = new Table(TableStyle::solidBorder()); $table->setHeaderRow(array_keys(reset($rows) ?: array())); foreach ($rows as $row) { $table->addRow($row); } $table->render($io); }
/** * Recursively prints the tree for the given resource. * * @param IO $io The I/O. * @param PuliResource $resource The printed resource. * @param int $total Collects the total number of printed resources. * @param string $prefix The prefix for all printed resources. */ private function printTree(IO $io, PuliResource $resource, &$total, $prefix = '') { // The root node has an empty name $children = $resource->listChildren(); $lastIndex = count($children) - 1; $index = 0; foreach ($children as $child) { $isLastChild = $index === $lastIndex; $childPrefix = $isLastChild ? self::LAST_CHILD_PREFIX : self::CHILD_PREFIX; $nestingPrefix = $isLastChild ? self::NESTING_CLOSED_PREFIX : self::NESTING_OPEN_PREFIX; $name = $child->getName() ?: '/'; if ($child->hasChildren()) { $name = '<c1>' . $name . '</c1>'; } $io->writeLine($prefix . $childPrefix . $name); $this->printTree($io, $child, $total, $prefix . $nestingPrefix); ++$index; ++$total; } }
/** * Prints the heading for a binding type state. * * @param IO $io The I/O. * @param int $typeState The {@link BindingTypeState} constant. */ private function printBindingTypeState(IO $io, $typeState) { switch ($typeState) { case BindingTypeState::ENABLED: $io->writeLine('The following binding types are currently enabled:'); $io->writeLine(''); return; case BindingTypeState::DUPLICATE: $io->writeLine('The following types have duplicate definitions and are disabled:'); $io->writeLine(''); return; } }
/** * Prints the heading for a given package state. * * @param IO $io The I/O. * @param int $packageState The {@link PackageState} constant. */ private function printPackageState(IO $io, $packageState) { switch ($packageState) { case PackageState::ENABLED: $io->writeLine('The following packages are currently enabled:'); $io->writeLine(''); return; case PackageState::NOT_FOUND: $io->writeLine('The following packages could not be found:'); $io->writeLine(' (use "puli package --clean" to remove)'); $io->writeLine(''); return; case PackageState::NOT_LOADABLE: $io->writeLine('The following packages could not be loaded:'); $io->writeLine(''); return; } }
public function handleGetDefault(Args $args, IO $io) { $io->writeLine($this->targetManager->getDefaultTarget()->getName()); return 0; }
/** * Prints the header for a path mapping state. * * @param IO $io The I/O. * @param int $pathMappingState The {@link PathMappingState} constant. */ private function printPathMappingStateHeader(IO $io, $pathMappingState) { switch ($pathMappingState) { case PathMappingState::ENABLED: $io->writeLine('The following path mappings are currently enabled:'); $io->writeLine(''); return; case PathMappingState::NOT_FOUND: $io->writeLine('The target paths of the following path mappings were not found:'); $io->writeLine(''); return; case PathMappingState::CONFLICT: $io->writeLine('Some path mappings have conflicting paths:'); $io->writeLine(' (add the package names to the "override-order" key in puli.json to resolve)'); $io->writeLine(''); return; } }
public function handleInstall(Args $args, IO $io) { if ($args->isArgumentSet('server')) { $expr = Expr::same($args->getArgument('server'), AssetMapping::SERVER_NAME); $mappings = $this->assetManager->findAssetMappings($expr); } else { $mappings = $this->assetManager->getAssetMappings(); } if (!$mappings) { $io->writeLine('Nothing to install.'); return 0; } /** @var InstallationParams[] $paramsToInstall */ $paramsToInstall = array(); // Prepare and validate the installation of all matching mappings foreach ($mappings as $mapping) { $paramsToInstall[] = $this->installationManager->prepareInstallation($mapping); } foreach ($paramsToInstall as $params) { foreach ($params->getResources() as $resource) { $serverPath = rtrim($params->getDocumentRoot(), '/') . $params->getServerPathForResource($resource); $io->writeLine(sprintf('Installing <c1>%s</c1> into <c2>%s</c2> via <u>%s</u>...', $resource->getRepositoryPath(), trim($serverPath, '/'), $params->getInstallerDescriptor()->getName())); $this->installationManager->installResource($resource, $params); } } return 0; }
/** * Prints the URL of a Puli path. * * @param string $path A Puli path. * @param IO $io The I/O. */ private function printUrl($path, IO $io) { $path = Path::makeAbsolute($path, $this->currentPath); $io->writeLine($this->urlGenerator->generateUrl($path)); }
/** * Prints the header for a binding state. * * @param IO $io The I/O. * @param int $bindingState The {@link BindingState} constant. */ private function printBindingStateHeader(IO $io, $bindingState) { switch ($bindingState) { case BindingState::ENABLED: $io->writeLine('The following bindings are currently enabled:'); $io->writeLine(''); return; case BindingState::DISABLED: $io->writeLine('The following bindings are disabled:'); $io->writeLine(' (use "puli bind --enable <uuid>" to enable)'); $io->writeLine(''); return; case BindingState::TYPE_NOT_FOUND: $io->writeLine('The types of the following bindings could not be found:'); $io->writeLine(' (install or create their type definitions to enable)'); $io->writeLine(''); return; case BindingState::TYPE_NOT_ENABLED: $io->writeLine('The types of the following bindings are not enabled:'); $io->writeLine(' (remove the duplicate type definitions to enable)'); $io->writeLine(''); return; case BindingState::INVALID: $io->writeLine('The following bindings have invalid parameters:'); $io->writeLine(' (remove the binding and add again with correct parameters)'); $io->writeLine(''); return; } }