123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace Symfony\Component\Yaml;
- use Symfony\Component\Yaml\Exception\ParseException;
- class Yaml
- {
-
- public static function parse($input, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false)
- {
-
- $file = '';
- if (false === strpos($input, "\n") && is_file($input)) {
- @trigger_error('The ability to pass file names to the '.__METHOD__.' method is deprecated since Symfony 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead.', E_USER_DEPRECATED);
- if (false === is_readable($input)) {
- throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input));
- }
- $file = $input;
- $input = file_get_contents($file);
- }
- $yaml = new Parser();
- try {
- return $yaml->parse($input, $exceptionOnInvalidType, $objectSupport, $objectForMap);
- } catch (ParseException $e) {
- if ($file) {
- $e->setParsedFile($file);
- }
- throw $e;
- }
- }
-
- public static function dump($input, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
- {
- if ($indent < 1) {
- throw new \InvalidArgumentException('The indentation must be greater than zero.');
- }
- $yaml = new Dumper();
- $yaml->setIndentation($indent);
- return $yaml->dump($input, $inline, 0, $exceptionOnInvalidType, $objectSupport);
- }
- }
|