Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/yaml/Yaml.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Yaml; | |
13 | |
14 use Symfony\Component\Yaml\Exception\ParseException; | |
15 | |
16 /** | |
17 * Yaml offers convenience methods to load and dump YAML. | |
18 * | |
19 * @author Fabien Potencier <fabien@symfony.com> | |
20 * | |
21 * @final since version 3.4 | |
22 */ | |
23 class Yaml | |
24 { | |
25 const DUMP_OBJECT = 1; | |
26 const PARSE_EXCEPTION_ON_INVALID_TYPE = 2; | |
27 const PARSE_OBJECT = 4; | |
28 const PARSE_OBJECT_FOR_MAP = 8; | |
29 const DUMP_EXCEPTION_ON_INVALID_TYPE = 16; | |
30 const PARSE_DATETIME = 32; | |
31 const DUMP_OBJECT_AS_MAP = 64; | |
32 const DUMP_MULTI_LINE_LITERAL_BLOCK = 128; | |
33 const PARSE_CONSTANT = 256; | |
34 const PARSE_CUSTOM_TAGS = 512; | |
35 const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024; | |
36 | |
37 /** | |
38 * @deprecated since version 3.4, to be removed in 4.0. Quote your evaluable keys instead. | |
39 */ | |
40 const PARSE_KEYS_AS_STRINGS = 2048; | |
41 | |
42 /** | |
43 * Parses a YAML file into a PHP value. | |
44 * | |
45 * Usage: | |
46 * <code> | |
47 * $array = Yaml::parseFile('config.yml'); | |
48 * print_r($array); | |
49 * </code> | |
50 * | |
51 * @param string $filename The path to the YAML file to be parsed | |
52 * @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior | |
53 * | |
54 * @return mixed The YAML converted to a PHP value | |
55 * | |
56 * @throws ParseException If the file could not be read or the YAML is not valid | |
57 */ | |
58 public static function parseFile($filename, $flags = 0) | |
59 { | |
60 $yaml = new Parser(); | |
61 | |
62 return $yaml->parseFile($filename, $flags); | |
63 } | |
64 | |
65 /** | |
66 * Parses YAML into a PHP value. | |
67 * | |
68 * Usage: | |
69 * <code> | |
70 * $array = Yaml::parse(file_get_contents('config.yml')); | |
71 * print_r($array); | |
72 * </code> | |
73 * | |
74 * @param string $input A string containing YAML | |
75 * @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior | |
76 * | |
77 * @return mixed The YAML converted to a PHP value | |
78 * | |
79 * @throws ParseException If the YAML is not valid | |
80 */ | |
81 public static function parse($input, $flags = 0) | |
82 { | |
83 if (is_bool($flags)) { | |
84 @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); | |
85 | |
86 if ($flags) { | |
87 $flags = self::PARSE_EXCEPTION_ON_INVALID_TYPE; | |
88 } else { | |
89 $flags = 0; | |
90 } | |
91 } | |
92 | |
93 if (func_num_args() >= 3) { | |
94 @trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the PARSE_OBJECT flag instead.', E_USER_DEPRECATED); | |
95 | |
96 if (func_get_arg(2)) { | |
97 $flags |= self::PARSE_OBJECT; | |
98 } | |
99 } | |
100 | |
101 if (func_num_args() >= 4) { | |
102 @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED); | |
103 | |
104 if (func_get_arg(3)) { | |
105 $flags |= self::PARSE_OBJECT_FOR_MAP; | |
106 } | |
107 } | |
108 | |
109 $yaml = new Parser(); | |
110 | |
111 return $yaml->parse($input, $flags); | |
112 } | |
113 | |
114 /** | |
115 * Dumps a PHP value to a YAML string. | |
116 * | |
117 * The dump method, when supplied with an array, will do its best | |
118 * to convert the array into friendly YAML. | |
119 * | |
120 * @param mixed $input The PHP value | |
121 * @param int $inline The level where you switch to inline YAML | |
122 * @param int $indent The amount of spaces to use for indentation of nested nodes | |
123 * @param int $flags A bit field of DUMP_* constants to customize the dumped YAML string | |
124 * | |
125 * @return string A YAML string representing the original PHP value | |
126 */ | |
127 public static function dump($input, $inline = 2, $indent = 4, $flags = 0) | |
128 { | |
129 if (is_bool($flags)) { | |
130 @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); | |
131 | |
132 if ($flags) { | |
133 $flags = self::DUMP_EXCEPTION_ON_INVALID_TYPE; | |
134 } else { | |
135 $flags = 0; | |
136 } | |
137 } | |
138 | |
139 if (func_num_args() >= 5) { | |
140 @trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED); | |
141 | |
142 if (func_get_arg(4)) { | |
143 $flags |= self::DUMP_OBJECT; | |
144 } | |
145 } | |
146 | |
147 $yaml = new Dumper($indent); | |
148 | |
149 return $yaml->dump($input, $inline, 0, $flags); | |
150 } | |
151 } |