Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / yaml / Yaml.php
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 class Yaml
22 {
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
33     /**
34      * Parses YAML into a PHP value.
35      *
36      *  Usage:
37      *  <code>
38      *   $array = Yaml::parse(file_get_contents('config.yml'));
39      *   print_r($array);
40      *  </code>
41      *
42      * @param string $input A string containing YAML
43      * @param int    $flags A bit field of PARSE_* constants to customize the YAML parser behavior
44      *
45      * @return mixed The YAML converted to a PHP value
46      *
47      * @throws ParseException If the YAML is not valid
48      */
49     public static function parse($input, $flags = 0)
50     {
51         if (is_bool($flags)) {
52             @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);
53
54             if ($flags) {
55                 $flags = self::PARSE_EXCEPTION_ON_INVALID_TYPE;
56             } else {
57                 $flags = 0;
58             }
59         }
60
61         if (func_num_args() >= 3) {
62             @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);
63
64             if (func_get_arg(2)) {
65                 $flags |= self::PARSE_OBJECT;
66             }
67         }
68
69         if (func_num_args() >= 4) {
70             @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);
71
72             if (func_get_arg(3)) {
73                 $flags |= self::PARSE_OBJECT_FOR_MAP;
74             }
75         }
76
77         $yaml = new Parser();
78
79         return $yaml->parse($input, $flags);
80     }
81
82     /**
83      * Dumps a PHP value to a YAML string.
84      *
85      * The dump method, when supplied with an array, will do its best
86      * to convert the array into friendly YAML.
87      *
88      * @param mixed $input  The PHP value
89      * @param int   $inline The level where you switch to inline YAML
90      * @param int   $indent The amount of spaces to use for indentation of nested nodes
91      * @param int   $flags  A bit field of DUMP_* constants to customize the dumped YAML string
92      *
93      * @return string A YAML string representing the original PHP value
94      */
95     public static function dump($input, $inline = 2, $indent = 4, $flags = 0)
96     {
97         if (is_bool($flags)) {
98             @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 DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
99
100             if ($flags) {
101                 $flags = self::DUMP_EXCEPTION_ON_INVALID_TYPE;
102             } else {
103                 $flags = 0;
104             }
105         }
106
107         if (func_num_args() >= 5) {
108             @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 DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
109
110             if (func_get_arg(4)) {
111                 $flags |= self::DUMP_OBJECT;
112             }
113         }
114
115         $yaml = new Dumper($indent);
116
117         return $yaml->dump($input, $inline, 0, $flags);
118     }
119 }