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 */ 18require_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: @package_version@ 27 * @link http://pear.php.net/package/PEAR 28 * @since Class available since Release 1.4.0a10 29 */ 30class 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 56 public function validate() 57 { 58 return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); 59 } 60 61 public function getName() 62 { 63 return 'postinstallscript'; 64 } 65 66 /** 67 * add a simple <paramgroup> to the post-install script 68 * 69 * Order is significant, so call this method in the same 70 * sequence the users should see the paramgroups. The $params 71 * parameter should either be the result of a call to {@link getParam()} 72 * or an array of calls to getParam(). 73 * 74 * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing 75 * a <conditiontype> tag 76 * 77 * @param string $id <paramgroup> id as seen by the script 78 * @param array|false $params array of getParam() calls, or false for no params 79 * @param string|false $instructions 80 */ 81 public function addParamGroup($id, $params = false, $instructions = false) 82 { 83 if ($params && isset($params[0]) && !isset($params[1])) { 84 $params = $params[0]; 85 } 86 $stuff = 87 array( 88 $this->_pkg->getTasksNs().':id' => $id, 89 ); 90 if ($instructions) { 91 $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions; 92 } 93 if ($params) { 94 $stuff[$this->_pkg->getTasksNs().':param'] = $params; 95 } 96 $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff; 97 } 98 99 /** 100 * Add a complex <paramgroup> to the post-install script with conditions 101 * 102 * This inserts a <paramgroup> with 103 * 104 * Order is significant, so call this method in the same 105 * sequence the users should see the paramgroups. The $params 106 * parameter should either be the result of a call to {@link getParam()} 107 * or an array of calls to getParam(). 108 * 109 * Use {@link addParamGroup()} to add a simple <paramgroup> 110 * 111 * @param string $id <paramgroup> id as seen by the script 112 * @param string $oldgroup <paramgroup> id of the section referenced by 113 * <conditiontype> 114 * @param string $param name of the <param> from the older section referenced 115 * by <contitiontype> 116 * @param string $value value to match of the parameter 117 * @param string $conditiontype one of '=', '!=', 'preg_match' 118 * @param array|false $params array of getParam() calls, or false for no params 119 * @param string|false $instructions 120 */ 121 public function addConditionTypeGroup($id, 122 $oldgroup, 123 $param, 124 $value, 125 $conditiontype = '=', 126 $params = false, 127 $instructions = false 128 ) { 129 if ($params && isset($params[0]) && !isset($params[1])) { 130 $params = $params[0]; 131 } 132 $stuff = array( 133 $this->_pkg->getTasksNs().':id' => $id, 134 ); 135 if ($instructions) { 136 $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions; 137 } 138 $stuff[$this->_pkg->getTasksNs().':name'] = $oldgroup.'::'.$param; 139 $stuff[$this->_pkg->getTasksNs().':conditiontype'] = $conditiontype; 140 $stuff[$this->_pkg->getTasksNs().':value'] = $value; 141 if ($params) { 142 $stuff[$this->_pkg->getTasksNs().':param'] = $params; 143 } 144 $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff; 145 } 146 147 public function getXml() 148 { 149 return $this->_params; 150 } 151 152 /** 153 * Use to set up a param tag for use in creating a paramgroup 154 * 155 * @param mixed $name Name of parameter 156 * @param mixed $prompt Prompt 157 * @param string $type Type, defaults to 'string' 158 * @param mixed $default Default value 159 * 160 * @return array 161 */ 162 public function getParam( 163 $name, $prompt, $type = 'string', $default = null 164 ) { 165 if ($default !== null) { 166 return 167 array( 168 $this->_pkg->getTasksNs().':name' => $name, 169 $this->_pkg->getTasksNs().':prompt' => $prompt, 170 $this->_pkg->getTasksNs().':type' => $type, 171 $this->_pkg->getTasksNs().':default' => $default, 172 ); 173 } 174 175 return 176 array( 177 $this->_pkg->getTasksNs().':name' => $name, 178 $this->_pkg->getTasksNs().':prompt' => $prompt, 179 $this->_pkg->getTasksNs().':type' => $type, 180 ); 181 } 182} 183