diff --git a/core/includes/common.inc b/core/includes/common.inc index 11f8a9d..6ea9bf9 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -9,30 +9,22 @@ */ use Drupal\Component\Serialization\Json; -use Drupal\Component\Serialization\Yaml; -use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Html; -use Drupal\Component\Utility\Number; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\SortArray; use Drupal\Component\Utility\String; -use Drupal\Component\Utility\Tags; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; -use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Routing\GeneratorNotInitializedException; use Drupal\Core\Template\Attribute; use Drupal\Core\Render\Element; -use Drupal\Core\Session\AnonymousUserSession; /** * @defgroup php_wrappers PHP wrapper functions diff --git a/core/lib/Drupal/Component/Serialization/Yaml.php b/core/lib/Drupal/Component/Serialization/Yaml.php index 7d0f0c5..fcc4baf 100644 --- a/core/lib/Drupal/Component/Serialization/Yaml.php +++ b/core/lib/Drupal/Component/Serialization/Yaml.php @@ -7,36 +7,56 @@ namespace Drupal\Component\Serialization; -use Drupal\Component\Serialization\Exception\InvalidDataTypeException; -use Symfony\Component\Yaml\Yaml as Symfony; - /** * Default serialization for YAML using the Symfony component. */ class Yaml implements SerializationInterface { /** + * The YAML implementation to use. + * + * @var \Drupal\Component\Serialization\SerializationInterface + */ + protected static $instance; + + /** + * Determines the optimal implementation to use for encoding and parsing Yaml. + * + * The selection is made based on the enabled PHP extensions, with the most + * performant available option chosen. + */ + public function __construct() { + if (isset(static::$instance)) { + return; + } + // If the PECL YAML extension installed, use that. + if (extension_loaded('yaml')) { + static::$instance = new YamlPecl(); + } + else { + // Otherwise, fallback to the Symfony implementation. + static::$instance = new YamlSymfony(); + } + } + + /** * {@inheritdoc} */ public static function encode($data) { - try { - return Symfony::dump($data, PHP_INT_MAX, 2, TRUE); - } - catch (\Exception $e) { - throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); + if (!isset(static::$instance)) { + new static(); } + return static::$instance->encode($data); } /** * {@inheritdoc} */ public static function decode($raw) { - try { - return Symfony::parse($raw, TRUE); - } - catch (\Exception $e) { - throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); + if (!isset(static::$instance)) { + new static(); } + return static::$instance->decode($raw); } /** diff --git a/core/lib/Drupal/Component/Serialization/YamlPecl.php b/core/lib/Drupal/Component/Serialization/YamlPecl.php new file mode 100644 index 0000000..7d5b586 --- /dev/null +++ b/core/lib/Drupal/Component/Serialization/YamlPecl.php @@ -0,0 +1,113 @@ + '\Drupal\Component\Serialization\YamlPecl::applyBooleanCallbacks', + YAML_SEQ_TAG => '\Drupal\Component\Serialization\YamlPecl::applySequenceCallbacks' + ]); + restore_error_handler(); + return $data; + } + + /** + * Temporary error handler for YamlPecl::decode(). + */ + public static function errorHandler($severity, $message, $file, $line) { + restore_error_handler(); + throw new InvalidDataTypeException($message, $severity); + } + + /** + * {@inheritdoc} + */ + public static function getFileExtension() { + return 'yml'; + } + + /** + * Applies callbacks after parsing to ignore 1.1 style booleans. + * + * @param mixed $value + * Value from YAML file. + * @param string $tag + * Tag that triggered the callback. + * @param int $flags + * Scalar entity style flags. + * + * @return string|bool + * FALSE, false, TRUE and true are returned as booleans, everything else is + * returned as a string. + */ + public static function applyBooleanCallbacks($value, $tag, $flags) { + // YAML 1.1 spec dictates that 'Y', 'N', 'y' and 'n' are booleans, we want + // the 1.2 behaviour so we only case 'false', 'FALSE', 'true' OR 'TRUE' as + // booleans. + if (!in_array(strtolower($value), ['false', 'true'], TRUE)) { + return $value; + } + $map = [ + 'false' => FALSE, + 'true' => TRUE, + ]; + return $map[strtolower($value)]; + } + + /** + * Applies sequence after parsing to ignore 1.1 issues. + * + * @param mixed $value + * Value from YAML file. + * @param string $tag + * Tag that triggered the callback. + * @param int $flags + * Scalar entity style flags. + * + * @return array|string + * Yaml 1.1 decodes - - as an array containg a NULL, in 1.2 it should be the + * string '-'. + */ + public static function applySequenceCallbacks($value, $tag, $flags) { + if ($value == [NULL]) { + return '-'; + } + return $value; + } + +} diff --git a/core/lib/Drupal/Component/Serialization/Yaml.php b/core/lib/Drupal/Component/Serialization/YamlSymfony.php similarity index 88% copy from core/lib/Drupal/Component/Serialization/Yaml.php copy to core/lib/Drupal/Component/Serialization/YamlSymfony.php index 7d0f0c5..2d71b7c 100644 --- a/core/lib/Drupal/Component/Serialization/Yaml.php +++ b/core/lib/Drupal/Component/Serialization/YamlSymfony.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Component\Serialization\Yaml. + * Contains \Drupal\Component\Serialization\YamlSymfony. */ namespace Drupal\Component\Serialization; @@ -13,7 +13,7 @@ /** * Default serialization for YAML using the Symfony component. */ -class Yaml implements SerializationInterface { +class YamlSymfony implements SerializationInterface { /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 5ff88b2..2be5420 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -12,7 +12,7 @@ use Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; /** * Parses library files to get extension data. diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index a97cf72..d83a4ec 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Diff\Diff; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; use Drupal\Core\Config\Entity\ConfigDependencyManager; use Drupal\Core\Config\Entity\ConfigEntityDependency; use Drupal\Core\Entity\EntityManagerInterface; diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index f404480..384e669 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Config; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Utility\String; diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php index d4ae53e..2c2eaef 100644 --- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php @@ -7,7 +7,7 @@ namespace Drupal\Core\DependencyInjection; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; diff --git a/core/lib/Drupal/Core/Discovery/YamlDiscovery.php b/core/lib/Drupal/Core/Discovery/YamlDiscovery.php new file mode 100644 index 0000000..bac6219 --- /dev/null +++ b/core/lib/Drupal/Core/Discovery/YamlDiscovery.php @@ -0,0 +1,30 @@ +findFiles() as $provider => $file) { + $all[$provider] = Yaml::decode(file_get_contents($file)); + } + + return $all; + } + +} diff --git a/core/lib/Drupal/Core/Extension/InfoParser.php b/core/lib/Drupal/Core/Extension/InfoParser.php index de1b24a..013453d 100644 --- a/core/lib/Drupal/Core/Extension/InfoParser.php +++ b/core/lib/Drupal/Core/Extension/InfoParser.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Extension; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Utility\String; diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 73278d3..48009a1 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Extension; -use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Serialization\Yaml; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DrupalKernelInterface; diff --git a/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php index 0b7d10f6..9803171 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Plugin\Discovery; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Component\Discovery\YamlDiscovery as ComponentYamlDiscovery; +use Drupal\Core\Discovery\YamlDiscovery as CoreYamlDiscovery; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; /** @@ -35,7 +35,7 @@ class YamlDiscovery implements DiscoveryInterface { * An array of directories to scan. */ function __construct($name, array $directories) { - $this->discovery = new ComponentYamlDiscovery($name, $directories); + $this->discovery = new CoreYamlDiscovery($name, $directories); } /** diff --git a/core/lib/Drupal/Core/Serialization/Yaml.php b/core/lib/Drupal/Core/Serialization/Yaml.php new file mode 100644 index 0000000..ff663d8 --- /dev/null +++ b/core/lib/Drupal/Core/Serialization/Yaml.php @@ -0,0 +1,48 @@ +get('yaml_parser_class'))) { + static::$instance = new $class(); + } + // If the PECL YAML extension installed, use that. + elseif (extension_loaded('yaml')) { + static::$instance = new YamlPecl(); + } + else { + // Otherwise, fallback to the Symfony implementation. + static::$instance = new YamlSymfony(); + } + } + +} diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml index 494752c..28e1821 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml @@ -61,7 +61,7 @@ process: source: - region - theme - - @theme + - '@theme' region_map: left: sidebar_first right: sidebar_second @@ -75,7 +75,7 @@ process: settings: plugin: d6_block_settings source: - - @plugin + - '@plugin' - delta - settings visibility: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml index 72ae39b..0e4b579 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml @@ -127,7 +127,7 @@ process: settings: plugin: field_settings source: - - @type + - '@type' - global_settings - widget_settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_filter_format.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_filter_format.yml index e6c86df..c2123d9 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_filter_format.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_filter_format.yml @@ -19,7 +19,7 @@ process: filters: plugin: iterator source: filters - key: @id + key: '@id' process: id: plugin: static_map diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml index 1cafbe9..f8fe199 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml @@ -27,10 +27,10 @@ process: source: - link_path - options - route_name: @route/route_name - route_parameters: @route/route_parameters - url: @route/url - options: @route/options + route_name: '@route/route_name' + route_parameters: '@route/route_parameters' + url: '@route/url' + options: '@route/options' external: external weight: weight expanded: expanded diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml index 9e1d7e7..9df3613 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml @@ -19,7 +19,7 @@ process: field_name: 'constants/name' type: 'constants/type' options: 'constants/options' - 'options/type': @type + 'options/type': '@type' destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml index f19d033..eb128d5 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml @@ -20,7 +20,7 @@ process: form_mode: 'constants/form_mode' type: 'constants/type' options: 'constants/options' - 'options/type': @type + 'options/type': '@type' destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml index afbf438..b53017f 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml @@ -22,7 +22,7 @@ process: field_name: 'constants/name' type: 'constants/type' options: 'constants/options' - 'options/type': @type + 'options/type': '@type' destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml index d2d7b14..69ca02d 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml @@ -21,7 +21,7 @@ process: form_mode: 'constants/form_mode' type: 'constants/type' options: 'constants/options' - 'options/type': @type + 'options/type': '@type' destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml index 32dcf1b..62ca89e 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml @@ -28,7 +28,7 @@ process: textarea: text_default url: link_default options: 'constants/options' - 'options/type': @type + 'options/type': '@type' hidden: plugin: static_map source: visibility diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml index e09b608..4b33943 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml @@ -26,11 +26,11 @@ process: textarea: text_textarea url: link_default options: 'constants/options' - 'options/type': @type + 'options/type': '@type' 'options/settings': plugin: field_instance_widget_settings source: - - @type + - '@type' - 'constants/empty' # we don't have any settings. 'options/settings/display_label': # Single on/off checkboxes need to have display_label = true otherwise their label doesn't show. plugin: static_map diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml index a833cbd..a1392e2 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml @@ -16,7 +16,7 @@ process: plugin: migration migration: d6_taxonomy_vocabulary source: vid - 'settings/allowed_values/0/vocabulary': @field_name + 'settings/allowed_values/0/vocabulary': '@field_name' 'settings/allowed_values/0/parent': 'constants/parent' cardinality: 'constants/cardinality' destination: diff --git a/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php b/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php index b925285..4669e03 100644 --- a/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php +++ b/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php @@ -81,7 +81,8 @@ public function testInfoParser() { $info_values = $this->infoParser->parse('core/modules/system/tests/fixtures/common_test.info.txt'); $this->assertEqual($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.', 'System'); $this->assertEqual($info_values['version'], \Drupal::VERSION, 'Constant value was parsed correctly.', 'System'); - $this->assertEqual($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.', 'System'); + debug($info_values); + $this->assertEqual($info_values['double_colon'], 'dummyClassName::foo', 'Value containing double-colon was parsed correctly.', 'System'); } } diff --git a/core/modules/system/tests/fixtures/common_test.info.txt b/core/modules/system/tests/fixtures/common_test.info.txt index 7e57dfe..ff535b1 100644 --- a/core/modules/system/tests/fixtures/common_test.info.txt +++ b/core/modules/system/tests/fixtures/common_test.info.txt @@ -4,4 +4,4 @@ type: module description: 'testing info file parsing' simple_string: 'A simple string' version: "VERSION" -double_colon: dummyClassName:: +double_colon: dummyClassName::foo diff --git a/core/modules/text/config/schema/text.data_types.schema.yml b/core/modules/text/config/schema/text.data_types.schema.yml deleted file mode 100644 index e69de29..0000000 diff --git a/core/modules/user/config/schema/user.views.schema.yml b/core/modules/user/config/schema/user.views.schema.yml index 31b3950..6089c6f 100644 --- a/core/modules/user/config/schema/user.views.schema.yml +++ b/core/modules/user/config/schema/user.views.schema.yml @@ -68,17 +68,13 @@ views_field_user: label: 'Link this field to its user' views.field.user_language: - type: views_field + type: views_field_user label: 'User language' mapping: link_to_node: type: boolean label: 'Link this field to its user' -views.field.user_language: - type: views_field_user - label: 'User language' - views.field.user_link: type: views_field label: 'User link' diff --git a/core/modules/views/config/schema/views.data_types.schema.yml b/core/modules/views/config/schema/views.data_types.schema.yml index 64ff9c4..7cf0cad 100644 --- a/core/modules/views/config/schema/views.data_types.schema.yml +++ b/core/modules/views/config/schema/views.data_types.schema.yml @@ -365,7 +365,6 @@ views_argument: label: 'Override title' title: type: label - label: 'Title' label: 'Overridden title' default_argument_type: type: string diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php new file mode 100644 index 0000000..2bd3764 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php @@ -0,0 +1,157 @@ +markTestSkipped('The PECL Yaml extension is not available.'); + } + } + + /** + * Tests encoding with Symfony and decoding with PECL and vice versa. + * + * @dataProvider providerYamlData + * @covers \Drupal\Component\Serialization\Yaml::encode + * @covers \Drupal\Component\Serialization\Yaml::decode + * @covers \Drupal\Component\Serialization\YamlPecl::encode + * @covers \Drupal\Component\Serialization\YamlPecl::decode + * @covers \Drupal\Component\Serialization\YamlSymfony::encode + * @covers \Drupal\Component\Serialization\YamlSymfony::decode + */ + public function testEncodeDecode($data, $parser_class, $dumper_class) { + $dumper = new $dumper_class; + $parser = new $parser_class; + + $dumped = $dumper->encode($data); + + $parsed = $parser->decode($dumped); + + $this->assertEquals($data, $parsed); + } + + /** + * Tests decoding YAML node anchors with both Symfony and PECL. + * + * @dataProvider providerYamlNodeAnchors + */ + public function testDecodeNodeAnchors($data) { + $symfony = new YamlSymfony(); + $pecl = new YamlPecl(); + $this->assertEquals($symfony->decode($data), $pecl->decode($data)); + } + + /** + * Data provider for YAML instance tests. + * + * @return array + */ + public function providerYamlData() { + $object = array( + 'foo' => 'bar', + 'id' => 'schnitzel', + 'ponies' => array('nope', 'thanks'), + 'how' => array( + 'about' => 'if', + 'i' => 'ask', + 'nicely' + ), + 'the' => array( + 'answer' => array( + 'still' => 'would', + 'be' => 'Y', + ), + ), + 'how_many_times' => 123, + 'should_i_ask' => FALSE, + 1, + FALSE, + array(1, FALSE), + array(10), + array(0 => '123456'), + ); + + // Test parsing with Symfony and dumping with PECL. + $data[] = array( + $object, + 'Drupal\Component\Serialization\YamlSymfony', + 'Drupal\Component\Serialization\YamlPecl' + ); + // Test parsing with PECL and dumping with Symfony. + $data[] = array( + $object, + 'Drupal\Component\Serialization\YamlPecl', + 'Drupal\Component\Serialization\YamlSymfony' + ); + return $data; + } + + /** + * Data provider for YAML instance tests. + * + * @return array + */ + public function providerYamlNodeAnchors() { + $yaml = <<assertEquals($symfony->decode($data), $pecl->decode($data)); + } + + /** + * Data provider for YAML files in core test. + * @return array + */ + public function providerYamlFilesInCore() { + $files = array(); + $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../../../../', \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); + foreach ($dirs as $dir) { + $pathname = $dir->getPathname(); + // Exclude vendor. + if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../vendor') === FALSE) { + if (strpos($dir->getRealPath(), 'invalid_file') !== FALSE) { + // There are some intentionally invalid files provided for testing + // library API behaviours, ignore them. + continue; + } + $files[] = array($dir->getRealPath()); + } + } + return $files; + } + +}