PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/php/PEAR/Frontend.php

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