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