function YamlPecl::applyBooleanCallbacks
Applies callbacks after parsing to ignore 1.1 style booleans.
Parameters
mixed $value: Value from YAML file.
string $tag: Tag that triggered the callback.
int $flags: Scalar entity style flags.
Return value
string|bool FALSE, false, TRUE and true are returned as booleans, everything else is returned as a string.
1 call to YamlPecl::applyBooleanCallbacks()
- YamlPeclTest::testApplyBooleanCallbacks in core/
tests/ Drupal/ Tests/ Component/ Serialization/ YamlPeclTest.php  - Tests YAML boolean callback.
 
File
- 
              core/
lib/ Drupal/ Component/ Serialization/ YamlPecl.php, line 96  
Class
- YamlPecl
 - Provides default serialization for YAML using the PECL extension.
 
Namespace
Drupal\Component\SerializationCode
public static function applyBooleanCallbacks($value, $tag, $flags) {
  // YAML 1.1 spec dictates that 'Y', 'N', 'y' and 'n' are booleans. But, we
  // want the 1.2 behavior, so we only consider 'false', 'FALSE', 'true' and
  // 'TRUE' as booleans.
  if (!in_array(strtolower($value), [
    'false',
    'true',
  ], TRUE)) {
    return $value;
  }
  $map = [
    'false' => FALSE,
    'true' => TRUE,
  ];
  return $map[strtolower($value)];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.