PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/php-pear-CodeGen-PECL-1.1.3/CodeGen_PECL-1.1.3/PECL/Element/Ini.php

#
PHP | 453 lines | 173 code | 69 blank | 211 comment | 8 complexity | 3a583c57b1ea47ccbacd4b7e9270de90 MD5 | raw file
  1. <?php
  2. /**
  3. * Class describing a PHP ini directive within a PECL extension
  4. *
  5. * PHP versions 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 Tools and Utilities
  14. * @package CodeGen
  15. * @author Hartmut Holzgraefe <hartmut@php.net>
  16. * @copyright 2005-2008 Hartmut Holzgraefe
  17. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  18. * @version CVS: $Id: Ini.php,v 1.7 2006/10/12 13:11:25 hholzgra Exp $
  19. * @link http://pear.php.net/package/CodeGen
  20. */
  21. /**
  22. * includes
  23. */
  24. require_once "CodeGen/PECL/Element.php";
  25. /**
  26. * Class describing a PHP ini directive within a PECL extension
  27. *
  28. * @category Tools and Utilities
  29. * @package CodeGen
  30. * @author Hartmut Holzgraefe <hartmut@php.net>
  31. * @copyright 2005-2008 Hartmut Holzgraefe
  32. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  33. * @version Release: @package_version@
  34. * @link http://pear.php.net/package/CodeGen
  35. */
  36. class CodeGen_PECL_Element_Ini
  37. extends CodeGen_PECL_Element
  38. {
  39. // TODO this should be a subclass of CodeGen_PECL_Element_Global ?
  40. /**
  41. * Directive name
  42. *
  43. * @access private
  44. * @var string
  45. */
  46. protected $name;
  47. /**
  48. * Set method for name
  49. *
  50. * @access public
  51. * @var string directive name
  52. */
  53. function setName($name)
  54. {
  55. if (!self::isName($name)) {
  56. return PEAR::raiseError("'$name' is not a valid php.ini directive name");
  57. }
  58. $this->name = $name;
  59. return true;
  60. }
  61. /**
  62. * Get method for name
  63. *
  64. * @access public
  65. * @return string
  66. */
  67. function getName()
  68. {
  69. return $this->name;
  70. }
  71. /**
  72. * Directive data type
  73. *
  74. * @access private
  75. * @var string
  76. */
  77. protected $type;
  78. /**
  79. * Set method for data type
  80. *
  81. * @access public
  82. * @param string one of bool, int, float, string
  83. */
  84. function setType($type)
  85. {
  86. switch ($type) {
  87. case "bool":
  88. $this->cType = "zend_bool";
  89. if (!$this->onupdate) {
  90. $this->onupdate = "OnUpdateBool";
  91. }
  92. return true;
  93. case "int":
  94. $this->cType = "long";
  95. if (!$this->onupdate) {
  96. $this->onupdate = "OnUpdateLong";
  97. }
  98. return true;
  99. case "float":
  100. $this->cType = "double";
  101. if (!$this->onupdate) {
  102. $this->onupdate = "OnUpdateReal";
  103. }
  104. return true;
  105. case "string":
  106. $this->cType = "char *";
  107. if (!$this->onupdate) {
  108. $this->onupdate = "OnUpdateString";
  109. }
  110. return true;
  111. default:
  112. return PEAR::raiseError("'$this->type' not supported, only bool, int, float and string");
  113. }
  114. }
  115. /**
  116. * Get method for type
  117. *
  118. * @access public
  119. * @return string
  120. */
  121. function getType()
  122. {
  123. return $this->cType;
  124. }
  125. /**
  126. * Directive default value
  127. *
  128. * @access private
  129. * @var string
  130. */
  131. protected $value;
  132. /**
  133. * Set method for default value
  134. *
  135. * @access public
  136. * @param string default value
  137. */
  138. function setValue($value)
  139. {
  140. // TODO checks
  141. $this->value = $value;
  142. return true;
  143. }
  144. /**
  145. * Get method for default value
  146. *
  147. * @access public
  148. * @return string
  149. */
  150. function getValue()
  151. {
  152. return $this->value;
  153. }
  154. /**
  155. * Directive description
  156. *
  157. * @access private
  158. * @var string
  159. */
  160. protected $desc;
  161. /**
  162. * Set method for directive description
  163. *
  164. * @access public
  165. * @param string description
  166. */
  167. function setDesc($desc)
  168. {
  169. $this->desc = $desc;
  170. return true;
  171. }
  172. /**
  173. * Get method for description
  174. *
  175. * @access public
  176. * @return string
  177. */
  178. function getDesc()
  179. {
  180. return $this->desc;
  181. }
  182. /**
  183. * Directive access mode
  184. *
  185. * @access private
  186. * @var string
  187. */
  188. protected $access = "PHP_INI_ALL";
  189. /**
  190. * Set method for access mode
  191. *
  192. * @access private
  193. * @param string access mode specification (system|perdir|user|all)
  194. */
  195. function setAccess($access)
  196. {
  197. switch ($access) {
  198. case "system":
  199. $this->access = "PHP_INI_SYSTEM";
  200. return true;
  201. case "perdir":
  202. $this->access = "PHP_INI_PERDIR";
  203. return true;
  204. case "user":
  205. // TODO shouldn't this be ALL instead?
  206. $this->access = "PHP_INI_USER";
  207. return true;
  208. case "all":
  209. case "":
  210. $this->access = "PHP_INI_ALL";
  211. return true;
  212. default:
  213. return PEAR::raiseError("'$access' is not a valid access mode (system|perdir|user|all)");
  214. }
  215. }
  216. /**
  217. * Get method for access
  218. *
  219. * @access public
  220. * @return string
  221. */
  222. function getAccess()
  223. {
  224. return $this->access;
  225. }
  226. /**
  227. * Directive OnUpdate handler
  228. *
  229. * @access private
  230. * @var string
  231. */
  232. protected $onupdate;
  233. /**
  234. * Set method for OnUpdate handler
  235. *
  236. * @access public
  237. * @param string C function name
  238. */
  239. function setOnUpdate($name)
  240. {
  241. if (!self::isName($name)) {
  242. return PEAR::raiseError("'$name' is not a valid update function name");
  243. }
  244. $this->onupdate = $name;
  245. return true;
  246. }
  247. /**
  248. * Get method for update handler
  249. *
  250. * @access public
  251. * @return string
  252. */
  253. function getOnupdate()
  254. {
  255. return $this->onupdate;
  256. }
  257. /**
  258. * Internal C type that stores the directives value
  259. *
  260. * @access private
  261. * @var string
  262. */
  263. protected $cType;
  264. /**
  265. * Constructor
  266. */
  267. function __construct()
  268. {
  269. $this->setType("string");
  270. }
  271. /**
  272. * Generate header for ini directive registration code
  273. *
  274. * @access private
  275. * @param string extension basename
  276. * @return string C code snippet
  277. */
  278. static function cCodeHeader($name)
  279. {
  280. // this is a small incompatibility between ZE1 and ZE2 APIs
  281. // "OnUpdateInt" was changed to "OnUpdateLong" as it actualy
  282. // works on C type "long", not "int"
  283. // the actual implementation didn't change so it is safe to
  284. // just revert the name change using a cpp #define
  285. // TODO: skip this for extensions that depend on PHP 5 anyway
  286. $code = "
  287. #ifndef ZEND_ENGINE_2
  288. #define OnUpdateLong OnUpdateInt
  289. #endif
  290. ";
  291. $code .="PHP_INI_BEGIN()\n";
  292. return $code;
  293. }
  294. /**
  295. * Generate registration code for this directive
  296. *
  297. * @access private
  298. * @param string extension basename
  299. * @return string C code snippet
  300. */
  301. function cCode($name)
  302. {
  303. $code = $this->ifConditionStart();
  304. $code.= " STD_PHP_INI_ENTRY(\"$name.{$this->name}\", \"{$this->value}\", {$this->access}, {$this->onupdate}, {$this->name}, zend_{$name}_globals, {$name}_globals)\n";
  305. $code.= $this->ifConditionEnd();
  306. return $code;
  307. }
  308. /**
  309. * Generate footer for ini directive registration code
  310. *
  311. * @access private
  312. * @param string extension basename
  313. * @return string C code snippet
  314. */
  315. static function cCodeFooter($name)
  316. {
  317. return "PHP_INI_END()\n\n";
  318. }
  319. /**
  320. * Generate header for ini directive documentation
  321. *
  322. * @access private
  323. * @param string extension basename
  324. * @return string DocBook XML snippet
  325. */
  326. static function docHeader($name)
  327. {
  328. return
  329. " <table>
  330. <title>$name &ConfigureOptions;</title>
  331. <tgroup cols='4'>
  332. <thead>
  333. <row>
  334. <entry>&Name;</entry>
  335. <entry>&Default;</entry>
  336. <entry>&Changeable;</entry>
  337. <entry>Changelog</entry>
  338. </row>
  339. </thead>
  340. <tbody>
  341. ";
  342. }
  343. /**
  344. * Generate documentation for ini directive documentation
  345. *
  346. * @access private
  347. * @param string id basename for extension
  348. * @return string DocBook XML snippet
  349. */
  350. function docEntry($base)
  351. {
  352. return
  353. " <row>
  354. <entry>$this->name</entry>
  355. <entry>$this->value</entry>
  356. <entry>$this->access</entry>
  357. <entry></entry>
  358. </row>
  359. ";
  360. }
  361. /**
  362. * Generate footer for ini directive documentation
  363. *
  364. * @access private
  365. * @param string extension basename
  366. * @return string DocBook XML snippet
  367. */
  368. static function docFooter()
  369. {
  370. return
  371. " </tbody>
  372. </tgroup>
  373. </table>
  374. ";
  375. }
  376. }
  377. /*
  378. * Local variables:
  379. * tab-width: 4
  380. * c-basic-offset: 4
  381. * indent-tabs-mode:nil
  382. * End:
  383. */
  384. ?>