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
 * <tasks:replace>
3
 * <tasks:replace>
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: Replace.php,v 1.15 2006/03/02 18:14:13 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
 * Base class
16
 * Base class
24
 */
17
 */
25
require_once 'PEAR/Task/Common.php';
18
require_once 'PEAR/Task/Common.php';
26
/**
19
/**
27
 * Implements the replace file task.
20
 * Implements the replace file task.
28
 * @category   pear
21
 * @category   pear
29
 * @package    PEAR
22
 * @package    PEAR
30
 * @author     Greg Beaver <cellog@php.net>
23
 * @author     Greg Beaver <cellog@php.net>
31
 * @copyright  1997-2006 The PHP Group
24
 * @copyright  1997-2009 The Authors
32
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
25
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
33
 * @version    Release: 1.5.1
26
 * @version    Release: 1.10.1
34
 * @link       http://pear.php.net/package/PEAR
27
 * @link       http://pear.php.net/package/PEAR
35
 * @since      Class available since Release 1.4.0a1
28
 * @since      Class available since Release 1.4.0a1
36
 */
29
 */
37
class PEAR_Task_Replace extends PEAR_Task_Common
30
class PEAR_Task_Replace extends PEAR_Task_Common
38
{
31
{
39
    var $type = 'simple';
32
    public $type = 'simple';
40
    var $phase = PEAR_TASK_PACKAGEANDINSTALL;
33
    public $phase = PEAR_TASK_PACKAGEANDINSTALL;
41
    var $_replacements;
34
    public $_replacements;
Line 42... Line 35...
42
 
35
 
43
    /**
36
    /**
-
 
37
     * Validate the raw xml at parsing-time.
44
     * Validate the raw xml at parsing-time.
38
     *
45
     * @param PEAR_PackageFile_v2
39
     * @param  PEAR_PackageFile_v2
46
     * @param array raw, parsed xml
40
     * @param  array raw, parsed xml
47
     * @param PEAR_Config
-
 
48
     * @static
41
     * @param  PEAR_Config
49
     */
42
     */
50
    function validateXml($pkg, $xml, &$config, $fileXml)
43
    public static function validateXml($pkg, $xml, $config, $fileXml)
51
    {
44
    {
52
        if (!isset($xml['attribs'])) {
45
        if (!isset($xml['attribs'])) {
53
            return array(PEAR_TASK_ERROR_NOATTRIBS);
46
            return array(PEAR_TASK_ERROR_NOATTRIBS);
54
        }
47
        }
Line 62... Line 55...
62
            return array(PEAR_TASK_ERROR_MISSING_ATTRIB, 'from');
55
            return array(PEAR_TASK_ERROR_MISSING_ATTRIB, 'from');
63
        }
56
        }
64
        if ($xml['attribs']['type'] == 'pear-config') {
57
        if ($xml['attribs']['type'] == 'pear-config') {
65
            if (!in_array($xml['attribs']['to'], $config->getKeys())) {
58
            if (!in_array($xml['attribs']['to'], $config->getKeys())) {
66
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
59
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
67
                    $config->getKeys());
60
                    $config->getKeys(), );
68
            }
61
            }
69
        } elseif ($xml['attribs']['type'] == 'php-const') {
62
        } elseif ($xml['attribs']['type'] == 'php-const') {
70
            if (defined($xml['attribs']['to'])) {
63
            if (defined($xml['attribs']['to'])) {
71
                return true;
64
                return true;
72
            } else {
65
            } else {
73
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
66
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
74
                    array('valid PHP constant'));
67
                    array('valid PHP constant'), );
75
            }
68
            }
76
        } elseif ($xml['attribs']['type'] == 'package-info') {
69
        } elseif ($xml['attribs']['type'] == 'package-info') {
-
 
70
            if (in_array(
77
            if (in_array($xml['attribs']['to'],
71
                $xml['attribs']['to'],
78
                array('name', 'summary', 'channel', 'notes', 'extends', 'description',
72
                array('name', 'summary', 'channel', 'notes', 'extends', 'description',
79
                    'release_notes', 'license', 'release-license', 'license-uri',
73
                    'release_notes', 'license', 'release-license', 'license-uri',
80
                    'version', 'api-version', 'state', 'api-state', 'release_date',
74
                    'version', 'api-version', 'state', 'api-state', 'release_date',
81
                    'date', 'time'))) {
75
                    'date', 'time', )
-
 
76
            )) {
82
                return true;
77
                return true;
83
            } else {
78
            } else {
84
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
79
                return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
85
                    array('name', 'summary', 'channel', 'notes', 'extends', 'description',
80
                    array('name', 'summary', 'channel', 'notes', 'extends', 'description',
86
                    'release_notes', 'license', 'release-license', 'license-uri',
81
                    'release_notes', 'license', 'release-license', 'license-uri',
87
                    'version', 'api-version', 'state', 'api-state', 'release_date',
82
                    'version', 'api-version', 'state', 'api-state', 'release_date',
88
                    'date', 'time'));
83
                    'date', 'time', ), );
89
            }
84
            }
90
        } else {
85
        } else {
91
            return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'type', $xml['attribs']['type'],
86
            return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'type', $xml['attribs']['type'],
92
                array('pear-config', 'package-info', 'php-const'));
87
                array('pear-config', 'package-info', 'php-const'), );
93
        }
88
        }
-
 
89
 
94
        return true;
90
        return true;
95
    }
91
    }
Line 96... Line 92...
96
 
92
 
97
    /**
93
    /**
98
     * Initialize a task instance with the parameters
94
     * Initialize a task instance with the parameters
99
     * @param array raw, parsed xml
95
     * @param array raw, parsed xml
-
 
96
     * @param unused
100
     * @param unused
97
     * @param unused
101
     */
98
     */
102
    function init($xml, $attribs)
99
    public function init($xml, $attribs, $lastVersion = null)
103
    {
100
    {
104
        $this->_replacements = isset($xml['attribs']) ? array($xml) : $xml;
101
        $this->_replacements = isset($xml['attribs']) ? array($xml) : $xml;
Line 105... Line 102...
105
    }
102
    }
106
 
103
 
107
    /**
104
    /**
108
     * Do a package.xml 1.0 replacement, with additional package-info fields available
105
     * Do a package.xml 1.0 replacement, with additional package-info fields available
-
 
106
     *
109
     *
107
     * See validateXml() source for the complete list of allowed fields
110
     * See validateXml() source for the complete list of allowed fields
108
     *
111
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
109
     * @param  PEAR_PackageFile_v1|PEAR_PackageFile_v2
112
     * @param string file contents
110
     * @param  string file contents
113
     * @param string the eventual final file location (informational only)
111
     * @param  string the eventual final file location (informational only)
114
     * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
112
     * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
115
     *         (use $this->throwError), otherwise return the new contents
113
     *                                 (use $this->throwError), otherwise return the new contents
116
     */
114
     */
117
    function startSession($pkg, $contents, $dest)
115
    public function startSession($pkg, $contents, $dest)
118
    {
116
    {
119
        $subst_from = $subst_to = array();
117
        $subst_from = $subst_to = array();
120
        foreach ($this->_replacements as $a) {
118
        foreach ($this->_replacements as $a) {
Line 128... Line 126...
128
                    $chan = $this->registry->getChannel($pkg->getChannel());
126
                    $chan = $this->registry->getChannel($pkg->getChannel());
129
                    if (!PEAR::isError($chan)) {
127
                    if (!PEAR::isError($chan)) {
130
                        $to = $chan->getServer();
128
                        $to = $chan->getServer();
131
                    } else {
129
                    } else {
132
                        $this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
130
                        $this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
-
 
131
 
133
                        return false;
132
                        return false;
134
                    }
133
                    }
135
                } else {
134
                } else {
136
                    if ($this->config->isDefinedLayer('ftp')) {
135
                    if ($this->config->isDefinedLayer('ftp')) {
137
                        // try the remote config file first
136
                        // try the remote config file first
Line 144... Line 143...
144
                        $to = $this->config->get($a['to'], null, $pkg->getChannel());
143
                        $to = $this->config->get($a['to'], null, $pkg->getChannel());
145
                    }
144
                    }
146
                }
145
                }
147
                if (is_null($to)) {
146
                if (is_null($to)) {
148
                    $this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
147
                    $this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
-
 
148
 
149
                    return false;
149
                    return false;
150
                }
150
                }
151
            } elseif ($a['type'] == 'php-const') {
151
            } elseif ($a['type'] == 'php-const') {
152
                if ($this->installphase == PEAR_TASK_PACKAGE) {
152
                if ($this->installphase == PEAR_TASK_PACKAGE) {
153
                    return false;
153
                    return false;
154
                }
154
                }
155
                if (defined($a['to'])) {
155
                if (defined($a['to'])) {
156
                    $to = constant($a['to']);
156
                    $to = constant($a['to']);
157
                } else {
157
                } else {
158
                    $this->logger->log(0, "$dest: invalid php-const replacement: $a[to]");
158
                    $this->logger->log(0, "$dest: invalid php-const replacement: $a[to]");
-
 
159
 
159
                    return false;
160
                    return false;
160
                }
161
                }
161
            } else {
162
            } else {
162
                if ($t = $pkg->packageInfo($a['to'])) {
163
                if ($t = $pkg->packageInfo($a['to'])) {
163
                    $to = $t;
164
                    $to = $t;
164
                } else {
165
                } else {
165
                    $this->logger->log(0, "$dest: invalid package-info replacement: $a[to]");
166
                    $this->logger->log(0, "$dest: invalid package-info replacement: $a[to]");
-
 
167
 
166
                    return false;
168
                    return false;
167
                }
169
                }
168
            }
170
            }
169
            if (!is_null($to)) {
171
            if (!is_null($to)) {
170
                $subst_from[] = $a['from'];
172
                $subst_from[] = $a['from'];
171
                $subst_to[] = $to;
173
                $subst_to[] = $to;
172
            }
174
            }
173
        }
175
        }
-
 
176
        $this->logger->log(
174
        $this->logger->log(3, "doing " . sizeof($subst_from) .
177
            3, "doing ".sizeof($subst_from).
175
            " substitution(s) for $dest");
178
            " substitution(s) for $dest"
-
 
179
        );
176
        if (sizeof($subst_from)) {
180
        if (sizeof($subst_from)) {
177
            $contents = str_replace($subst_from, $subst_to, $contents);
181
            $contents = str_replace($subst_from, $subst_to, $contents);
178
        }
182
        }
-
 
183
 
179
        return $contents;
184
        return $contents;
180
    }
185
    }
181
}
186
}
182
?>
-
 
183
187