Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Task_Common, base class for installer tasks
3
 * PEAR_Task_Common, base class for installer tasks
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
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   pear
7
 * @category  pear
14
 * @package    PEAR
8
 * @package   PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author    Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright 1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: Common.php,v 1.16 2006/11/12 05:02:41 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link      http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since     File available since Release 1.4.0a1
21
 */
14
 */
22
/**#@+
15
/**#@+
23
 * Error codes for task validation routines
16
 * Error codes for task validation routines
24
 */
17
 */
25
define('PEAR_TASK_ERROR_NOATTRIBS', 1);
18
define('PEAR_TASK_ERROR_NOATTRIBS', 1);
Line 46... Line 39...
46
 * </file>
39
 * </file>
47
 *
40
 *
48
 * This will first replace any instance of @data-dir@ in the test.php file
41
 * This will first replace any instance of @data-dir@ in the test.php file
49
 * with the path to the current data directory.  Then, it will include the
42
 * with the path to the current data directory.  Then, it will include the
50
 * test.php file and run the script it contains to configure the package post-installation.
43
 * test.php file and run the script it contains to configure the package post-installation.
-
 
44
 *
51
 * @category   pear
45
 * @category  pear
52
 * @package    PEAR
46
 * @package   PEAR
53
 * @author     Greg Beaver <cellog@php.net>
47
 * @author    Greg Beaver <cellog@php.net>
54
 * @copyright  1997-2006 The PHP Group
48
 * @copyright 1997-2009 The Authors
55
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
49
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
56
 * @version    Release: 1.5.1
50
 * @version   Release: 1.10.1
57
 * @link       http://pear.php.net/package/PEAR
51
 * @link      http://pear.php.net/package/PEAR
58
 * @since      Class available since Release 1.4.0a1
52
 * @since     Class available since Release 1.4.0a1
59
 * @abstract
53
 * @abstract
60
 */
54
 */
61
class PEAR_Task_Common
55
class PEAR_Task_Common
62
{
56
{
63
    /**
57
    /**
Line 66... Line 60...
66
     * - simple tasks operate on the contents of a file and write out changes to disk
60
     * - simple tasks operate on the contents of a file and write out changes to disk
67
     * - multiple tasks operate on the contents of many files and write out the
61
     * - multiple tasks operate on the contents of many files and write out the
68
     *   changes directly to disk
62
     *   changes directly to disk
69
     *
63
     *
70
     * Child task classes must override this property.
64
     * Child task classes must override this property.
-
 
65
     *
71
     * @access protected
66
     * @access protected
72
     */
67
     */
73
    var $type = 'simple';
68
    protected $type = 'simple';
74
    /**
69
    /**
75
     * Determines which install phase this task is executed under
70
     * Determines which install phase this task is executed under
76
     */
71
     */
77
    var $phase = PEAR_TASK_INSTALL;
72
    public $phase = PEAR_TASK_INSTALL;
78
    /**
73
    /**
79
     * @access protected
74
     * @access protected
80
     */
75
     */
81
    var $config;
76
    protected $config;
82
    /**
77
    /**
83
     * @access protected
78
     * @access protected
84
     */
79
     */
85
    var $registry;
80
    protected $registry;
86
    /**
81
    /**
87
     * @access protected
82
     * @access protected
88
     */
83
     */
89
    var $logger;
84
    public $logger;
90
    /**
85
    /**
91
     * @access protected
86
     * @access protected
92
     */
87
     */
93
    var $installphase;
88
    protected $installphase;
94
    /**
89
    /**
95
     * @param PEAR_Config
90
     * @param PEAR_Config
96
     * @param PEAR_Common
91
     * @param PEAR_Common
97
     */
92
     */
98
    function PEAR_Task_Common(&$config, &$logger, $phase)
93
    function __construct(&$config, &$logger, $phase)
99
    {
94
    {
100
        $this->config = &$config;
95
        $this->config = &$config;
101
        $this->registry = &$config->getRegistry();
96
        $this->registry = &$config->getRegistry();
102
        $this->logger = &$logger;
97
        $this->logger = &$logger;
103
        $this->installphase = $phase;
98
        $this->installphase = $phase;
Line 106... Line 101...
106
        }
101
        }
107
    }
102
    }
Line 108... Line 103...
108
 
103
 
109
    /**
104
    /**
-
 
105
     * Validate the basic contents of a task tag.
110
     * Validate the basic contents of a task tag.
106
     *
111
     * @param PEAR_PackageFile_v2
107
     * @param PEAR_PackageFile_v2
112
     * @param array
108
     * @param array
113
     * @param PEAR_Config
109
     * @param PEAR_Config
-
 
110
     * @param array the entire parsed <file> tag
114
     * @param array the entire parsed <file> tag
111
     *
115
     * @return true|array On error, return an array in format:
112
     * @return true|array On error, return an array in format:
-
 
113
     *                    array(PEAR_TASK_ERROR_???[, param1][, param2][, ...])
-
 
114
     *
-
 
115
     * For PEAR_TASK_ERROR_MISSING_ATTRIB, pass the attribute name in
-
 
116
     * For PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, pass the attribute name and
116
     *    array(PEAR_TASK_ERROR_???[, param1][, param2][, ...])
117
     * an array of legal values in
117
     *
-
 
118
     *    For PEAR_TASK_ERROR_MISSING_ATTRIB, pass the attribute name in
-
 
119
     *    For PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, pass the attribute name and an array
-
 
120
     *    of legal values in
-
 
121
     * @static
118
     *
122
     * @abstract
119
     * @abstract
123
     */
120
     */
124
    function validateXml($pkg, $xml, &$config, $fileXml)
121
    public static function validateXml($pkg, $xml, $config, $fileXml)
125
    {
122
    {
Line 126... Line 123...
126
    }
123
    }
127
 
124
 
-
 
125
    /**
128
    /**
126
     * Initialize a task instance with the parameters
129
     * Initialize a task instance with the parameters
127
     *
130
     * @param array raw, parsed xml
128
     * @param    array raw, parsed xml
131
     * @param array attributes from the <file> tag containing this task
129
     * @param    array attributes from the <file> tag containing this task
132
     * @param string|null last installed version of this package
130
     * @param    string|null last installed version of this package
133
     * @abstract
131
     * @abstract
134
     */
132
     */
135
    function init($xml, $fileAttributes, $lastVersion)
133
    public function init($xml, $fileAttributes, $lastVersion)
Line 136... Line 134...
136
    {
134
    {
137
    }
135
    }
138
 
136
 
-
 
137
    /**
139
    /**
138
     * Begin a task processing session.  All multiple tasks will be processed
140
     * Begin a task processing session.  All multiple tasks will be processed after each file
139
     * after each file has been successfully installed, all simple tasks should
141
     * has been successfully installed, all simple tasks should perform their task here and
140
     * perform their task here and return any errors using the custom
-
 
141
     * throwError() method to allow forward compatibility
142
     * return any errors using the custom throwError() method to allow forward compatibility
142
     *
143
     *
143
     * This method MUST NOT write out any changes to disk
144
     * This method MUST NOT write out any changes to disk
144
     *
145
     * @param PEAR_PackageFile_v2
145
     * @param    PEAR_PackageFile_v2
146
     * @param string file contents
146
     * @param    string file contents
147
     * @param string the eventual final file location (informational only)
147
     * @param    string the eventual final file location (informational only)
148
     * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
148
     * @return   string|false|PEAR_Error false to skip this file, PEAR_Error to fail
149
     *         (use $this->throwError), otherwise return the new contents
149
     *           (use $this->throwError), otherwise return the new contents
150
     * @abstract
150
     * @abstract
151
     */
151
     */
Line 152... Line 152...
152
    function startSession($pkg, $contents, $dest)
152
    public function startSession($pkg, $contents, $dest)
153
    {
153
    {
154
    }
154
    }
-
 
155
 
155
 
156
    /**
156
    /**
157
     * This method is used to process each of the tasks for a particular
157
     * This method is used to process each of the tasks for a particular multiple class
-
 
158
     * type.  Simple tasks need not implement this method.
-
 
159
     * @param array an array of tasks
158
     * multiple class type.  Simple tasks need not implement this method.
160
     * @access protected
159
     *
161
     * @static
160
     * @param    array an array of tasks
162
     * @abstract
161
     * @access   protected
Line 163... Line 162...
163
     */
162
     */
164
    function run($tasks)
-
 
165
    {
163
    public static function run($tasks)
166
    }
164
    {
167
 
165
    }
168
    /**
166
 
169
     * @static
167
    /**
170
     * @final
168
     * @final
Line 171... Line 169...
171
     */
169
     */
172
    function hasPostinstallTasks()
-
 
173
    {
170
    public static function hasPostinstallTasks()
174
        return isset($GLOBALS['_PEAR_TASK_POSTINSTANCES']);
171
    {
175
    }
172
        return isset($GLOBALS['_PEAR_TASK_POSTINSTANCES']);
176
 
173
    }
177
    /**
174
 
-
 
175
     /**
178
     * @static
176
      * @final
179
     * @final
177
      */
-
 
178
    public static function runPostinstallTasks()
180
     */
179
    {
181
     function runPostinstallTasks()
180
        foreach ($GLOBALS['_PEAR_TASK_POSTINSTANCES'] as $class => $tasks) {
182
     {
181
            $err = call_user_func(
183
         foreach ($GLOBALS['_PEAR_TASK_POSTINSTANCES'] as $class => $tasks) {
182
                array($class, 'run'),
184
             $err = call_user_func(array($class, 'run'),
183
                $GLOBALS['_PEAR_TASK_POSTINSTANCES'][$class]
185
                  $GLOBALS['_PEAR_TASK_POSTINSTANCES'][$class]);
184
            );
Line 186... Line 185...
186
             if ($err) {
185
            if ($err) {
187
                 return PEAR_Task_Common::throwError($err);
186
                return PEAR_Task_Common::throwError($err);
188
             }
187
            }
189
         }
188
        }
190
         unset($GLOBALS['_PEAR_TASK_POSTINSTANCES']);
189
        unset($GLOBALS['_PEAR_TASK_POSTINSTANCES']);
191
    }
190
    }
192
 
191
 
193
    /**
192
    /**
Line 194... Line 193...
194
     * Determines whether a role is a script
193
     * Determines whether a role is a script
195
     * @return bool
194
     * @return bool
196
     */
195
     */
-
 
196
    public function isScript()
197
    function isScript()
197
    {
198
    {
198
            return $this->type == 'script';
199
        return $this->type == 'script';
199
    }
200
    }
-
 
201
 
200