[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 /** 3 * PEAR_Frontend, the singleton-based frontend for user input/output 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: This source file is subject to version 3.0 of the PHP license 8 * that is available through the world-wide-web at the following URI: 9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of 10 * the PHP License and are unable to obtain it through the web, please 11 * send a note to license@php.net so we can mail you a copy immediately. 12 * 13 * @category pear 14 * @package PEAR 15 * @author Greg Beaver <cellog@php.net> 16 * @copyright 1997-2006 The PHP Group 17 * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 * @version CVS: $Id: Frontend.php,v 1.9 2006/03/03 13:13:07 pajoye Exp $ 19 * @link http://pear.php.net/package/PEAR 20 * @since File available since Release 1.4.0a1 21 */ 22 23 /** 24 * Which user interface class is being used. 25 * @var string class name 26 */ 27 $GLOBALS['_PEAR_FRONTEND_CLASS'] = 'PEAR_Frontend_CLI'; 28 29 /** 30 * Instance of $_PEAR_Command_uiclass. 31 * @var object 32 */ 33 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null; 34 35 /** 36 * Singleton-based frontend for PEAR user input/output 37 * 38 * Note that frontend classes must implement userConfirm(), and shoul implement 39 * displayFatalError() and outputData() 40 * @category pear 41 * @package PEAR 42 * @author Greg Beaver <cellog@php.net> 43 * @copyright 1997-2006 The PHP Group 44 * @license http://www.php.net/license/3_0.txt PHP License 3.0 45 * @version Release: 1.4.11 46 * @link http://pear.php.net/package/PEAR 47 * @since Class available since Release 1.4.0a1 48 */ 49 class PEAR_Frontend extends PEAR 50 { 51 /** 52 * Retrieve the frontend object 53 * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk 54 * @static 55 */ 56 function &singleton($type = null) 57 { 58 if ($type === null) { 59 if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) { 60 $a = false; 61 return $a; 62 } 63 return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; 64 } else { 65 $a = PEAR_Frontend::setFrontendClass($type); 66 return $a; 67 } 68 } 69 70 /** 71 * Set the frontend class that will be used by calls to {@link singleton()} 72 * 73 * Frontends are expected to conform to the PEAR naming standard of 74 * _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php) 75 * @param string $uiclass full class name 76 * @return PEAR_Frontend 77 * @static 78 */ 79 function &setFrontendClass($uiclass) 80 { 81 if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) && 82 is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) { 83 return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; 84 } 85 if (!class_exists($uiclass)) { 86 $file = str_replace('_', '/', $uiclass) . '.php'; 87 if (PEAR_Frontend::isIncludeable($file)) { 88 include_once $file; 89 } 90 } 91 if (class_exists($uiclass)) { 92 $obj = &new $uiclass; 93 // quick test to see if this class implements a few of the most 94 // important frontend methods 95 if (method_exists($obj, 'userConfirm')) { 96 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj; 97 $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass; 98 return $obj; 99 } else { 100 $err = PEAR::raiseError("not a frontend class: $uiclass"); 101 return $err; 102 } 103 } 104 $err = PEAR::raiseError("no such class: $uiclass"); 105 return $err; 106 } 107 108 /** 109 * Set the frontend class that will be used by calls to {@link singleton()} 110 * 111 * Frontends are expected to be a descendant of PEAR_Frontend 112 * @param PEAR_Frontend 113 * @return PEAR_Frontend 114 * @static 115 */ 116 function &setFrontendObject($uiobject) 117 { 118 if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) && 119 is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) { 120 return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; 121 } 122 if (!is_a($uiobject, 'PEAR_Frontend')) { 123 $err = PEAR::raiseError('not a valid frontend class: (' . 124 get_class($uiobject) . ')'); 125 return $err; 126 } 127 // quick test to see if this class implements a few of the most 128 // important frontend methods 129 if (method_exists($uiobject, 'userConfirm')) { 130 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject; 131 $GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject); 132 return $uiobject; 133 } else { 134 $err = PEAR::raiseError("not a value frontend class: (" . get_class($uiobject) 135 . ')'); 136 return $err; 137 } 138 } 139 140 /** 141 * @param string $path relative or absolute include path 142 * @return boolean 143 * @static 144 */ 145 function isIncludeable($path) 146 { 147 if (file_exists($path) && is_readable($path)) { 148 return true; 149 } 150 $ipath = explode(PATH_SEPARATOR, ini_get('include_path')); 151 foreach ($ipath as $include) { 152 $test = realpath($include . DIRECTORY_SEPARATOR . $path); 153 if (!$test) { // support wrappers like phar (realpath just don't work with them) 154 $test = $include . DIRECTORY_SEPARATOR . $path; 155 } 156 if (file_exists($test) && is_readable($test)) { 157 return true; 158 } 159 } 160 return false; 161 } 162 163 /** 164 * @param PEAR_Config 165 */ 166 function setConfig(&$config) 167 { 168 } 169 170 /** 171 * This can be overridden to allow session-based temporary file management 172 * 173 * By default, all files are deleted at the end of a session. The web installer 174 * needs to be able to sustain a list over many sessions in order to support 175 * user interaction with install scripts 176 */ 177 function addTempFile($file) 178 { 179 $GLOBALS['_PEAR_Common_tempfiles'][] = $file; 180 } 181 182 function log($msg, $append_crlf = true) 183 { 184 } 185 } 186 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |