コード例 #1
0
 /**
  * Handles the "puli type --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)
 {
     $packageNames = ArgsUtil::getPackageNames($args, $this->packages);
     $states = $this->getBindingTypeStates($args);
     $printStates = count($states) > 1;
     $printPackageName = count($packageNames) > 1;
     $printHeaders = $printStates || $printPackageName;
     $printTypeAdvice = true;
     $printBindAdvice = false;
     $indentation = $printStates && $printPackageName ? 8 : ($printStates || $printPackageName ? 4 : 0);
     foreach ($states as $state) {
         $statePrinted = !$printStates;
         foreach ($packageNames as $packageName) {
             $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($state));
             $bindingTypes = $this->discoveryManager->findTypeDescriptors($expr);
             if (!$bindingTypes) {
                 continue;
             }
             $printTypeAdvice = false;
             if (!$statePrinted) {
                 $this->printBindingTypeState($io, $state);
                 $statePrinted = true;
                 // Only print the advice if at least one type was printed
                 $printBindAdvice = true;
             }
             if ($printPackageName) {
                 $prefix = $printStates ? '    ' : '';
                 $io->writeLine("{$prefix}Package: {$packageName}");
                 $io->writeLine('');
             }
             $styleTag = BindingTypeState::ENABLED === $state ? null : 'bad';
             $this->printTypeTable($io, $bindingTypes, $styleTag, $indentation);
             if ($printHeaders) {
                 $io->writeLine('');
             }
         }
     }
     if ($printTypeAdvice) {
         $io->writeLine('No types defined. Use "puli type --define <name>" to define a type.');
     }
     if ($printBindAdvice) {
         $io->writeLine('Use "puli bind <resource> <type>" to bind a resource to a type.');
     }
     return 0;
 }