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;
 }
Example #2
0
 /**
  * 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);
 }
Example #3
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();
     foreach ($this->discovery->findByType($typeName) as $binding) {
         foreach ($binding->getResources() as $resource) {
             $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource));
         }
     }
     ksort($matches);
     return $matches;
 }
Example #4
0
 /**
  * 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);
 }
Example #5
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;
 }
Example #6
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);
 }