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: Proplist.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 Proplist command manager class
55
 *
56
 * List all properties on 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
 *  'v [verbose]'   =>  true|false,
65
 *                      // prints extra information
66
 *  'R'             =>  true|false,
67
 *                      // descend recursively
68
 *  'recursive'     =>  true|false,
69
 *                      // descend recursively
70
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
71
 *                        A revision argument can be one of:
72
 *                           NUMBER       revision number
73
 *                           "{" DATE "}" revision at start of the date
74
 *                           "HEAD"       latest in repository
75
 *                           "BASE"       base rev of item's working copy
76
 *                           "COMMITTED"  last commit at or before BASE
77
 *                           "PREV"       revision just before COMMITTED',
78
 *                      // either 'r' or 'revision' may be used
79
 *  'q [quiet]'     =>  true|false,
80
 *                      // prints as little as possible
81
 *  'revprop'       =>  true|false,
82
 *                      // operate on a revision property (use with r)
83
 *  'username'      =>  'Subversion repository login',
84
 *  'password'      =>  'Subversion repository password',
85
 *  'no-auth-cache' =>  true|false,
86
 *                      // Do not cache authentication tokens
87
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
88
 * );
89
 *
90
 * </code>
91
 *
92
 * Note: Subversion does not offer an XML output option for this subcommand
93
 *
94
 * The non-interactive option available on the command-line
95
 * svn client may also be set (true|false), but it is set to true by default.
96
 *
97
 * Usage example:
98
 * <code>
99
 * <?php
100
 * require_once 'VersionControl/SVN.php';
101
 *
102
 * // Setup error handling -- always a good idea!
103
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
104
 *
105
 * // Set up runtime options. Will be passed to all
106
 * // subclasses.
107
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
108
 *
109
 * // Pass array of subcommands we need to factory
110
 * $svn = VersionControl_SVN::factory(array('proplist'), $options);
111
 *
112
 * // Define any switches and aguments we may need
113
 * $switches = array('revprop' => true, 'r' => '17', 'username' => 'user', 'password' => 'pass');
114
 * $args = array('svn://svn.example.com/repos/TestProj/trunk');
115
 *
116
 * // Run command
117
 * if ($output = $svn->proplist->run($args, $switches)) {
118
 *     print_r($output);
119
 * } else {
120
 *     if (count($errs = $svnstack->getErrors())) {
121
 *         foreach ($errs as $err) {
122
 *             echo '<br />'.$err['message']."<br />\n";
123
 *             echo "Command used: " . $err['params']['cmd'];
124
 *         }
125
 *     }
126
 * }
127
 * ?>
128
 * </code>
129
 *
130
 * @package  VersionControl_SVN
131
 * @version  0.3.4
132
 * @category SCM
133
 * @author   Clay Loveless <clay@killersoft.com>
134
 */
135
class VersionControl_SVN_Proplist extends VersionControl_SVN
136
{
137
    /**
138
     * Valid switches for svn proplist
139
     *
140
     * @var     array
141
     * @access  public
142
     */
143
    var $valid_switches = array('r',
144
                                'revision',
145
                                'revprop',
146
                                'R',
147
                                'recursive',
148
                                'verbose',
149
                                'v',
150
                                'quiet',
151
                                'q',
152
                                'username',
153
                                'password',
154
                                'no-auth-cache',
155
                                'no_auth_cache',
156
                                'non-interactive',
157
                                'non_interactive',
158
                                'config-dir'
159
                                );
160
 
161
    /**
162
     * Command-line arguments that should be passed
163
     * <b>outside</b> of those specified in {@link switches}.
164
     *
165
     * @var     array
166
     * @access  public
167
     */
168
    var $args = array();
169
 
170
    /**
171
     * Minimum number of args required by this subcommand.
172
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
173
     * Subversion Complete Reference for details on arguments for this subcommand.
174
     * @var     int
175
     * @access  public
176
     */
177
    var $min_args = 0;
178
 
179
    /**
180
     * Switches required by this subcommand.
181
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
182
     * Subversion Complete Reference for details on arguments for this subcommand.
183
     * @var     array
184
     * @access  public
185
     */
186
    var $required_switches = array();
187
 
188
    /**
189
     * Use exec or passthru to get results from command.
190
     * @var     bool
191
     * @access  public
192
     */
193
    var $passthru = false;
194
 
195
    /**
196
     * Prepare the svn subcommand switches.
197
     *
198
     * Defaults to non-interactive mode, and will auto-set the
199
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
200
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
201
     *
202
     * @param   void
203
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
204
     *                 for error details, if any.
205
     */
206
    function prepare()
207
    {
208
        $meets_requirements = $this->checkCommandRequirements();
209
        if (!$meets_requirements) {
210
            return false;
211
        }
212
 
213
        $valid_switches     = $this->valid_switches;
214
        $switches           = $this->switches;
215
        $args               = $this->args;
216
        $fetchmode          = $this->fetchmode;
217
        $invalid_switches   = array();
218
        $_switches          = '';
219
 
220
        foreach ($switches as $switch => $val) {
221
            if (in_array($switch, $valid_switches)) {
222
                $switch = str_replace('_', '-', $switch);
223
                switch ($switch) {
224
                    case 'revision':
225
                    case 'username':
226
                    case 'password':
227
                    case 'config-dir':
228
                        $_switches .= "--$switch $val ";
229
                        break;
230
                    case 'r':
231
                        $_switches .= "-$switch $val ";
232
                        break;
233
                    case 'revprop':
234
                    case 'non-interactive':
235
                    case 'recursive':
236
                    case 'verbose':
237
                    case 'quiet':
238
                    case 'no-auth-cache':
239
                        if ($val === true) {
240
                            $_switches .= "--$switch ";
241
                        }
242
                        break;
243
                    case 'R':
244
                    case 'v':
245
                    case 'q':
246
                        if ($val === true) {
247
                            $_switches .= "-$switch ";
248
                        }
249
                        break;
250
                    default:
251
                        // that's all, folks!
252
                        break;
253
                }
254
            } else {
255
                $invalid_switches[] = $switch;
256
            }
257
        }
258
 
259
        $_switches = trim($_switches);
260
        $this->_switches = $_switches;
261
 
262
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
263
        if (!empty($args)) {
264
            $cmd .= ' '. join(' ', $args);
265
        }
266
 
267
        $this->_prepped_cmd = $cmd;
268
        $this->prepared = true;
269
 
270
        $invalid = count($invalid_switches);
271
        if ($invalid > 0) {
272
            $params['was'] = 'was';
273
            $params['is_invalid_switch'] = 'is an invalid switch';
274
            if ($invalid > 1) {
275
                $params['was'] = 'were';
276
                $params['is_invalid_switch'] = 'are invalid switches';
277
            }
278
            $params['list'] = $invalid_switches;
279
            $params['switches'] = $switches;
280
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
281
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
282
        }
283
        return true;
284
    }
285
 
286
    // }}}
287
    // {{{ parseOutput()
288
 
289
    /**
290
     * Handles output parsing of standard and verbose output of command.
291
     *
292
     * @param   array   $out    Array of output captured by exec command in {@link run}.
293
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
294
     *                  if desired fetchmode is not available.
295
     * @access  public
296
     */
297
    function parseOutput($out)
298
    {
299
        $fetchmode = $this->fetchmode;
300
        switch($fetchmode) {
301
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
302
                return join("\n", $out);
303
                break;
304
            case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
305
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
306
                // Temporary, see parseOutputArray below
307
                return join("\n", $out);
308
                break;
309
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
310
                // Temporary, will return object-ified array from
311
                // parseOutputArray
312
                return join("\n", $out);
313
                break;
314
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
315
                // Temporary, will eventually build an XML string
316
                // with XML_Util or XML_Tree
317
                return join("\n", $out);
318
                break;
319
            default:
320
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
321
                return join("\n", $out);
322
                break;
323
        }
324
    }
325
 
326
    /**
327
     * Helper method for parseOutput that parses output into an associative array
328
     *
329
     * @todo Finish this method! : )
330
     */
331
    function parseOutputArray($out)
332
    {
333
        $parsed = array();
334
    }
335
}
336
 
337
// }}}
338
?>