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: Propset.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 Propset command manager class
55
 *
56
 * Set PROPNAME to PROPVAL on files, dirs, or revisions.
57
 *
58
 * Note: svn recognizes the following special versioned properties
59
 * but will store any arbitrary properties set:
60
 *   svn:ignore     - A newline separated list of file patterns to ignore.
61
 *   svn:keywords   - Keywords to be expanded.  Valid keywords are:
62
 *     URL, HeadURL             - The URL for the head version of the object.
63
 *     Author, LastChangedBy    - The last person to modify the file.
64
 *     Date, LastChangedDate    - The date/time the object was last modified.
65
 *     Rev, LastChangedRevision - The last revision the object changed.
66
 *     Id                       - A compressed summary of the previous
67
 *                                  4 keywords.
68
 *   svn:executable - If present, make the file executable. This
69
 *     property cannot be set on a directory.  A non-recursive attempt
70
 *     will fail, and a recursive attempt will set the property only
71
 *     on the file children of the directory.
72
 *   svn:eol-style  - One of 'native', 'LF', 'CR', 'CRLF'.
73
 *   svn:mime-type  - The mimetype of the file.  Used to determine
74
 *     whether to merge the file, and how to serve it from Apache.
75
 *     A mimetype beginning with 'text/' (or an absent mimetype) is
76
 *     treated as text.  Anything else is treated as binary.
77
 *   svn:externals  - A newline separated list of module specifiers,
78
 *     each of which consists of a relative directory path, optional
79
 *     revision flags, and an URL.  For example
80
 *       foo             http://example.com/repos/zig
81
 *       foo/bar -r 1234 http://example.com/repos/zag
82
 *
83
 *
84
 * $switches is an array containing one or more command line options
85
 * defined by the following associative keys:
86
 *
87
 * <code>
88
 *
89
 * $switches = array(
90
 *  'F [file]'      =>  'Read data from specified file',
91
 *                      // either 'F' or 'file' may be used
92
 *  'q [quiet]'     =>  true|false,
93
 *                      // print as little as possible
94
 *  'R'             =>  true|false,
95
 *                      // descend recursively
96
 *  'recursive'     =>  true|false,
97
 *                      // descend recursively
98
 *  'revprop'       =>  true|false,
99
 *                      // operate on a revision property (use with r)
100
 *  'targets'       =>  'ARG',
101
 *                      // pass contents of file ARG as additional args
102
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
103
 *                        A revision argument can be one of:
104
 *                           NUMBER       revision number
105
 *                           "{" DATE "}" revision at start of the date
106
 *                           "HEAD"       latest in repository
107
 *                           "BASE"       base rev of item's working copy
108
 *                           "COMMITTED"  last commit at or before BASE
109
 *                           "PREV"       revision just before COMMITTED',
110
 *                      // either 'r' or 'revision' may be used
111
 *  'username'      =>  'Subversion repository login',
112
 *  'password'      =>  'Subversion repository password',
113
 *  'no-auth-cache' =>  true|false,
114
 *                      // Do not cache authentication tokens
115
 *  'encoding'      =>  'ARG',
116
 *                      // treat value as being in charset encoding ARG
117
 *  'force'         =>  true|false,
118
 *                      // force operation to run
119
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
120
 * );
121
 *
122
 * </code>
123
 *
124
 * Note: Subversion does not offer an XML output option for this subcommand
125
 *
126
 * The non-interactive option available on the command-line
127
 * svn client may also be set (true|false), but it is set to true by default.
128
 *
129
 * Usage example:
130
 * <code>
131
 * <?php
132
 * require_once 'VersionControl/SVN.php';
133
 *
134
 * // Setup error handling -- always a good idea!
135
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
136
 *
137
 * // Set up runtime options. Will be passed to all
138
 * // subclasses.
139
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
140
 *
141
 * // Pass array of subcommands we need to factory
142
 * $svn = VersionControl_SVN::factory(array('propset'), $options);
143
 *
144
 * // Define any switches and aguments we may need
145
 * $switches = array('username' => 'user', 'password' => 'pass');
146
 * $args = array('svn:mime-type', 'image/jpeg', 'foo.jpg');
147
 *
148
 * // Run command
149
 * if ($output = $svn->propset->run($args, $switches)) {
150
 *     print_r($output);
151
 * } else {
152
 *     if (count($errs = $svnstack->getErrors())) {
153
 *         foreach ($errs as $err) {
154
 *             echo '<br />'.$err['message']."<br />\n";
155
 *             echo "Command used: " . $err['params']['cmd'];
156
 *         }
157
 *     }
158
 * }
159
 * ?>
160
 * </code>
161
 *
162
 * @package  VersionControl_SVN
163
 * @version  0.3.4
164
 * @category SCM
165
 * @author   Clay Loveless <clay@killersoft.com>
166
 */
167
class VersionControl_SVN_Propset extends VersionControl_SVN
168
{
169
    /**
170
     * Valid switches for svn propset
171
     *
172
     * @var     array
173
     * @access  public
174
     */
175
    var $valid_switches = array('r',
176
                                'revision',
177
                                'revprop',
178
                                'R',
179
                                'recursive',
180
                                'q',
181
                                'quiet',
182
                                'F',
183
                                'file',
184
                                'targets',
185
                                'username',
186
                                'password',
187
                                'no-auth-cache',
188
                                'no_auth_cache',
189
                                'non-interactive',
190
                                'non_interactive',
191
                                'force',
192
                                'encoding',
193
                                'config-dir'
194
                                );
195
 
196
    /**
197
     * Command-line arguments that should be passed
198
     * <b>outside</b> of those specified in {@link switches}.
199
     *
200
     * @var     array
201
     * @access  public
202
     */
203
    var $args = array();
204
 
205
    /**
206
     * Minimum number of args required by this subcommand.
207
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
208
     * Subversion Complete Reference for details on arguments for this subcommand.
209
     * @var     int
210
     * @access  public
211
     */
212
    var $min_args = 3;
213
 
214
    /**
215
     * Switches required by this subcommand.
216
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
217
     * Subversion Complete Reference for details on arguments for this subcommand.
218
     * @var     array
219
     * @access  public
220
     */
221
    var $required_switches = array();
222
 
223
    /**
224
     * Use exec or passthru to get results from command.
225
     * @var     bool
226
     * @access  public
227
     */
228
    var $passthru = false;
229
 
230
    /**
231
     * Prepare the svn subcommand switches.
232
     *
233
     * Defaults to non-interactive mode, and will auto-set the
234
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
235
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
236
     *
237
     * @param   void
238
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
239
     *                 for error details, if any.
240
     */
241
    function prepare()
242
    {
243
        $meets_requirements = $this->checkCommandRequirements();
244
        if (!$meets_requirements) {
245
            return false;
246
        }
247
 
248
        $valid_switches     = $this->valid_switches;
249
        $switches           = $this->switches;
250
        $args               = $this->args;
251
        $fetchmode          = $this->fetchmode;
252
        $invalid_switches   = array();
253
        $_switches          = '';
254
 
255
        foreach ($switches as $switch => $val) {
256
            if (in_array($switch, $valid_switches)) {
257
                $switch = str_replace('_', '-', $switch);
258
                switch ($switch) {
259
                    case 'revision':
260
                    case 'username':
261
                    case 'password':
262
                    case 'file':
263
                    case 'config-dir':
264
                    case 'targets':
265
                        $_switches .= "--$switch $val ";
266
                        break;
267
                    case 'r':
268
                    case 'F':
269
                        $_switches .= "-$switch $val ";
270
                        break;
271
                    case 'force':
272
                    case 'revprop':
273
                    case 'non-interactive':
274
                    case 'recursive':
275
                    case 'no-auth-cache':
276
                        if ($val === true) {
277
                            $_switches .= "--$switch ";
278
                        }
279
                        break;
280
                    case 'R':
281
                    case 'q':
282
                        if ($val === true) {
283
                            $_switches .= "-$switch ";
284
                        }
285
                        break;
286
                    default:
287
                        // that's all, folks!
288
                        break;
289
                }
290
            } else {
291
                $invalid_switches[] = $switch;
292
            }
293
        }
294
 
295
        $_switches = trim($_switches);
296
        $this->_switches = $_switches;
297
 
298
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
299
        if (!empty($args)) {
300
            $cmd .= ' '. join(' ', $args);
301
        }
302
 
303
        $this->_prepped_cmd = $cmd;
304
        $this->prepared = true;
305
 
306
        $invalid = count($invalid_switches);
307
        if ($invalid > 0) {
308
            $params['was'] = 'was';
309
            $params['is_invalid_switch'] = 'is an invalid switch';
310
            if ($invalid > 1) {
311
                $params['was'] = 'were';
312
                $params['is_invalid_switch'] = 'are invalid switches';
313
            }
314
            $params['list'] = $invalid_switches;
315
            $params['switches'] = $switches;
316
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
317
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
318
        }
319
        return true;
320
    }
321
 
322
    // }}}
323
    // {{{ parseOutput()
324
 
325
    /**
326
     * Handles output parsing of standard and verbose output of command.
327
     *
328
     * @param   array   $out    Array of output captured by exec command in {@link run}.
329
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
330
     *                  if desired fetchmode is not available.
331
     * @access  public
332
     */
333
    function parseOutput($out)
334
    {
335
        $fetchmode = $this->fetchmode;
336
        switch($fetchmode) {
337
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
338
                return join("\n", $out);
339
                break;
340
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
341
                // Temporary, see parseOutputArray below
342
                return join("\n", $out);
343
                break;
344
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
345
                // Temporary, will return object-ified array from
346
                // parseOutputArray
347
                return join("\n", $out);
348
                break;
349
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
350
                // Temporary, will eventually build an XML string
351
                // with XML_Util or XML_Tree
352
                return join("\n", $out);
353
                break;
354
            default:
355
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
356
                return join("\n", $out);
357
                break;
358
        }
359
    }
360
 
361
    /**
362
     * Helper method for parseOutput that parses output into an associative array
363
     *
364
     * @todo Finish this method! : )
365
     */
366
    function parseOutputArray($out)
367
    {
368
        $parsed = array();
369
    }
370
}
371
 
372
// }}}
373
?>