/** * 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; $printAdvice = false; $indentation = $printStates && $printPackageName ? 8 : ($printStates || $printPackageName ? 4 : 0); foreach ($states as $state) { $statePrinted = !$printStates; foreach ($packageNames as $packageName) { $expr = Expr::same($packageName, BindingTypeDescriptor::CONTAINING_PACKAGE)->andSame($state, BindingTypeDescriptor::STATE); $bindingTypes = $this->discoveryManager->findBindingTypes($expr); if (!$bindingTypes) { continue; } if (!$statePrinted) { $this->printBindingTypeState($io, $state); $statePrinted = true; // Only print the advice if at least one type was printed $printAdvice = 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 ($printAdvice) { $io->writeLine('Use "puli bind <resource> <type>" to bind a resource to a type.'); } return 0; }