Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 5                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 2004-2007, Clay Loveless                               |
7
// | All rights reserved.                                                 |
8
// +----------------------------------------------------------------------+
9
// | This LICENSE is in the BSD license style.                            |
10
// | http://www.opensource.org/licenses/bsd-license.php                   |
11
// |                                                                      |
12
// | Redistribution and use in source and binary forms, with or without   |
13
// | modification, are permitted provided that the following conditions   |
14
// | are met:                                                             |
15
// |                                                                      |
16
// |  * Redistributions of source code must retain the above copyright    |
17
// |    notice, this list of conditions and the following disclaimer.     |
18
// |                                                                      |
19
// |  * Redistributions in binary form must reproduce the above           |
20
// |    copyright notice, this list of conditions and the following       |
21
// |    disclaimer in the documentation and/or other materials provided   |
22
// |    with the distribution.                                            |
23
// |                                                                      |
24
// |  * Neither the name of Clay Loveless nor the names of contributors   |
25
// |    may be used to endorse or promote products derived from this      |
26
// |    software without specific prior written permission.               |
27
// |                                                                      |
28
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
32
// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35
// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36
// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38
// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39
// | POSSIBILITY OF SUCH DAMAGE.                                          |
40
// +----------------------------------------------------------------------+
41
// | Author: Clay Loveless <clay@killersoft.com>                          |
42
// +----------------------------------------------------------------------+
43
//
44
// $Id: Propdel.php 286753 2009-08-03 19:37:03Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Propdel command manager class
55
 *
56
 * Remove PROPNAME from files, dirs, or revisions.
57
 *
58
 * $switches is an array containing one or more command line options
59
 * defined by the following associative keys:
60
 *
61
 * <code>
62
 *
63
 * $switches = array(
64
 *  'q [quiet]'     =>  true|false,
65
 *                      // prints as little as possible
66
 *  'R'             =>  true|false,
67
 *                      // descend recursively
68
 *  'recursive'     =>  true|false,
69
 *                      // descend recursively
70
 *  'revprop'       =>  true|false,
71
 *                      // operate on a revision property (use with r)
72
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
73
 *                        A revision argument can be one of:
74
 *                           NUMBER       revision number
75
 *                           "{" DATE "}" revision at start of the date
76
 *                           "HEAD"       latest in repository
77
 *                           "BASE"       base rev of item's working copy
78
 *                           "COMMITTED"  last commit at or before BASE
79
 *                           "PREV"       revision just before COMMITTED',
80
 *                      // either 'r' or 'revision' may be used
81
 *  'username'      =>  'Subversion repository login',
82
 *  'password'      =>  'Subversion repository password',
83
 *  'no-auth-cache' =>  true|false,
84
 *                      // Do not cache authentication tokens
85
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
86
 * );
87
 *
88
 * </code>
89
 *
90
 * Note: Subversion does not offer an XML output option for this subcommand
91
 *
92
 * The non-interactive option available on the command-line
93
 * svn client may also be set (true|false), but it is set to true by default.
94
 *
95
 * Usage example:
96
 * <code>
97
 * <?php
98
 * require_once 'VersionControl/SVN.php';
99
 *
100
 * // Setup error handling -- always a good idea!
101
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
102
 *
103
 * // Set up runtime options. Will be passed to all
104
 * // subclasses.
105
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
106
 *
107
 * // Pass array of subcommands we need to factory
108
 * $svn = VersionControl_SVN::factory(array('propdel'), $options);
109
 *
110
 * // Define any switches and aguments we may need
111
 * $switches = array('revprop' => true, 'r' => '10', 'username' => 'user', 'password' => 'pass');
112
 * $args = array('release-date');
113
 *
114
 * // Run command -- will remove 'release-date' property from revision 10
115
 * if ($output = $svn->propdel->run($args, $switches)) {
116
 *     print_r($output);
117
 * } else {
118
 *     if (count($errs = $svnstack->getErrors())) {
119
 *         foreach ($errs as $err) {
120
 *             echo '<br />'.$err['message']."<br />\n";
121
 *             echo "Command used: " . $err['params']['cmd'];
122
 *         }
123
 *     }
124
 * }
125
 * ?>
126
 * </code>
127
 *
128
 * @package  VersionControl_SVN
129
 * @version  0.3.4
130
 * @category SCM
131
 * @author   Clay Loveless <clay@killersoft.com>
132
 */
133
class VersionControl_SVN_Propdel extends VersionControl_SVN
134
{
135
    /**
136
     * Valid switches for svn propdel
137
     *
138
     * @var     array
139
     * @access  public
140
     */
141
    var $valid_switches = array('r',
142
                                'revision',
143
                                'revprop',
144
                                'R',
145
                                'recursive',
146
                                'q',
147
                                'quiet',
148
                                'username',
149
                                'password',
150
                                'no-auth-cache',
151
                                'no_auth_cache',
152
                                'non-interactive',
153
                                'non_interactive',
154
                                'config-dir'
155
                                );
156
 
157
    /**
158
     * Command-line arguments that should be passed
159
     * <b>outside</b> of those specified in {@link switches}.
160
     *
161
     * @var     array
162
     * @access  public
163
     */
164
    var $args = array();
165
 
166
    /**
167
     * Minimum number of args required by this subcommand.
168
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
169
     * Subversion Complete Reference for details on arguments for this subcommand.
170
     * @var     int
171
     * @access  public
172
     */
173
    var $min_args = 1;
174
 
175
    /**
176
     * Switches required by this subcommand.
177
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
178
     * Subversion Complete Reference for details on arguments for this subcommand.
179
     * @var     array
180
     * @access  public
181
     */
182
    var $required_switches = array();
183
 
184
    /**
185
     * Use exec or passthru to get results from command.
186
     * @var     bool
187
     * @access  public
188
     */
189
    var $passthru = false;
190
 
191
    /**
192
     * Prepare the svn subcommand switches.
193
     *
194
     * Defaults to non-interactive mode, and will auto-set the
195
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
196
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
197
     *
198
     * @param   void
199
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
200
     *                 for error details, if any.
201
     */
202
    function prepare()
203
    {
204
        $meets_requirements = $this->checkCommandRequirements();
205
        if (!$meets_requirements) {
206
            return false;
207
        }
208
 
209
        $valid_switches     = $this->valid_switches;
210
        $switches           = $this->switches;
211
        $args               = $this->args;
212
        $fetchmode          = $this->fetchmode;
213
        $invalid_switches   = array();
214
        $_switches          = '';
215
 
216
        foreach ($switches as $switch => $val) {
217
            if (in_array($switch, $valid_switches)) {
218
                $switch = str_replace('_', '-', $switch);
219
                switch ($switch) {
220
                    case 'revision':
221
                    case 'username':
222
                    case 'password':
223
                    case 'config-dir':
224
                        $_switches .= "--$switch $val ";
225
                        break;
226
                    case 'r':
227
                        $_switches .= "-$switch $val ";
228
                        break;
229
                    case 'quiet':
230
                    case 'revprop':
231
                    case 'non-interactive':
232
                    case 'recursive':
233
                    case 'no-auth-cache':
234
                        if ($val === true) {
235
                            $_switches .= "--$switch ";
236
                        }
237
                        break;
238
                    case 'q':
239
                    case 'R':
240
                        if ($val === true) {
241
                            $_switches .= "-$switch ";
242
                        }
243
                        break;
244
                    default:
245
                        // that's all, folks!
246
                        break;
247
                }
248
            } else {
249
                $invalid_switches[] = $switch;
250
            }
251
        }
252
 
253
        $_switches = trim($_switches);
254
        $this->_switches = $_switches;
255
 
256
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
257
        if (!empty($args)) {
258
            $cmd .= ' '. join(' ', $args);
259
        }
260
 
261
        $this->_prepped_cmd = $cmd;
262
        $this->prepared = true;
263
 
264
        $invalid = count($invalid_switches);
265
        if ($invalid > 0) {
266
            $params['was'] = 'was';
267
            $params['is_invalid_switch'] = 'is an invalid switch';
268
            if ($invalid > 1) {
269
                $params['was'] = 'were';
270
                $params['is_invalid_switch'] = 'are invalid switches';
271
            }
272
            $params['list'] = $invalid_switches;
273
            $params['switches'] = $switches;
274
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
275
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
276
        }
277
        return true;
278
    }
279
 
280
    // }}}
281
    // {{{ parseOutput()
282
 
283
    /**
284
     * Handles output parsing of standard and verbose output of command.
285
     *
286
     * @param   array   $out    Array of output captured by exec command in {@link run}.
287
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
288
     *                  if desired fetchmode is not available.
289
     * @access  public
290
     */
291
    function parseOutput($out)
292
    {
293
        $fetchmode = $this->fetchmode;
294
        switch($fetchmode) {
295
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
296
                return join("\n", $out);
297
                break;
298
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
299
                // Temporary, see parseOutputArray below
300
                return join("\n", $out);
301
                break;
302
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
303
                // Temporary, will return object-ified array from
304
                // parseOutputArray
305
                return join("\n", $out);
306
                break;
307
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
308
                // Temporary, will eventually build an XML string
309
                // with XML_Util or XML_Tree
310
                return join("\n", $out);
311
                break;
312
            default:
313
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
314
                return join("\n", $out);
315
                break;
316
        }
317
    }
318
 
319
    /**
320
     * Helper method for parseOutput that parses output into an associative array
321
     *
322
     * @todo Finish this method! : )
323
     */
324
    function parseOutputArray($out)
325
    {
326
        $parsed = array();
327
    }
328
}
329
 
330
// }}}
331
?>