public function handleAdd(Args $args) { $descriptions = $args->getOption('description'); $parameters = array(); // The first description is for the installer $description = $descriptions ? array_shift($descriptions) : null; foreach ($args->getOption('param') as $parameter) { // Subsequent descriptions are for the parameters $paramDescription = $descriptions ? array_shift($descriptions) : null; // Optional parameter with default value if (false !== ($pos = strpos($parameter, '='))) { $parameters[] = new InstallerParameter(substr($parameter, 0, $pos), InstallerParameter::OPTIONAL, StringUtil::parseValue(substr($parameter, $pos + 1)), $paramDescription); continue; } // Required parameter $parameters[] = new InstallerParameter($parameter, InstallerParameter::REQUIRED, null, $paramDescription); } $this->installerManager->addRootInstallerDescriptor(new InstallerDescriptor($args->getArgument('name'), $args->getArgument('class'), $description, $parameters)); return 0; }
private function parseParams(Args $args, array &$bindingParams) { foreach ($args->getOption('param') as $parameter) { // Optional parameter with default value if (false !== ($pos = strpos($parameter, '='))) { $key = substr($parameter, 0, $pos); $bindingParams[$key] = new BindingParameter($key, BindingParameter::OPTIONAL, StringUtil::parseValue(substr($parameter, $pos + 1))); continue; } // Required parameter $bindingParams[$parameter] = new BindingParameter($parameter, BindingParameter::REQUIRED, null); } }
private function parseParams(Args $args, array &$parameters) { foreach ($args->getOption('param') as $parameter) { $pos = strpos($parameter, '='); if (false === $pos) { throw new RuntimeException(sprintf('Invalid parameter "%s". Expected "<name>=<value>".', $parameter)); } $parameters[substr($parameter, 0, $pos)] = StringUtil::parseValue(substr($parameter, $pos + 1)); } }
/** * Prints the resources in the long style (with the "-l" option). * * @param IO $io The I/O. * @param ResourceCollection $resources The resources. */ private function listLong(IO $io, ResourceCollection $resources) { $style = TableStyle::borderless(); $style->setColumnAlignments(array(Alignment::LEFT, Alignment::RIGHT, Alignment::LEFT, Alignment::RIGHT, Alignment::RIGHT, Alignment::LEFT)); $table = new Table($style); $today = new DateTime(); $currentYear = (int) $today->format('Y'); foreach ($resources as $resource) { // Create date from timestamp. Result is in the UTC timezone. $modifiedAt = new DateTime('@' . $resource->getMetadata()->getModificationTime()); // Set timezone to server timezone. $modifiedAt->setTimezone($today->getTimezone()); $year = (int) $modifiedAt->format('Y'); $table->addRow(array(StringUtil::getShortClassName(get_class($resource)), $this->formatSize($resource->getMetadata()->getSize()), $modifiedAt->format('M'), $modifiedAt->format('j'), $year < $currentYear ? $year : $modifiedAt->format('H:i'), $this->formatName($resource))); } $table->render($io); }
/** * Finds the resources for a given binding type. * * @param string $typeName The type name. * * @return string[] An array of short resource class names indexed by * the resource path. */ private function findByBindingType($typeName) { $matches = array(); foreach ($this->discovery->findByType($typeName) as $binding) { foreach ($binding->getResources() as $resource) { $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource)); } } ksort($matches); return $matches; }
/** * Prints not-loadable packages in a table. * * @param IO $io The I/O. * @param Package[] $packages The not-loadable packages. * @param bool $indent Whether to indent the output. */ private function printNotLoadablePackages(IO $io, array $packages, $indent = false) { $rootDir = $this->packageManager->getContext()->getRootDirectory(); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Package Name', 'Error')); ksort($packages); foreach ($packages as $package) { $packageName = $package->getName(); $loadErrors = $package->getLoadErrors(); $errorMessage = ''; foreach ($loadErrors as $loadError) { $errorMessage .= StringUtil::getShortClassName(get_class($loadError)) . ': ' . $loadError->getMessage() . "\n"; } $errorMessage = rtrim($errorMessage); if (!$errorMessage) { $errorMessage = 'Unknown error.'; } // Remove root directory $errorMessage = str_replace($rootDir . '/', '', $errorMessage); $table->addRow(array(sprintf('<bad>%s</bad>', $packageName), sprintf('<bad>%s</bad>', $errorMessage))); } $table->render($io, $indent ? 4 : 0); }
/** * Handles the "config <key> <value>" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleSet(Args $args) { $value = StringUtil::parseValue($args->getArgument('value')); $this->manager->setConfigKey($args->getArgument('key'), $value); return 0; }
/** * Finds the resources for a given binding type. * * @param string $typeName The type name. * * @return string[] An array of short resource class names indexed by * the resource path. */ private function findByBindingType($typeName) { $matches = array(); $expr = Expr::isInstanceOf('Puli\\Discovery\\Binding\\ResourceBinding'); foreach ($this->discovery->findBindings($typeName, $expr) as $binding) { /** @var ResourceBinding $binding */ foreach ($binding->getResources() as $resource) { $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource)); } } ksort($matches); return $matches; }
private function parseParams(Args $args, array &$bindingParams) { foreach ($args->getOption('param') as $parameter) { $pos = strpos($parameter, '='); if (false === $pos) { throw new RuntimeException(sprintf('The "--param" option expects a parameter in the form ' . '"key=value". Got: "%s"', $parameter)); } $key = substr($parameter, 0, $pos); $value = StringUtil::parseValue(substr($parameter, $pos + 1)); $bindingParams[$key] = $value; } }