Updated PEAR and PEAR packages.
[timetracker.git] / WEB-INF / lib / pear / PEAR / Frontend.php
1 <?php
2 /**
3  * PEAR_Frontend, the singleton-based frontend for user input/output
4  *
5  * PHP versions 4 and 5
6  *
7  * @category   pear
8  * @package    PEAR
9  * @author     Greg Beaver <cellog@php.net>
10  * @copyright  1997-2009 The Authors
11  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
12  * @link       http://pear.php.net/package/PEAR
13  * @since      File available since Release 1.4.0a1
14  */
15
16 /**
17  * Include error handling
18  */
19 //require_once 'PEAR.php';
20
21 /**
22  * Which user interface class is being used.
23  * @var string class name
24  */
25 $GLOBALS['_PEAR_FRONTEND_CLASS'] = 'PEAR_Frontend_CLI';
26
27 /**
28  * Instance of $_PEAR_Command_uiclass.
29  * @var object
30  */
31 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null;
32
33 /**
34  * Singleton-based frontend for PEAR user input/output
35  *
36  * @category   pear
37  * @package    PEAR
38  * @author     Greg Beaver <cellog@php.net>
39  * @copyright  1997-2009 The Authors
40  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
41  * @version    Release: 1.10.1
42  * @link       http://pear.php.net/package/PEAR
43  * @since      Class available since Release 1.4.0a1
44  */
45 class PEAR_Frontend extends PEAR
46 {
47     /**
48      * Retrieve the frontend object
49      * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk
50      */
51     public static function &singleton($type = null)
52     {
53         if ($type === null) {
54             if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) {
55                 $a = false;
56                 return $a;
57             }
58             return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
59         }
60
61         $a = PEAR_Frontend::setFrontendClass($type);
62         return $a;
63     }
64
65     /**
66      * Set the frontend class that will be used by calls to {@link singleton()}
67      *
68      * Frontends are expected to conform to the PEAR naming standard of
69      * _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php)
70      * @param string $uiclass full class name
71      * @return PEAR_Frontend
72      */
73     public static function &setFrontendClass($uiclass)
74     {
75         if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
76               is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
77             return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
78         }
79
80         if (!class_exists($uiclass)) {
81             $file = str_replace('_', '/', $uiclass) . '.php';
82             if (PEAR_Frontend::isIncludeable($file)) {
83                 include_once $file;
84             }
85         }
86
87         if (class_exists($uiclass)) {
88             $obj = new $uiclass;
89             // quick test to see if this class implements a few of the most
90             // important frontend methods
91             if (is_a($obj, 'PEAR_Frontend')) {
92                 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj;
93                 $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
94                 return $obj;
95             }
96
97             $err = PEAR::raiseError("not a frontend class: $uiclass");
98             return $err;
99         }
100
101         $err = PEAR::raiseError("no such class: $uiclass");
102         return $err;
103     }
104
105     /**
106      * Set the frontend class that will be used by calls to {@link singleton()}
107      *
108      * Frontends are expected to be a descendant of PEAR_Frontend
109      * @param PEAR_Frontend
110      * @return PEAR_Frontend
111      */
112     public static function &setFrontendObject($uiobject)
113     {
114         if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
115               is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) {
116             return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
117         }
118
119         if (!is_a($uiobject, 'PEAR_Frontend')) {
120             $err = PEAR::raiseError('not a valid frontend class: (' .
121                 get_class($uiobject) . ')');
122             return $err;
123         }
124
125         $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject;
126         $GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject);
127         return $uiobject;
128     }
129
130     /**
131      * @param string $path relative or absolute include path
132      * @return boolean
133      */
134     public static function isIncludeable($path)
135     {
136         if (file_exists($path) && is_readable($path)) {
137             return true;
138         }
139
140         $fp = @fopen($path, 'r', true);
141         if ($fp) {
142             fclose($fp);
143             return true;
144         }
145
146         return false;
147     }
148
149     /**
150      * @param PEAR_Config
151      */
152     function setConfig(&$config)
153     {
154     }
155
156     /**
157      * This can be overridden to allow session-based temporary file management
158      *
159      * By default, all files are deleted at the end of a session.  The web installer
160      * needs to be able to sustain a list over many sessions in order to support
161      * user interaction with install scripts
162      */
163     function addTempFile($file)
164     {
165         $GLOBALS['_PEAR_Common_tempfiles'][] = $file;
166     }
167
168     /**
169      * Log an action
170      *
171      * @param string $msg the message to log
172      * @param boolean $append_crlf
173      * @return boolean true
174      * @abstract
175      */
176     function log($msg, $append_crlf = true)
177     {
178     }
179
180     /**
181      * Run a post-installation script
182      *
183      * @param array $scripts array of post-install scripts
184      * @abstract
185      */
186     function runPostinstallScripts(&$scripts)
187     {
188     }
189
190     /**
191      * Display human-friendly output formatted depending on the
192      * $command parameter.
193      *
194      * This should be able to handle basic output data with no command
195      * @param mixed  $data    data structure containing the information to display
196      * @param string $command command from which this method was called
197      * @abstract
198      */
199     function outputData($data, $command = '_default')
200     {
201     }
202
203     /**
204      * Display a modal form dialog and return the given input
205      *
206      * A frontend that requires multiple requests to retrieve and process
207      * data must take these needs into account, and implement the request
208      * handling code.
209      * @param string $command  command from which this method was called
210      * @param array  $prompts  associative array. keys are the input field names
211      *                         and values are the description
212      * @param array  $types    array of input field types (text, password,
213      *                         etc.) keys have to be the same like in $prompts
214      * @param array  $defaults array of default values. again keys have
215      *                         to be the same like in $prompts.  Do not depend
216      *                         on a default value being set.
217      * @return array input sent by the user
218      * @abstract
219      */
220     function userDialog($command, $prompts, $types = array(), $defaults = array())
221     {
222     }
223 }