public function handleList(Args $args, IO $io) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Name', 'Class', 'Description')); foreach ($this->installerManager->getInstallerDescriptors() as $descriptor) { $className = $descriptor->getClassName(); if (!$args->isOptionSet('long')) { $className = StringUtil::getShortClassName($className); } $parameters = array(); foreach ($descriptor->getParameters() as $parameterName => $parameter) { if (!$parameter->isRequired()) { $parameterName .= '=' . StringUtil::formatValue($parameter->getDefaultValue()); } $parameters[] = $parameterName; } $description = $descriptor->getDescription(); if (!empty($parameters)) { // non-breaking space $description .= ' <c1>(' . implode(", ", $parameters) . ')</c1>'; } $table->addRow(array('<u>' . $descriptor->getName() . '</u>', '<c1>' . $className . '</c1>', $description)); } $table->render($io); return 0; }
/** * Handles the "config" 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) { $raw = !$args->isOptionSet('parsed'); $userValues = $this->manager->getConfigKeys(false, false, $raw); $effectiveValues = $this->manager->getConfigKeys(true, true, $raw); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Config Key', 'User Value', 'Effective Value')); foreach ($effectiveValues as $key => $value) { $table->addRow(array("<c1>{$key}</c1>", array_key_exists($key, $userValues) ? StringUtil::formatValue($userValues[$key], false) : '', StringUtil::formatValue($value, false))); } $table->render($io); return 0; }
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; }
/** * Prints the binding types in a table. * * @param IO $io The I/O. * @param BindingTypeDescriptor[] $descriptors The type descriptors to print. * @param string $styleTag The tag used to style the output * @param int $indentation The number of spaces to indent. */ private function printTypeTable(IO $io, array $descriptors, $styleTag = null, $indentation = 0) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Type', 'Description', 'Parameters')); $paramTag = $styleTag ?: 'c1'; $typeTag = $styleTag ?: 'u'; foreach ($descriptors as $descriptor) { $type = $descriptor->getType(); $parameters = array(); foreach ($type->getParameters() as $parameter) { $paramString = $parameter->isRequired() ? $parameter->getName() : $parameter->getName() . '=' . StringUtil::formatValue($parameter->getDefaultValue()); $parameters[$parameter->getName()] = "<{$paramTag}>{$paramString}</{$paramTag}>"; } $description = $descriptor->getDescription(); if ($styleTag) { $description = "<{$styleTag}>{$description}</{$styleTag}>"; } ksort($parameters); $table->addRow(array("<{$typeTag}>" . $descriptor->getTypeName() . "</{$typeTag}>", $description, implode("\n", $parameters))); } $table->render($io, $indentation); }
/** * 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); }
/** * Prints a list of binding descriptors. * * @param IO $io The I/O. * @param BindingDescriptor[] $descriptors The binding descriptors. * @param int $indentation The number of spaces to indent. * @param bool $enabled Whether the binding descriptors * are enabled. If not, the output * is printed in red. */ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, $enabled = true) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('UUID', 'Glob', 'Type')); $paramTag = $enabled ? 'c1' : 'bad'; $artifactTag = $enabled ? 'c1' : 'bad'; $typeTag = $enabled ? 'u' : 'bad'; foreach ($descriptors as $descriptor) { $parameters = array(); $binding = $descriptor->getBinding(); foreach ($binding->getParameterValues() as $parameterName => $parameterValue) { $parameters[] = $parameterName . '=' . StringUtil::formatValue($parameterValue); } $uuid = substr($descriptor->getUuid(), 0, 6); if (!$enabled) { $uuid = "<bad>{$uuid}</bad>"; } $paramString = ''; if (!empty($parameters)) { // \xc2\xa0 is a non-breaking space $paramString = " <{$paramTag}>(" . implode(", ", $parameters) . ")</{$paramTag}>"; } if ($binding instanceof ResourceBinding) { $artifact = $binding->getQuery(); } elseif ($binding instanceof ClassBinding) { $artifact = StringUtil::getShortClassName($binding->getClassName()); } else { continue; } $typeString = StringUtil::getShortClassName($binding->getTypeName()); $table->addRow(array($uuid, "<{$artifactTag}>{$artifact}</{$artifactTag}>", "<{$typeTag}>{$typeString}</{$typeTag}>" . $paramString)); } $table->render($io, $indentation); }
/** * Prints a list of conflicting path mappings. * * @param IO $io The I/O. * @param PathMapping[] $mappings The path mappings. * @param int $indentation The number of spaces to indent the * output. */ private function printConflictTable(IO $io, array $mappings, $indentation = 0) { /** @var PathConflict[] $conflicts */ $conflicts = array(); $shortPrefix = str_repeat(' ', $indentation); $prefix = str_repeat(' ', $indentation + 4); $printNewline = false; foreach ($mappings as $mapping) { foreach ($mapping->getConflicts() as $conflict) { $conflicts[spl_object_hash($conflict)] = $conflict; } } foreach ($conflicts as $conflict) { if ($printNewline) { $io->writeLine(''); } $io->writeLine(sprintf('%sConflicting path: %s', $shortPrefix, $conflict->getRepositoryPath())); $io->writeLine(''); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Package', 'Puli Path', 'Real Path(s)')); foreach ($conflict->getMappings() as $mapping) { $table->addRow(array('<bad>' . $mapping->getContainingPackage()->getName() . '</bad>', '<bad>' . $mapping->getRepositoryPath() . '</bad>', '<bad>' . implode(', ', $mapping->getPathReferences()) . '</bad>')); } $io->writeLine(sprintf('%sMapped by the following mappings:', $prefix)); $io->writeLine(''); $table->render($io, $indentation + 4); $printNewline = true; } }
/** * Prints a list of binding descriptors. * * @param IO $io The I/O. * @param BindingDescriptor[] $descriptors The binding descriptors. * @param int $indentation The number of spaces to indent. * @param bool $enabled Whether the binding descriptors * are enabled. If not, the output * is printed in red. */ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, $enabled = true) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('UUID', 'Glob', 'Type')); $paramTag = $enabled ? 'c1' : 'bad'; $queryTag = $enabled ? 'c1' : 'bad'; $typeTag = $enabled ? 'u' : 'bad'; foreach ($descriptors as $descriptor) { $parameters = array(); foreach ($descriptor->getParameterValues() as $parameterName => $value) { $parameters[] = $parameterName . '=' . StringUtil::formatValue($value); } $uuid = substr($descriptor->getUuid(), 0, 6); if (!$enabled) { $uuid = "<bad>{$uuid}</bad>"; } if ($parameters) { // \xc2\xa0 is a non-breaking space $paramString = " <{$paramTag}>(" . implode(", ", $parameters) . ")</{$paramTag}>"; } else { $paramString = ''; } $table->addRow(array($uuid, "<{$queryTag}>{$descriptor->getQuery()}</{$queryTag}>", "<{$typeTag}>{$descriptor->getTypeName()}</{$typeTag}>" . $paramString)); } $table->render($io, $indentation); }