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