Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 1
<?php
2
/**
3
 * <tasks:postinstallscript> - read/write version
4
 *
5
 * PHP versions 4 and 5
6
 *
187 mathias 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
94 jpm 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>
187 mathias 24
 * @copyright  1997-2009 The Authors
25
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
26
 * @version    Release: 1.10.1
94 jpm 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
     */
187 mathias 37
    public $_pkg;
94 jpm 38
    /**
39
     * Enter description here...
40
     *
187 mathias 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
     *
94 jpm 46
     * @return PEAR_Task_Postinstallscript_rw
47
     */
187 mathias 48
    function __construct(&$pkg, &$config, &$logger, $fileXml)
94 jpm 49
    {
187 mathias 50
        parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
94 jpm 51
        $this->_contents = $fileXml;
52
        $this->_pkg = &$pkg;
53
        $this->_params = array();
54
    }
55
 
187 mathias 56
    public function validate()
94 jpm 57
    {
58
        return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
59
    }
60
 
187 mathias 61
    public function getName()
94 jpm 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().
187 mathias 73
     *
94 jpm 74
     * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing
75
     * a <conditiontype> tag
187 mathias 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
94 jpm 79
     * @param string|false $instructions
80
     */
187 mathias 81
    public function addParamGroup($id, $params = false, $instructions = false)
94 jpm 82
    {
83
        if ($params && isset($params[0]) && !isset($params[1])) {
84
            $params = $params[0];
85
        }
86
        $stuff =
87
            array(
187 mathias 88
                $this->_pkg->getTasksNs().':id' => $id,
94 jpm 89
            );
90
        if ($instructions) {
187 mathias 91
            $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
94 jpm 92
        }
93
        if ($params) {
187 mathias 94
            $stuff[$this->_pkg->getTasksNs().':param'] = $params;
94 jpm 95
        }
187 mathias 96
        $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
94 jpm 97
    }
98
 
99
    /**
187 mathias 100
     * Add a complex <paramgroup> to the post-install script with conditions
94 jpm 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().
187 mathias 108
     *
94 jpm 109
     * Use {@link addParamGroup()} to add a simple <paramgroup>
110
     *
187 mathias 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
94 jpm 119
     * @param string|false $instructions
120
     */
187 mathias 121
    public function addConditionTypeGroup($id,
122
        $oldgroup,
123
        $param,
124
        $value,
125
        $conditiontype = '=',
126
        $params = false,
127
        $instructions = false
128
    ) {
94 jpm 129
        if ($params && isset($params[0]) && !isset($params[1])) {
130
            $params = $params[0];
131
        }
187 mathias 132
        $stuff = array(
133
            $this->_pkg->getTasksNs().':id' => $id,
134
        );
94 jpm 135
        if ($instructions) {
187 mathias 136
            $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
94 jpm 137
        }
187 mathias 138
        $stuff[$this->_pkg->getTasksNs().':name'] = $oldgroup.'::'.$param;
139
        $stuff[$this->_pkg->getTasksNs().':conditiontype'] = $conditiontype;
140
        $stuff[$this->_pkg->getTasksNs().':value'] = $value;
94 jpm 141
        if ($params) {
187 mathias 142
            $stuff[$this->_pkg->getTasksNs().':param'] = $params;
94 jpm 143
        }
187 mathias 144
        $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
94 jpm 145
    }
146
 
187 mathias 147
    public function getXml()
94 jpm 148
    {
149
        return $this->_params;
150
    }
151
 
152
    /**
153
     * Use to set up a param tag for use in creating a paramgroup
187 mathias 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
94 jpm 161
     */
187 mathias 162
    public static function getParam(
163
        $name, $prompt, $type = 'string', $default = null
164
    ) {
94 jpm 165
        if ($default !== null) {
187 mathias 166
            return
94 jpm 167
            array(
187 mathias 168
                $this->_pkg->getTasksNs().':name' => $name,
169
                $this->_pkg->getTasksNs().':prompt' => $prompt,
170
                $this->_pkg->getTasksNs().':type' => $type,
171
                $this->_pkg->getTasksNs().':default' => $default,
94 jpm 172
            );
173
        }
187 mathias 174
 
94 jpm 175
        return
176
            array(
187 mathias 177
                $this->_pkg->getTasksNs().':name' => $name,
178
                $this->_pkg->getTasksNs().':prompt' => $prompt,
179
                $this->_pkg->getTasksNs().':type' => $type,
94 jpm 180
            );
181
    }
182
}