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