diff --git a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php index a1cddfb..cadbc9c 100644 --- a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php +++ b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php @@ -29,11 +29,11 @@ class YamlDiscovery implements DiscoverableInterface { protected $directories = array(); /** - * The symfony YAML parser. + * The YAML parser. * - * @var \Symfony\Component\Yaml\Parser + * @var \Drupal\Component\Yaml\Yaml */ - protected $parser; + protected $yaml; /** * Constructs a YamlDiscovery object. diff --git a/core/lib/Drupal/Component/Yaml/Symfony.php b/core/lib/Drupal/Component/Yaml/Symfony.php index 342752e..e262765 100644 --- a/core/lib/Drupal/Component/Yaml/Symfony.php +++ b/core/lib/Drupal/Component/Yaml/Symfony.php @@ -11,7 +11,7 @@ use Symfony\Component\Yaml\Parser; /** - * Yaml implementation using the Symfony classes. + * YAML implementation using the Symfony parser. */ class Symfony implements YamlInterface { diff --git a/core/lib/Drupal/Component/Yaml/Yaml.php b/core/lib/Drupal/Component/Yaml/Yaml.php index 4ff4c7c..e8cb4d3 100644 --- a/core/lib/Drupal/Component/Yaml/Yaml.php +++ b/core/lib/Drupal/Component/Yaml/Yaml.php @@ -8,22 +8,29 @@ namespace Drupal\Component\Yaml; /** - * Factory class for Yaml. + * Factory class for YAML parsing. * - * Determines which Yaml implementation to use, and uses that to parse - * and encode Yaml. + * Determines which YAML implementation to use, and uses that to parse + * and encode YAML. */ class Yaml implements YamlInterface { /** - * Holds the Yaml implementation. + * The YAML plugin class to use. + * + * @var string + */ + protected static $pluginClass; + + /** + * Holds the YAML implementation. * * @var \Drupal\Component\Yaml\YamlInterface */ protected $plugin; /** - * Instantiates the correct Yaml object. + * Instantiates the correct YAML object. */ public function __construct() { $class = $this->determinePlugin(); @@ -51,21 +58,22 @@ public function dump($value) { * most performant available option chosen. * * @return string - * The class name for the optimal Yaml implementation. + * The class name for the optimal YAML implementation. */ protected function determinePlugin() { - static $plugin; - if (!empty($plugin)) { - return $plugin; + if (isset(static::$pluginClass)) { + return static::$pluginClass; } - // Fallback to the Symfony implementation. - $plugin = 'Drupal\Component\Yaml\Symfony'; - - // Is the PECL Yaml extension installed + // If the PECL YAML extension installed, use that. if (function_exists('yaml_emit')) { - $plugin = 'Drupal\Component\Yaml\Pecl'; + static::$pluginClass = 'Drupal\Component\Yaml\Pecl'; + } + else { + // Otherwise, fallback to the Symfony implementation. + static::$pluginClass = 'Drupal\Component\Yaml\Symfony'; } - return $plugin; + + return static::$pluginClass; } } diff --git a/core/lib/Drupal/Component/Yaml/YamlInterface.php b/core/lib/Drupal/Component/Yaml/YamlInterface.php index 6b0e575..ecf03a1 100644 --- a/core/lib/Drupal/Component/Yaml/YamlInterface.php +++ b/core/lib/Drupal/Component/Yaml/YamlInterface.php @@ -8,17 +8,17 @@ namespace Drupal\Component\Yaml; /** - * Interface that defines a Yaml backend. + * Interface that defines a YAML parser. */ interface YamlInterface { /** - * Parses a Yaml string to PHP value. + * Parses a YAML string to PHP value. * * If $input is empty this should return NULL and not produce a PHP warning. * * @param string $input - * Yaml string to parse. + * The YAML string to parse. * * @return mixed * A PHP value. @@ -26,13 +26,13 @@ public function parse($input); /** - * Dumps a PHP value to Yaml string. + * Dumps a PHP value to YAML string. * * @param mixed $input * The PHP value. * * @return string - * Yaml string. + * The dumped YAML string. */ public function dump($input); diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index d6a4c1b..369ed13 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -134,11 +134,13 @@ public function rename($name, $new_name) { * Gets the YAML instance. * * @return \Drupal\Component\Yaml\YamlInterface + * The YAML parser. */ protected function getYaml() { if (!isset($this->yaml)) { - $this->yaml = new Yaml; + $this->yaml = new Yaml(); } + return $this->yaml; } diff --git a/core/lib/Drupal/Core/Extension/InfoParser.php b/core/lib/Drupal/Core/Extension/InfoParser.php index 06e18b3..c55d1df 100644 --- a/core/lib/Drupal/Core/Extension/InfoParser.php +++ b/core/lib/Drupal/Core/Extension/InfoParser.php @@ -62,13 +62,14 @@ public function parse($filename) { /** * Returns a parser for parsing .info.yml files. * - * @return \Symfony\Component\Yaml\Parser - * Symfony YAML parser object. + * @return \Drupal\Component\Yaml\YamlInterface + * The YAML parser. */ protected function getYaml() { if (!$this->yaml) { $this->yaml = new Yaml(); } + return $this->yaml; }