rw.php 5.7 KB

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