root/trunk/patXMLPretty/Engine/Automatic.php

Revision 45, 2.1 kB (checked in by argh, 3 years ago)

Fixed check for PHP5-only support.

Line 
1 <?php
2 /**
3  * File containing the patXMLPretty_Engine_Automatic class.
4  *
5  * @package        patXMLPretty
6  * @subpackage     Engine
7  * @author        Sebastian 'The Argh' Mordziol <argh@php-tools.net>
8  * @see         patXMLPretty_Engine_Automatic
9  */
10
11 /**
12  * Special parsing engine which automatically determines the
13  * best parsing engine to use on the current system and delegates
14  * parsing to that engine.
15  *
16  * @package        patXMLPretty
17  * @subpackage     Engine
18  * @author        Sebastian 'The Argh' Mordziol <argh@php-tools.net>
19  * @version        0.1.0
20  * @license        LGPL
21  * @link        http://www.php-tools.net
22  * @see         patXMLPretty_Engine
23  */
24 class patXMLPretty_Engine_Automatic extends patXMLPretty_Engine
25 {
26    /**
27     * Stores the name of the engine
28     *
29     * @access    private
30     * @var        string
31     */
32     var $name = 'Automatic';
33
34    /**
35     * Stores a reference to the selected parsing engine
36     * once it has been loaded.
37     *
38     * @access    private
39     * @var         patXMLPretty_Engine
40     * @see        getEngine()
41     */
42     var $engine = null;
43
44    /**
45     * Determines the engine to use, loads it and retrieves the
46     * elements collection from it.
47     *
48     * Note: any options you set for this engine are passed on
49     * to the target engine, so you can use this feature to set
50     * any options you want the target engine to use.
51     *
52     * @access    public
53     * @param    string
54     * @return    array|patError
55     */
56     function parse( $xmlSource )
57     {
58         $engine =& $this->getEngine();
59         if( patErrorManager::isError( $engine ) ) {
60             return $engine;
61         }
62
63         $result = $engine->parse( $xmlSource );
64         return $result;
65     }
66
67    /**
68     * Retrieves the engine object the automatic renderer
69     * has selected depending on the available resources and
70     * the current system.
71     *
72     * @access    public
73     * @return    patXMLPretty_Engine|patError
74     * @see
75     */
76     function &getEngine()
77     {
78         if( is_object( $this->engine ) ) {
79             return $this->engine;
80         }
81
82         $engineType = 'Unserializer';
83         if( substr( phpversion(), 0, 1 ) >= 5 ) {
84             $engineType = 'DOM';
85         }
86
87         $engine =& $this->pretty->createEngine( $engineType, $this->options );
88         if( patErrorManager::isError( $engine ) ) {
89             return $engine;
90         }
91
92         $this->engine =& $engine;
93         return $engine;
94     }
95 }
96
97 ?>
Note: See TracBrowser for help on using the browser.