MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Yaml.php
Ir para a documentação deste ficheiro.
1<?php
2
4
5/*
6 * This file is part of the symfony package.
7 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
20class Yaml
21{
22 static protected $spec = '1.2';
23
29 static public function setSpecVersion($version)
30 {
31 if (!in_array($version, array('1.1', '1.2')))
32 {
33 throw new \InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
34 }
35
36 self::$spec = $version;
37 }
38
44 static public function getSpecVersion()
45 {
46 return self::$spec;
47 }
48
67 public static function load($input)
68 {
69 $file = '';
70
71 // if input is a file, process it
72 if (strpos($input, "\n") === false && is_file($input))
73 {
74 $file = $input;
75
76 ob_start();
77 $retval = include($input);
78 $content = ob_get_clean();
79
80 // if an array is returned by the config file assume it's in plain php form else in YAML
81 $input = is_array($retval) ? $retval : $content;
82 }
83
84 // if an array is returned by the config file assume it's in plain php form else in YAML
85 if (is_array($input))
86 {
87 return $input;
88 }
89
90 $yaml = new Parser();
91
92 try
93 {
94 $ret = $yaml->parse($input);
95 }
96 catch (\Exception $e)
97 {
98 throw new \InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
99 }
100
101 return $ret;
102 }
103
115 public static function dump($array, $inline = 2)
116 {
117 $yaml = new Dumper();
118
119 return $yaml->dump($array, $inline);
120 }
121}
static dump($array, $inline=2)
Definição Yaml.php:115
static setSpecVersion($version)
Definição Yaml.php:29
static load($input)
Definição Yaml.php:67