~patrix-sbs/oraculum/git

« back to all changes in this revision

Viewing changes to models/doctrine/lib/Doctrine/Parser.php

  • Committer: Patrick Kaminski
  • Date: 2009-09-02 02:33:07 UTC
  • Revision ID: git-v1:943803254fca67bfb4c0374422b1b836b14dc518
Tags: v0.1a
Sending Oraculum Framework v0.1 alpha

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 *  $Id: Parser.php 1080 2007-02-10 18:17:08Z jwage $
 
4
 *
 
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
16
 *
 
17
 * This software consists of voluntary contributions made by many individuals
 
18
 * and is licensed under the LGPL. For more information, see
 
19
 * <http://www.phpdoctrine.org>.
 
20
 */
 
21
 
 
22
/**
 
23
 * Doctrine_Parser
 
24
 *
 
25
 * @package     Doctrine
 
26
 * @subpackage  Parser
 
27
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 
28
 * @link        www.phpdoctrine.org
 
29
 * @since       1.0
 
30
 * @version     $Revision: 1080 $
 
31
 * @author      Jonathan H. Wage <jwage@mac.com>
 
32
 */
 
33
abstract class Doctrine_Parser
 
34
{
 
35
    /**
 
36
     * loadData
 
37
     *
 
38
     * Override in the parser driver
 
39
     *
 
40
     * @param string $array 
 
41
     * @return void
 
42
     * @author Jonathan H. Wage
 
43
     */
 
44
    abstract public function loadData($array);
 
45
 
 
46
    /**
 
47
     * dumpData
 
48
     *
 
49
     * Override in the praser driver
 
50
     *
 
51
     * @param string $array 
 
52
     * @param string $path 
 
53
     * @return void
 
54
     * @author Jonathan H. Wage
 
55
     */
 
56
    abstract public function dumpData($array, $path = null);
 
57
 
 
58
    /**
 
59
     * getParser
 
60
     *
 
61
     * Get instance of the specified parser
 
62
     *
 
63
     * @param string $type 
 
64
     * @return void
 
65
     * @author Jonathan H. Wage
 
66
     */
 
67
    static public function getParser($type)
 
68
    {
 
69
        $class = 'Doctrine_Parser_'.ucfirst($type);
 
70
 
 
71
        return new $class;
 
72
    }
 
73
 
 
74
    /**
 
75
     * load
 
76
     *
 
77
     * Interface for loading and parsing data from a file
 
78
     *
 
79
     * @param string $path 
 
80
     * @param string $type 
 
81
     * @return void
 
82
     * @author Jonathan H. Wage
 
83
     */
 
84
    static public function load($path, $type = 'xml')
 
85
    {
 
86
        $parser = self::getParser($type);
 
87
 
 
88
        return (array) $parser->loadData($path);
 
89
    }
 
90
 
 
91
    /**
 
92
     * dump
 
93
     *
 
94
     * Interface for pulling and dumping data to a file
 
95
     *
 
96
     * @param string $array 
 
97
     * @param string $path 
 
98
     * @param string $type 
 
99
     * @return void
 
100
     * @author Jonathan H. Wage
 
101
     */
 
102
    static public function dump($array, $type = 'xml', $path = null)
 
103
    {
 
104
        $parser = self::getParser($type);
 
105
 
 
106
        return $parser->dumpData($array, $path);
 
107
    }
 
108
 
 
109
    /**
 
110
     * doLoad
 
111
     *
 
112
     * Get contents whether it is the path to a file file or a string of txt.
 
113
     * Either should allow php code in it.
 
114
     *
 
115
     * @param string $path 
 
116
     * @return void
 
117
     */
 
118
    public function doLoad($path)
 
119
    {
 
120
        ob_start();
 
121
        if ( ! file_exists($path)) {
 
122
            $contents = $path;
 
123
            $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'dparser_' . microtime();
 
124
 
 
125
            file_put_contents($path, $contents);
 
126
        }
 
127
 
 
128
        include($path);
 
129
 
 
130
        // Fix #1569. Need to check if it's still all valid
 
131
        $contents = ob_get_clean(); //iconv("UTF-8", "UTF-8", ob_get_clean());
 
132
 
 
133
        return $contents;
 
134
    }
 
135
 
 
136
    /**
 
137
     * doDump
 
138
     *
 
139
     * @param string $data 
 
140
     * @param string $path 
 
141
     * @return void
 
142
     */
 
143
    public function doDump($data, $path = null)
 
144
    {
 
145
      if ($path !== null) {
 
146
            return file_put_contents($path, $data);
 
147
        } else {
 
148
            return $data;
 
149
        }
 
150
    }
 
151
}
 
 
b'\\ No newline at end of file'