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