Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Shared / ServicesTrait.php
index 7f1b11888d68bcb6cf7f1f38b71860bcc2db9691..4543128c31e91584388c030661897992522e4e30 100644 (file)
@@ -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;
     }
 }