Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / psy / psysh / src / Command / ParseCommand.php
similarity index 84%
rename from vendor/psy/psysh/src/Psy/Command/ParseCommand.php
rename to vendor/psy/psysh/src/Command/ParseCommand.php
index 301bb614a1994c3af827603d2906160561fdcccd..5fe36d126a5daafc187244f9e92ca430753a6acb 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * This file is part of Psy Shell.
  *
- * (c) 2012-2017 Justin Hileman
+ * (c) 2012-2018 Justin Hileman
  *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
@@ -13,11 +13,12 @@ namespace Psy\Command;
 
 use PhpParser\Node;
 use PhpParser\Parser;
+use Psy\Context;
+use Psy\ContextAware;
 use Psy\Input\CodeArgument;
 use Psy\ParserFactory;
 use Psy\VarDumper\Presenter;
 use Psy\VarDumper\PresenterAware;
-use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -26,8 +27,15 @@ use Symfony\Component\VarDumper\Caster\Caster;
 /**
  * Parse PHP code and show the abstract syntax tree.
  */
-class ParseCommand extends Command implements PresenterAware
+class ParseCommand extends Command implements ContextAware, PresenterAware
 {
+    /**
+     * Context instance (for ContextAware interface).
+     *
+     * @var Context
+     */
+    protected $context;
+
     private $presenter;
     private $parserFactory;
     private $parsers;
@@ -38,11 +46,21 @@ class ParseCommand extends Command implements PresenterAware
     public function __construct($name = null)
     {
         $this->parserFactory = new ParserFactory();
-        $this->parsers       = array();
+        $this->parsers       = [];
 
         parent::__construct($name);
     }
 
+    /**
+     * ContextAware interface.
+     *
+     * @param Context $context
+     */
+    public function setContext(Context $context)
+    {
+        $this->context = $context;
+    }
+
     /**
      * PresenterAware interface.
      *
@@ -51,12 +69,12 @@ class ParseCommand extends Command implements PresenterAware
     public function setPresenter(Presenter $presenter)
     {
         $this->presenter = clone $presenter;
-        $this->presenter->addCasters(array(
+        $this->presenter->addCasters([
             'PhpParser\Node' => function (Node $node, array $a) {
-                $a = array(
+                $a = [
                     Caster::PREFIX_VIRTUAL . 'type'       => $node->getType(),
                     Caster::PREFIX_VIRTUAL . 'attributes' => $node->getAttributes(),
-                );
+                ];
 
                 foreach ($node->getSubNodeNames() as $name) {
                     $a[Caster::PREFIX_VIRTUAL . $name] = $node->$name;
@@ -64,7 +82,7 @@ class ParseCommand extends Command implements PresenterAware
 
                 return $a;
             },
-        ));
+        ]);
     }
 
     /**
@@ -72,15 +90,15 @@ class ParseCommand extends Command implements PresenterAware
      */
     protected function configure()
     {
-        $definition = array(
-            new CodeArgument('code', InputArgument::REQUIRED, 'PHP code to parse.'),
-            new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse', 10),
-        );
+        $definition = [
+            new CodeArgument('code', CodeArgument::REQUIRED, 'PHP code to parse.'),
+            new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse.', 10),
+        ];
 
         if ($this->parserFactory->hasKindsSupport()) {
             $msg = 'One of PhpParser\\ParserFactory constants: '
                 . implode(', ', ParserFactory::getPossibleKinds())
-                . " (default is based on current interpreter's version)";
+                . " (default is based on current interpreter's version).";
             $defaultKind = $this->parserFactory->getDefaultKind();
 
             $definition[] = new InputOption('kind', '', InputOption::VALUE_REQUIRED, $msg, $defaultKind);
@@ -118,6 +136,8 @@ HELP
         $depth      = $input->getOption('depth');
         $nodes      = $this->parse($this->getParser($parserKind), $code);
         $output->page($this->presenter->present($nodes, $depth));
+
+        $this->context->setReturnValue($nodes);
     }
 
     /**