rw.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * <tasks:postinstallscript> - read/write version
  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.0a10
  14. */
  15. /**
  16. * Base class
  17. */
  18. require_once 'PEAR/Task/Postinstallscript.php';
  19. /**
  20. * Abstracts the postinstallscript file task xml.
  21. * @category pear
  22. * @package PEAR
  23. * @author Greg Beaver <cellog@php.net>
  24. * @copyright 1997-2009 The Authors
  25. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  26. * @version Release: 1.10.10
  27. * @link http://pear.php.net/package/PEAR
  28. * @since Class available since Release 1.4.0a10
  29. */
  30. class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript
  31. {
  32. /**
  33. * parent package file object
  34. *
  35. * @var PEAR_PackageFile_v2_rw
  36. */
  37. public $_pkg;
  38. /**
  39. * Enter description here...
  40. *
  41. * @param PEAR_PackageFile_v2_rw $pkg Package
  42. * @param PEAR_Config $config Config
  43. * @param PEAR_Frontend $logger Logger
  44. * @param array $fileXml XML
  45. *
  46. * @return PEAR_Task_Postinstallscript_rw
  47. */
  48. function __construct(&$pkg, &$config, &$logger, $fileXml)
  49. {
  50. parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
  51. $this->_contents = $fileXml;
  52. $this->_pkg = &$pkg;
  53. $this->_params = array();
  54. }
  55. public function validate()
  56. {
  57. return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
  58. }
  59. public function getName()
  60. {
  61. return 'postinstallscript';
  62. }
  63. /**
  64. * add a simple <paramgroup> to the post-install script
  65. *
  66. * Order is significant, so call this method in the same
  67. * sequence the users should see the paramgroups. The $params
  68. * parameter should either be the result of a call to {@link getParam()}
  69. * or an array of calls to getParam().
  70. *
  71. * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing
  72. * a <conditiontype> tag
  73. *
  74. * @param string $id <paramgroup> id as seen by the script
  75. * @param array|false $params array of getParam() calls, or false for no params
  76. * @param string|false $instructions
  77. */
  78. public function addParamGroup($id, $params = false, $instructions = false)
  79. {
  80. if ($params && isset($params[0]) && !isset($params[1])) {
  81. $params = $params[0];
  82. }
  83. $stuff =
  84. array(
  85. $this->_pkg->getTasksNs().':id' => $id,
  86. );
  87. if ($instructions) {
  88. $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
  89. }
  90. if ($params) {
  91. $stuff[$this->_pkg->getTasksNs().':param'] = $params;
  92. }
  93. $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
  94. }
  95. /**
  96. * Add a complex <paramgroup> to the post-install script with conditions
  97. *
  98. * This inserts a <paramgroup> with
  99. *
  100. * Order is significant, so call this method in the same
  101. * sequence the users should see the paramgroups. The $params
  102. * parameter should either be the result of a call to {@link getParam()}
  103. * or an array of calls to getParam().
  104. *
  105. * Use {@link addParamGroup()} to add a simple <paramgroup>
  106. *
  107. * @param string $id <paramgroup> id as seen by the script
  108. * @param string $oldgroup <paramgroup> id of the section referenced by
  109. * <conditiontype>
  110. * @param string $param name of the <param> from the older section referenced
  111. * by <contitiontype>
  112. * @param string $value value to match of the parameter
  113. * @param string $conditiontype one of '=', '!=', 'preg_match'
  114. * @param array|false $params array of getParam() calls, or false for no params
  115. * @param string|false $instructions
  116. */
  117. public function addConditionTypeGroup($id,
  118. $oldgroup,
  119. $param,
  120. $value,
  121. $conditiontype = '=',
  122. $params = false,
  123. $instructions = false
  124. ) {
  125. if ($params && isset($params[0]) && !isset($params[1])) {
  126. $params = $params[0];
  127. }
  128. $stuff = array(
  129. $this->_pkg->getTasksNs().':id' => $id,
  130. );
  131. if ($instructions) {
  132. $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
  133. }
  134. $stuff[$this->_pkg->getTasksNs().':name'] = $oldgroup.'::'.$param;
  135. $stuff[$this->_pkg->getTasksNs().':conditiontype'] = $conditiontype;
  136. $stuff[$this->_pkg->getTasksNs().':value'] = $value;
  137. if ($params) {
  138. $stuff[$this->_pkg->getTasksNs().':param'] = $params;
  139. }
  140. $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
  141. }
  142. public function getXml()
  143. {
  144. return $this->_params;
  145. }
  146. /**
  147. * Use to set up a param tag for use in creating a paramgroup
  148. *
  149. * @param mixed $name Name of parameter
  150. * @param mixed $prompt Prompt
  151. * @param string $type Type, defaults to 'string'
  152. * @param mixed $default Default value
  153. *
  154. * @return array
  155. */
  156. public function getParam(
  157. $name, $prompt, $type = 'string', $default = null
  158. ) {
  159. if ($default !== null) {
  160. return
  161. array(
  162. $this->_pkg->getTasksNs().':name' => $name,
  163. $this->_pkg->getTasksNs().':prompt' => $prompt,
  164. $this->_pkg->getTasksNs().':type' => $type,
  165. $this->_pkg->getTasksNs().':default' => $default,
  166. );
  167. }
  168. return
  169. array(
  170. $this->_pkg->getTasksNs().':name' => $name,
  171. $this->_pkg->getTasksNs().':prompt' => $prompt,
  172. $this->_pkg->getTasksNs().':type' => $type,
  173. );
  174. }
  175. }