root/trunk/patXMLPretty/Module.php

Revision 39, 2.7 kB (checked in by argh, 3 years ago)

Added some docs; Added the setPretty method so that a module always has a reference to the main patXMLPretty object; Added the getName method.

Line 
1 <?php
2 /**
3  * File containing the patXMLPretty_Module class.
4  *
5  * @package        patXMLPretty
6  * @author        Sebastian 'The Argh' Mordziol <argh@php-tools.net>
7  * @see         patXMLPretty_Module
8  */
9
10 /**
11  * Notice: tried to access an unknown option
12  */
13  define( 'PATXMLPRETTY_MODULE_NOTICE_UNKNOWN_OPTION', 'patXMLPretty_Module:01' );
14
15 /**
16  * Base class for patXMLPretty modules (Engine, Renderer, ConfigReader...)
17  * that implements common functionality.
18  *
19  * @package        patXMLPretty
20  * @subpackage     Module
21  * @author        Sebastian Mordziol <argh@php-tools.net>
22  * @version        0.1.0
23  * @license        LGPL
24  * @link        http://www.php-tools.net
25  */
26 class patXMLPretty_Module
27 {
28    /**
29     * Stores a reference to the patXMLPretty object
30     * this module has been created by.
31     *
32     * @access    private
33     * @var        patXMLPretty
34     * @see        setPretty()
35     */
36     var $pretty = null;
37
38    /**
39     * Stores all available options and their values/default values.
40     *
41     * @abstract
42     * @access    private
43     * @var        array
44     * @see        setOptions()
45     * @see         setOption()
46     * @see         getOption()
47     */
48     var $options = array();
49
50    /**
51     * Stores the name of the module
52     *
53     * @abstract
54     * @access    private
55     * @var        string
56     * @see        getName()
57     */
58     var $name = null;
59
60    /**
61     * Sets the patXMLPretty object this module has
62     * been created by.
63     *
64     * @access    public
65     * @param    patXMLPretty
66     * @see        $pretty
67     */
68     function setPretty( &$pretty )
69     {
70         $this->pretty =& $pretty;
71     }
72
73    /**
74     * Sets a collection of options, overwriting any
75     * existing values.
76     *
77     * @access    public
78     * @param    array
79     * @see        setOption()
80     */
81     function setOptions( $options )
82     {
83         foreach( $options as $optionName => $optionValue ) {
84             $this->setOption( $optionName, $optionValue );
85         }
86     }
87
88    /**
89     * Sets a single option, overwriting any existing option value.
90     *
91     * @access    public
92     * @param    string
93     * @param     mixed
94     * @see        setOptions()
95     * @see         $options
96     */
97     function setOption( $name, $value )
98     {
99         $this->options[$name] = $value;
100     }
101
102    /**
103     * Retrieves the current value of the specified option.
104     *
105     * @access    public
106     * @param    string
107     * @return    mixed|patError
108     * @see        setOption()
109     * @see         $options
110     */
111     function getOption( $optionName )
112     {
113         if( !isset( $this->options[$optionName] ) ) {
114             $error = patErrorManager::raiseNotice(
115                 PATXMLPRETTY_MODULE_NOTICE_UNKNOWN_OPTION,
116                 $this->userMessages['notice'],
117                 'The option ['.$optionName.'] does not exist. Please always use the '.
118                 '[optionExists] method prior to getting an option you are not sure '.
119                 'exists to avoid this notice.'
120             );
121             return $error;
122         }
123
124         return $this->options[$optionName];
125     }
126
127    /**
128     * Retrieves the name of the current module.
129     *
130     * @access    public
131     * @return    string
132     * @see        $name
133     */
134     function getName()
135     {
136         return $this->name;
137     }
138 }
139
140 ?>
Note: See TracBrowser for help on using the browser.