3
* $Id: Parser.php 1080 2007-02-10 18:17:08Z jwage $
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.
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>.
27
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28
* @link www.phpdoctrine.org
30
* @version $Revision: 1080 $
31
* @author Jonathan H. Wage <jwage@mac.com>
33
abstract class Doctrine_Parser
38
* Override in the parser driver
40
* @param string $array
42
* @author Jonathan H. Wage
44
abstract public function loadData($array);
49
* Override in the praser driver
51
* @param string $array
54
* @author Jonathan H. Wage
56
abstract public function dumpData($array, $path = null);
61
* Get instance of the specified parser
65
* @author Jonathan H. Wage
67
static public function getParser($type)
69
$class = 'Doctrine_Parser_'.ucfirst($type);
77
* Interface for loading and parsing data from a file
82
* @author Jonathan H. Wage
84
static public function load($path, $type = 'xml')
86
$parser = self::getParser($type);
88
return (array) $parser->loadData($path);
94
* Interface for pulling and dumping data to a file
96
* @param string $array
100
* @author Jonathan H. Wage
102
static public function dump($array, $type = 'xml', $path = null)
104
$parser = self::getParser($type);
106
return $parser->dumpData($array, $path);
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.
115
* @param string $path
118
public function doLoad($path)
121
if ( ! file_exists($path)) {
123
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'dparser_' . microtime();
125
file_put_contents($path, $contents);
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());
139
* @param string $data
140
* @param string $path
143
public function doDump($data, $path = null)
145
if ($path !== null) {
146
return file_put_contents($path, $data);
b'\\ No newline at end of file'