Chris@0: '\Drupal\Component\Serialization\YamlPecl::applyBooleanCallbacks', Chris@0: ]); Chris@0: restore_error_handler(); Chris@0: return $data; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Handles errors for \Drupal\Component\Serialization\YamlPecl::decode(). Chris@0: * Chris@0: * @param int $severity Chris@0: * The severity level of the error. Chris@0: * @param string $message Chris@0: * The error message to display. Chris@0: * Chris@0: * @see \Drupal\Component\Serialization\YamlPecl::decode() Chris@0: */ Chris@0: public static function errorHandler($severity, $message) { Chris@0: restore_error_handler(); Chris@0: throw new InvalidDataTypeException($message, $severity); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getFileExtension() { Chris@0: return 'yml'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Applies callbacks after parsing to ignore 1.1 style booleans. Chris@0: * Chris@0: * @param mixed $value Chris@0: * Value from YAML file. Chris@0: * @param string $tag Chris@0: * Tag that triggered the callback. Chris@0: * @param int $flags Chris@0: * Scalar entity style flags. Chris@0: * Chris@0: * @return string|bool Chris@0: * FALSE, false, TRUE and true are returned as booleans, everything else is Chris@0: * returned as a string. Chris@0: */ Chris@0: public static function applyBooleanCallbacks($value, $tag, $flags) { Chris@0: // YAML 1.1 spec dictates that 'Y', 'N', 'y' and 'n' are booleans. But, we Chris@0: // want the 1.2 behavior, so we only consider 'false', 'FALSE', 'true' and Chris@0: // 'TRUE' as booleans. Chris@0: if (!in_array(strtolower($value), ['false', 'true'], TRUE)) { Chris@0: return $value; Chris@0: } Chris@0: $map = [ Chris@0: 'false' => FALSE, Chris@0: 'true' => TRUE, Chris@0: ]; Chris@0: return $map[strtolower($value)]; Chris@0: } Chris@0: Chris@0: }