X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FShared%2FServicesTrait.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FShared%2FServicesTrait.php;h=4543128c31e91584388c030661897992522e4e30;hp=7f1b11888d68bcb6cf7f1f38b71860bcc2db9691;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Shared/ServicesTrait.php b/vendor/drupal/console/src/Command/Shared/ServicesTrait.php index 7f1b11888..4543128c3 100644 --- a/vendor/drupal/console/src/Command/Shared/ServicesTrait.php +++ b/vendor/drupal/console/src/Command/Shared/ServicesTrait.php @@ -7,35 +7,32 @@ namespace Drupal\Console\Command\Shared; -use Drupal\Console\Core\Style\DrupalStyle; - trait ServicesTrait { /** - * @param DrupalStyle $io - * * @return mixed */ - public function servicesQuestion(DrupalStyle $io) + public function servicesQuestion() { - if ($io->confirm( + if ($this->getIo()->confirm( $this->trans('commands.common.questions.services.confirm'), false ) ) { $service_collection = []; - $io->writeln($this->trans('commands.common.questions.services.message')); + $this->getIo()->writeln($this->trans('commands.common.questions.services.message')); $services = $this->container->getServiceIds(); + while (true) { - $service = $io->choiceNoList( + $service = $this->getIo()->choiceNoList( $this->trans('commands.common.questions.services.name'), $services, - null, + '', true ); $service = trim($service); - if (empty($service)) { + if (empty($service) || is_numeric($service)) { break; } @@ -58,10 +55,11 @@ trait ServicesTrait */ public function buildServices($services) { + $buildServices = []; if (!empty($services)) { - $buildServices = []; foreach ($services as $service) { $class = get_class($this->container->get($service)); + $class = $this->getInterface($class); $shortClass = explode('\\', $class); $machineName = str_replace('.', '_', $service); $buildServices[$service] = [ @@ -72,10 +70,31 @@ trait ServicesTrait 'short' => end($shortClass), ]; } + } + + return $buildServices; + } - return $buildServices; + /** + * Gets class interface. + * + * @param string $class + * Class name. + * + * @return string + * Interface + */ + private function getInterface($class) { + $interfaceName = $class; + $interfaces = class_implements($class); + if (!empty($interfaces)) { + if (count($interfaces) == 1) { + $interfaceName = array_shift($interfaces); + } elseif ($key = array_search($class . 'Interface', $interfaces)) { + $interfaceName = $interfaces[$key]; + } } - return []; + return $interfaceName; } }