Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / psy / psysh / src / Configuration.php
similarity index 89%
rename from vendor/psy/psysh/src/Psy/Configuration.php
rename to vendor/psy/psysh/src/Configuration.php
index b0953fabf66d929e9dc3f609fa450bbe5a09c45f..82d20eee28a06bfba0288da4980f9fb01e424a77 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,8 +13,6 @@ namespace Psy;
 
 use Psy\Exception\DeprecatedException;
 use Psy\Exception\RuntimeException;
-use Psy\ExecutionLoop\ForkingLoop;
-use Psy\ExecutionLoop\Loop;
 use Psy\Output\OutputPager;
 use Psy\Output\ShellOutput;
 use Psy\Readline\GNUReadline;
@@ -28,7 +26,6 @@ use Psy\VersionUpdater\Checker;
 use Psy\VersionUpdater\GitHubChecker;
 use Psy\VersionUpdater\IntervalChecker;
 use Psy\VersionUpdater\NoopChecker;
-use XdgBaseDir\Xdg;
 
 /**
  * The Psy Shell configuration.
@@ -39,7 +36,7 @@ class Configuration
     const COLOR_MODE_FORCED   = 'forced';
     const COLOR_MODE_DISABLED = 'disabled';
 
-    private static $AVAILABLE_OPTIONS = array(
+    private static $AVAILABLE_OPTIONS = [
         'codeCleaner',
         'colorMode',
         'configDir',
@@ -49,21 +46,20 @@ class Configuration
         'errorLoggingLevel',
         'forceArrayIndexes',
         'historySize',
-        'loop',
         'manualDbFile',
         'pager',
         'prompt',
         'requireSemicolons',
         'runtimeDir',
         'startupMessage',
-        'tabCompletion',
         'updateCheck',
         'useBracketedPaste',
         'usePcntl',
         'useReadline',
+        'useTabCompletion',
         'useUnicode',
         'warnOnMultipleConfigs',
-    );
+    ];
 
     private $defaultIncludes;
     private $configDir;
@@ -80,12 +76,12 @@ class Configuration
     private $useBracketedPaste;
     private $hasPcntl;
     private $usePcntl;
-    private $newCommands       = array();
+    private $newCommands       = [];
     private $requireSemicolons = false;
     private $useUnicode;
-    private $tabCompletion;
-    private $tabCompletionMatchers = array();
-    private $errorLoggingLevel     = E_ALL;
+    private $useTabCompletion;
+    private $newMatchers = [];
+    private $errorLoggingLevel = E_ALL;
     private $warnOnMultipleConfigs = false;
     private $colorMode;
     private $updateCheck;
@@ -98,10 +94,9 @@ class Configuration
     private $shell;
     private $cleaner;
     private $pager;
-    private $loop;
     private $manualDb;
     private $presenter;
-    private $completer;
+    private $autoCompleter;
     private $checker;
     private $prompt;
 
@@ -112,7 +107,7 @@ class Configuration
      *
      * @param array $config Optional array of configuration values
      */
-    public function __construct(array $config = array())
+    public function __construct(array $config = [])
     {
         $this->setColorMode(self::COLOR_MODE_AUTO);
 
@@ -125,8 +120,8 @@ class Configuration
 
         // legacy baseDir option
         if (isset($config['baseDir'])) {
-            $msg = "The 'baseDir' configuration option is deprecated. " .
-                "Please specify 'configDir' and 'dataDir' options instead.";
+            $msg = "The 'baseDir' configuration option is deprecated; " .
+                "please specify 'configDir' and 'dataDir' options instead";
             throw new DeprecatedException($msg);
         }
 
@@ -182,7 +177,7 @@ class Configuration
             return $this->configFile;
         }
 
-        $files = ConfigPaths::getConfigFiles(array('config.php', 'rc.php'), $this->configDir);
+        $files = ConfigPaths::getConfigFiles(['config.php', 'rc.php'], $this->configDir);
 
         if (!empty($files)) {
             if ($this->warnOnMultipleConfigs && count($files) > 1) {
@@ -225,12 +220,28 @@ class Configuration
             }
         }
 
-        foreach (array('commands', 'tabCompletionMatchers', 'casters') as $option) {
+        // legacy `tabCompletion` option
+        if (isset($options['tabCompletion'])) {
+            $msg = '`tabCompletion` is deprecated; use `useTabCompletion` instead.';
+            @trigger_error($msg, E_USER_DEPRECATED);
+
+            $this->setUseTabCompletion($options['tabCompletion']);
+        }
+
+        foreach (['commands', 'matchers', 'casters'] as $option) {
             if (isset($options[$option])) {
                 $method = 'add' . ucfirst($option);
                 $this->$method($options[$option]);
             }
         }
+
+        // legacy `tabCompletionMatchers` option
+        if (isset($options['tabCompletionMatchers'])) {
+            $msg = '`tabCompletionMatchers` is deprecated; use `matchers` instead.';
+            @trigger_error($msg, E_USER_DEPRECATED);
+
+            $this->addMatchers($options['tabCompletionMatchers']);
+        }
     }
 
     /**
@@ -269,7 +280,7 @@ class Configuration
      *
      * @param array $includes
      */
-    public function setDefaultIncludes(array $includes = array())
+    public function setDefaultIncludes(array $includes = [])
     {
         $this->defaultIncludes = $includes;
     }
@@ -281,7 +292,7 @@ class Configuration
      */
     public function getDefaultIncludes()
     {
-        return $this->defaultIncludes ?: array();
+        return $this->defaultIncludes ?: [];
     }
 
     /**
@@ -379,26 +390,7 @@ class Configuration
             return $this->historyFile;
         }
 
-        // Deprecation warning for incorrect psysh_history path.
-        // @todo remove this before v0.9.0
-        $xdg = new Xdg();
-        $oldHistory = $xdg->getHomeConfigDir() . '/psysh_history';
-        if (@is_file($oldHistory)) {
-            $dir = $this->configDir ?: ConfigPaths::getCurrentConfigDir();
-            $newHistory = $dir . '/psysh_history';
-
-            $msg = sprintf(
-                "PsySH history file found at '%s'. Please delete it or move it to '%s'.",
-                strtr($oldHistory, '\\', '/'),
-                $newHistory
-            );
-            @trigger_error($msg, E_USER_DEPRECATED);
-            $this->setHistoryFile($oldHistory);
-
-            return $this->historyFile;
-        }
-
-        $files = ConfigPaths::getConfigFiles(array('psysh_history', 'history'), $this->configDir);
+        $files = ConfigPaths::getConfigFiles(['psysh_history', 'history'], $this->configDir);
 
         if (!empty($files)) {
             if ($this->warnOnMultipleConfigs && count($files) > 1) {
@@ -767,24 +759,44 @@ class Configuration
     /**
      * Enable or disable tab completion.
      *
-     * @param bool $tabCompletion
+     * @param bool $useTabCompletion
      */
-    public function setTabCompletion($tabCompletion)
+    public function setUseTabCompletion($useTabCompletion)
     {
-        $this->tabCompletion = (bool) $tabCompletion;
+        $this->useTabCompletion = (bool) $useTabCompletion;
+    }
+
+    /**
+     * @deprecated Call `setUseTabCompletion` instead
+     *
+     * @param bool $useTabCompletion
+     */
+    public function setTabCompletion($useTabCompletion)
+    {
+        $this->setUseTabCompletion($useTabCompletion);
     }
 
     /**
      * Check whether to use tab completion.
      *
-     * If `setTabCompletion` has been set to true, but readline is not actually
-     * available, this will return false.
+     * If `setUseTabCompletion` has been set to true, but readline is not
+     * actually available, this will return false.
      *
      * @return bool True if the current Shell should use tab completion
      */
+    public function useTabCompletion()
+    {
+        return isset($this->useTabCompletion) ? ($this->hasReadline && $this->useTabCompletion) : $this->hasReadline;
+    }
+
+    /**
+     * @deprecated Call `useTabCompletion` instead
+     *
+     * @return bool
+     */
     public function getTabCompletion()
     {
-        return isset($this->tabCompletion) ? ($this->hasReadline && $this->tabCompletion) : $this->hasReadline;
+        return $this->useTabCompletion();
     }
 
     /**
@@ -850,7 +862,7 @@ class Configuration
     public function setPager($pager)
     {
         if ($pager && !is_string($pager) && !$pager instanceof OutputPager) {
-            throw new \InvalidArgumentException('Unexpected pager instance.');
+            throw new \InvalidArgumentException('Unexpected pager instance');
         }
 
         $this->pager = $pager;
@@ -880,81 +892,77 @@ class Configuration
     }
 
     /**
-     * Set the Shell evaluation Loop service.
+     * Set the Shell AutoCompleter service.
      *
-     * @param Loop $loop
+     * @param AutoCompleter $autoCompleter
      */
-    public function setLoop(Loop $loop)
+    public function setAutoCompleter(AutoCompleter $autoCompleter)
     {
-        $this->loop = $loop;
+        $this->autoCompleter = $autoCompleter;
     }
 
     /**
-     * Get a Shell evaluation Loop service instance.
-     *
-     * If none has been explicitly defined, this will create a new instance.
-     * If Pcntl is available and enabled, the new instance will be a ForkingLoop.
+     * Get an AutoCompleter service instance.
      *
-     * @return Loop
+     * @return AutoCompleter
      */
-    public function getLoop()
+    public function getAutoCompleter()
     {
-        if (!isset($this->loop)) {
-            if ($this->usePcntl()) {
-                $this->loop = new ForkingLoop($this);
-            } else {
-                $this->loop = new Loop($this);
-            }
+        if (!isset($this->autoCompleter)) {
+            $this->autoCompleter = new AutoCompleter();
         }
 
-        return $this->loop;
+        return $this->autoCompleter;
     }
 
     /**
-     * Set the Shell autocompleter service.
+     * @deprecated Nothing should be using this anymore
      *
-     * @param AutoCompleter $completer
+     * @return array
      */
-    public function setAutoCompleter(AutoCompleter $completer)
+    public function getTabCompletionMatchers()
     {
-        $this->completer = $completer;
+        return [];
     }
 
     /**
-     * Get an AutoCompleter service instance.
+     * Add tab completion matchers to the AutoCompleter.
      *
-     * @return AutoCompleter
+     * This will buffer new matchers in the event that the Shell has not yet
+     * been instantiated. This allows the user to specify matchers in their
+     * config rc file, despite the fact that their file is needed in the Shell
+     * constructor.
+     *
+     * @param array $matchers
      */
-    public function getAutoCompleter()
+    public function addMatchers(array $matchers)
     {
-        if (!isset($this->completer)) {
-            $this->completer = new AutoCompleter();
+        $this->newMatchers = array_merge($this->newMatchers, $matchers);
+        if (isset($this->shell)) {
+            $this->doAddMatchers();
         }
-
-        return $this->completer;
     }
 
     /**
-     * Get user specified tab completion matchers for the AutoCompleter.
-     *
-     * @return array
+     * Internal method for adding tab completion matchers. This will set any new
+     * matchers once a Shell is available.
      */
-    public function getTabCompletionMatchers()
+    private function doAddMatchers()
     {
-        return $this->tabCompletionMatchers;
+        if (!empty($this->newMatchers)) {
+            $this->shell->addMatchers($this->newMatchers);
+            $this->newMatchers = [];
+        }
     }
 
     /**
-     * Add additional tab completion matchers to the AutoCompleter.
+     * @deprecated Use `addMatchers` instead
      *
      * @param array $matchers
      */
     public function addTabCompletionMatchers(array $matchers)
     {
-        $this->tabCompletionMatchers = array_merge($this->tabCompletionMatchers, $matchers);
-        if (isset($this->shell)) {
-            $this->shell->addTabCompletionMatchers($this->tabCompletionMatchers);
-        }
+        $this->addMatchers($matchers);
     }
 
     /**
@@ -983,7 +991,7 @@ class Configuration
     {
         if (!empty($this->newCommands)) {
             $this->shell->addCommands($this->newCommands);
-            $this->newCommands = array();
+            $this->newCommands = [];
         }
     }
 
@@ -996,6 +1004,7 @@ class Configuration
     {
         $this->shell = $shell;
         $this->doAddCommands();
+        $this->doAddMatchers();
     }
 
     /**
@@ -1022,7 +1031,7 @@ class Configuration
             return $this->manualDbFile;
         }
 
-        $files = ConfigPaths::getDataFiles(array('php_manual.sqlite'), $this->dataDir);
+        $files = ConfigPaths::getDataFiles(['php_manual.sqlite'], $this->dataDir);
         if (!empty($files)) {
             if ($this->warnOnMultipleConfigs && count($files) > 1) {
                 $msg = sprintf('Multiple manual database files found: %s. Using %s', implode($files, ', '), $files[0]);
@@ -1118,11 +1127,11 @@ class Configuration
      */
     public function setColorMode($colorMode)
     {
-        $validColorModes = array(
+        $validColorModes = [
             self::COLOR_MODE_AUTO,
             self::COLOR_MODE_FORCED,
             self::COLOR_MODE_DISABLED,
-        );
+        ];
 
         if (in_array($colorMode, $validColorModes)) {
             $this->colorMode = $colorMode;
@@ -1209,13 +1218,13 @@ class Configuration
      */
     public function setUpdateCheck($interval)
     {
-        $validIntervals = array(
+        $validIntervals = [
             Checker::ALWAYS,
             Checker::DAILY,
             Checker::WEEKLY,
             Checker::MONTHLY,
             Checker::NEVER,
-        );
+        ];
 
         if (!in_array($interval, $validIntervals)) {
             throw new \InvalidArgumentException('invalid update check interval: ' . $interval);