diff --git a/core/lib/Drupal/Component/Yaml/Pecl.php b/core/lib/Drupal/Component/Yaml/Pecl.php index a63848e..635b277 100644 --- a/core/lib/Drupal/Component/Yaml/Pecl.php +++ b/core/lib/Drupal/Component/Yaml/Pecl.php @@ -12,17 +12,17 @@ */ class Pecl implements YamlInterface { - /* - * Implements Drupal\Component\Yaml\YamlInterface::__construct(). + /** + * Sets defaults according to Drupal coding standards. */ - public function __construct($indentation = 2) { - ini_set('yaml.output_indent', $indentation); + public function __construct() { + ini_set('yaml.output_indent', 2); // Don't break Yaml files at 80 characters. ini_set('yaml.output_width', -1); } - /* - * Implements Drupal\Component\Yaml\YamlInterface::parse(). + /** + * {@inheritdoc} */ public function parse($input) { // Prevent PHP warning if $input is empty. @@ -32,8 +32,8 @@ public function parse($input) { return yaml_parse($input); } - /* - * Implements Drupal\Component\Yaml\YamlInterface::dump(). + /** + * {@inheritdoc} */ public function dump($value) { return yaml_emit($value); diff --git a/core/lib/Drupal/Component/Yaml/Symfony.php b/core/lib/Drupal/Component/Yaml/Symfony.php index 667e38e..342752e 100644 --- a/core/lib/Drupal/Component/Yaml/Symfony.php +++ b/core/lib/Drupal/Component/Yaml/Symfony.php @@ -20,7 +20,7 @@ class Symfony implements YamlInterface { * * @var int */ - protected $indentation; + protected $indentation = 2; /** * A shared YAML dumper instance. @@ -36,22 +36,15 @@ class Symfony implements YamlInterface { */ protected $parser; - /* - * Implements Drupal\Component\Yaml\YamlInterface::__construct(). - */ - public function __construct($indentation=2) { - $this->indentation = $indentation; - } - - /* - * Implements Drupal\Component\Yaml\YamlInterface::parse(). + /** + * {@inheritdoc} */ public function parse($input) { return $this->getParser()->parse($input); } - /* - * Implements Drupal\Component\Yaml\YamlInterface::dump(). + /** + * {@inheritdoc} */ public function dump($value) { // The level where you switch to inline YAML is set to PHP_INT_MAX to ensure diff --git a/core/lib/Drupal/Component/Yaml/Yaml.php b/core/lib/Drupal/Component/Yaml/Yaml.php index dcef286..0a16f01 100644 --- a/core/lib/Drupal/Component/Yaml/Yaml.php +++ b/core/lib/Drupal/Component/Yaml/Yaml.php @@ -11,9 +11,9 @@ * Factory class for Yaml. * * Determines which Yaml implementation to use, and uses that to parse - * and encode yaml. + * and encode Yaml. */ -class Yaml { +class Yaml implements YamlInterface { /** * Holds the Yaml implementation. @@ -31,26 +31,14 @@ public function __construct() { } /** - * Parses Yaml string. - * - * @param string input - * - * @see Drupal\Component\Yaml\YamlInterface::parse() + * {@inheritdoc} */ public function parse($input) { return $this->plugin->parse($input); } /** - * Parses Yaml. - * - * @see Drupal\Component\Yaml\YamlInterface::dump() - * - * @param mixed $value - * PHP value. - * - * @return string - * Yaml string. + * {@inheritdoc} */ public function dump($value) { return $this->plugin->dump($value); diff --git a/core/lib/Drupal/Component/Yaml/YamlInterface.php b/core/lib/Drupal/Component/Yaml/YamlInterface.php index 6415486..6b0e575 100644 --- a/core/lib/Drupal/Component/Yaml/YamlInterface.php +++ b/core/lib/Drupal/Component/Yaml/YamlInterface.php @@ -12,14 +12,6 @@ */ interface YamlInterface { - /* - * Constructs an Yaml parser and dumper. - * - * @param int $indentation - * Number of spaces to indent sections. Value should be between 1 and 10. - */ - public function __construct($indentation = 2); - /** * Parses a Yaml string to PHP value. * diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index 69daaeb..c9ea18d 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -123,7 +123,7 @@ public function rename($name, $new_name) { /** * Gets the YAML instance. * - * @return Symfony\Component\Yaml\Dumper + * @return \Drupal\Component\Yaml\YamlInterface */ protected function getYaml() { if (!isset($this->yaml)) { diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php index bd69f0f..c9c3c6e 100644 --- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php @@ -7,12 +7,12 @@ namespace Drupal\Core\DependencyInjection; +use Drupal\Component\Yaml\Yaml; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Yaml\Parser; /** * YamlFileLoader loads YAML files service definitions. @@ -24,12 +24,20 @@ class YamlFileLoader { /** + * A YAML file parser. + * + * @var \Drupal\Component\Yaml\YamlInterface + */ + protected $yaml; + + /** * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container */ protected $container; public function __construct(ContainerBuilder $container) { $this->container = $container; + $this->yaml = new Yaml(); } /** @@ -178,8 +186,7 @@ protected function parseDefinition($id, $service, $filename) { * The file content. */ protected function loadFile($filename) { - $parser = new Parser(); - return $this->validate($parser->parse(file_get_contents($filename)), $filename); + return $this->validate($this->yaml->parse(file_get_contents($filename)), $filename); } /** diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 3a5ffbe..a52e271 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Extension; use Drupal\Component\Graph\Graph; -use Symfony\Component\Yaml\Parser; +use Drupal\Component\Yaml\Yaml; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; @@ -834,6 +834,7 @@ public function uninstall($module_list = array(), $uninstall_dependents = TRUE) $schema_store = \Drupal::keyValue('system.schema'); $disabled_config = config('system.module.disabled'); + $yaml = new Yaml(); foreach ($module_list as $module) { // Uninstall the module. module_load_install($module); @@ -846,8 +847,7 @@ public function uninstall($module_list = array(), $uninstall_dependents = TRUE) // Remove any cache bins defined by the module. $service_yaml_file = drupal_get_path('module', $module) . "/$module.services.yml"; if (file_exists($service_yaml_file)) { - $parser = new Parser; - $definitions = $parser->parse(file_get_contents($service_yaml_file)); + $definitions = $yaml->parse(file_get_contents($service_yaml_file)); if (isset($definitions['services'])) { foreach ($definitions['services'] as $id => $definition) { if (isset($definition['tags'])) {