| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\YamlException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Convert all or part of a YAML document stream read from a file to a PHP variable. |
| 9 |
* |
| 10 |
* @param string $filename Path to the file. |
| 11 |
* @param int $pos Document to extract from stream (-1 for all |
| 12 |
* documents, 0 for first document, ...). |
| 13 |
* @param int|null $ndocs If ndocs is provided, then it is filled with the |
| 14 |
* number of documents found in stream. |
| 15 |
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML |
| 16 |
* tag => callable mappings. See |
| 17 |
* parse callbacks for more |
| 18 |
* details. |
| 19 |
* |
| 20 |
* @return mixed Returns the value encoded in input in appropriate |
| 21 |
* PHP type. If pos is -1 an |
| 22 |
* array will be returned with one entry for each document found |
| 23 |
* in the stream. |
| 24 |
* @throws YamlException |
| 25 |
* |
| 26 |
*/ |
| 27 |
function yaml_parse_file(string $filename, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null) |
| 28 |
{ |
| 29 |
error_clear_last(); |
| 30 |
$result = \yaml_parse_file($filename, $pos, $ndocs, $callbacks); |
| 31 |
if ($result === false) { |
| 32 |
throw YamlException::createFromPhpError(); |
| 33 |
} |
| 34 |
return $result; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* Convert all or part of a YAML document stream read from a URL to a PHP variable. |
| 40 |
* |
| 41 |
* @param string $url url should be of the form "scheme://...". PHP |
| 42 |
* will search for a protocol handler (also known as a wrapper) for that |
| 43 |
* scheme. If no wrappers for that protocol are registered, PHP will emit |
| 44 |
* a notice to help you track potential problems in your script and then |
| 45 |
* continue as though filename specifies a regular file. |
| 46 |
* @param int $pos Document to extract from stream (-1 for all |
| 47 |
* documents, 0 for first document, ...). |
| 48 |
* @param int|null $ndocs If ndocs is provided, then it is filled with the |
| 49 |
* number of documents found in stream. |
| 50 |
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML |
| 51 |
* tag => callable mappings. See |
| 52 |
* parse callbacks for more |
| 53 |
* |
| 54 |
* @return mixed Returns the value encoded in input in appropriate |
| 55 |
* PHP type. If pos is |
| 56 |
* -1 an array will be returned with one entry |
| 57 |
* for each document found in the stream. |
| 58 |
* @throws YamlException |
| 59 |
* |
| 60 |
*/ |
| 61 |
function yaml_parse_url(string $url, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null) |
| 62 |
{ |
| 63 |
error_clear_last(); |
| 64 |
$result = \yaml_parse_url($url, $pos, $ndocs, $callbacks); |
| 65 |
if ($result === false) { |
| 66 |
throw YamlException::createFromPhpError(); |
| 67 |
} |
| 68 |
return $result; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
/** |
| 73 |
* Convert all or part of a YAML document stream to a PHP variable. |
| 74 |
* |
| 75 |
* @param string $input The string to parse as a YAML document stream. |
| 76 |
* @param int $pos Document to extract from stream (-1 for all |
| 77 |
* documents, 0 for first document, ...). |
| 78 |
* @param int|null $ndocs If ndocs is provided, then it is filled with the |
| 79 |
* number of documents found in stream. |
| 80 |
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML |
| 81 |
* tag => callable mappings. See |
| 82 |
* parse callbacks for more |
| 83 |
* details. |
| 84 |
* |
| 85 |
* @return mixed Returns the value encoded in input in appropriate |
| 86 |
* PHP type. If pos is -1 an |
| 87 |
* array will be returned with one entry for each document found |
| 88 |
* in the stream. |
| 89 |
* @throws YamlException |
| 90 |
* |
| 91 |
*/ |
| 92 |
function yaml_parse(string $input, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null) |
| 93 |
{ |
| 94 |
error_clear_last(); |
| 95 |
$result = \yaml_parse($input, $pos, $ndocs, $callbacks); |
| 96 |
if ($result === false) { |
| 97 |
throw YamlException::createFromPhpError(); |
| 98 |
} |
| 99 |
return $result; |
| 100 |
} |
| 101 |
|