Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Escaper.php

function Escaper::requiresSingleQuoting

Determines if a PHP value would require single quoting in YAML.

Parameters

string $value A PHP value:

1 call to Escaper::requiresSingleQuoting()
Inline::dump in vendor/symfony/yaml/Inline.php
Dumps a given PHP variable to a YAML string.

File

vendor/symfony/yaml/Escaper.php, line 73

Class

Escaper
Escaper encapsulates escaping rules for single and double-quoted YAML strings.

Namespace

Symfony\Component\Yaml

Code

public static function requiresSingleQuoting(string $value) : bool {
    // Determines if a PHP value is entirely composed of a value that would
    // require single quoting in YAML.
    if (\in_array(strtolower($value), [
        'null',
        '~',
        'true',
        'false',
        'y',
        'n',
        'yes',
        'no',
        'on',
        'off',
    ])) {
        return true;
    }
    // Determines if the PHP value contains any single characters that would
    // cause it to require single quoting in YAML.
    return 0 < preg_match('/[\\s\'"\\:\\{\\}\\[\\],&\\*\\#\\?] | \\A[\\-?|<>=!%@`\\p{Zs}]/xu', $value);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal