4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Drush\Internal\Config\Yaml;
14 use Drush\Internal\Config\Yaml\Exception\ParseException;
17 * Yaml offers convenience methods to load and dump YAML.
19 * @author Fabien Potencier <fabien@symfony.com>
23 const DUMP_OBJECT = 1;
24 const PARSE_EXCEPTION_ON_INVALID_TYPE = 2;
25 const PARSE_OBJECT = 4;
26 const PARSE_OBJECT_FOR_MAP = 8;
27 const DUMP_EXCEPTION_ON_INVALID_TYPE = 16;
28 const PARSE_DATETIME = 32;
29 const DUMP_OBJECT_AS_MAP = 64;
30 const DUMP_MULTI_LINE_LITERAL_BLOCK = 128;
31 const PARSE_CONSTANT = 256;
32 const PARSE_CUSTOM_TAGS = 512;
33 const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024;
34 const PARSE_KEYS_AS_STRINGS = 2048;
37 * Parses YAML into a PHP value.
41 * $array = Yaml::parse(file_get_contents('config.yml'));
45 * @param string $input A string containing YAML
46 * @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
48 * @return mixed The YAML converted to a PHP value
50 * @throws ParseException If the YAML is not valid
52 public static function parse($input, $flags = 0)
54 if (is_bool($flags)) {
55 @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
58 $flags = self::PARSE_EXCEPTION_ON_INVALID_TYPE;
64 if (func_num_args() >= 3) {
65 @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
67 if (func_get_arg(2)) {
68 $flags |= self::PARSE_OBJECT;
72 if (func_num_args() >= 4) {
73 @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED);
75 if (func_get_arg(3)) {
76 $flags |= self::PARSE_OBJECT_FOR_MAP;
82 return $yaml->parse($input, $flags);