1 |
<?php
|
2 |
require_once('spyc.php');
|
3 |
|
4 |
/*
|
5 |
* $Id: Yml.php 1080 2007-02-10 18:17:08Z jwage $
|
6 |
*
|
7 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
8 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
9 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
10 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
11 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
12 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
13 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
14 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
15 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
16 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
17 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
18 |
*
|
19 |
* This software consists of voluntary contributions made by many individuals
|
20 |
* and is licensed under the LGPL. For more information, see
|
21 |
* <http://www.phpdoctrine.com>.
|
22 |
*/
|
23 |
/**
|
24 |
* Doctrine_Parser_Yml
|
25 |
*
|
26 |
* @package Doctrine
|
27 |
* @subpackage Parser
|
28 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
29 |
* @link www.phpdoctrine.com
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 1080 $
|
32 |
* @author Jonathan H. Wage <jwage@mac.com>
|
33 |
*/
|
34 |
class Doctrine_Parser_Yml extends Doctrine_Parser
|
35 |
{
|
36 |
/**
|
37 |
* dumpData
|
38 |
*
|
39 |
* Dump an array of data to a specified path or return
|
40 |
*
|
41 |
* @param string $array
|
42 |
* @param string $path
|
43 |
* @return void
|
44 |
* @author Jonathan H. Wage
|
45 |
*/
|
46 |
public function dumpData($array, $path = null)
|
47 |
{
|
48 |
$spyc = new DoctrineSpyc();
|
49 |
|
50 |
$yml = $spyc->dump($array, false, false);
|
51 |
|
52 |
if ($path) {
|
53 |
return file_put_contents($path, $yml);
|
54 |
} else {
|
55 |
return $yml;
|
56 |
}
|
57 |
}
|
58 |
/**
|
59 |
* loadData
|
60 |
*
|
61 |
* Load and parse data from a yml file
|
62 |
*
|
63 |
* @param string $path
|
64 |
* @return void
|
65 |
* @author Jonathan H. Wage
|
66 |
*/
|
67 |
public function loadData($path)
|
68 |
{
|
69 |
$contents = $this->getContents($path);
|
70 |
|
71 |
$spyc = new DoctrineSpyc();
|
72 |
|
73 |
$array = $spyc->load($contents);
|
74 |
|
75 |
return $array;
|
76 |
}
|
77 |
}
|