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: Info.php 286756 2009-08-03 20:02:16Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Info command manager class
55
 *
56
 * Display information about a file or directory in PATH.
57
 *
58
 * If the 'path' option is omitted, '.' is assumed.
59
 *
60
 * $switches is an array containing one or more command line options
61
 * defined by the following associative keys:
62
 *
63
 * <code>
64
 *
65
 * $switches = array(
66
 *  'targets'       =>  'ARG',
67
 *                      // passes contents of file ARG as additional arguments
68
 *  'R'             =>  true|false,
69
 *                      // descend recursively
70
 *  'recursive'     =>  true|false,
71
 *                      // descend recursively
72
 *  'config-dir'    =>  'Path to a Subversion configuration directory',
73
 *
74
 *  'username'      =>  'username for accessing repository',
75
 *
76
 *  'password'      =>  'password for accessing repository'
77
 * );
78
 *
79
 * </code>
80
 *
81
 * Usage example:
82
 * <code>
83
 * <?php
84
 * require_once 'VersionControl/SVN.php';
85
 *
86
 * // Setup error handling -- always a good idea!
87
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
88
 *
89
 * // Set up runtime options. Will be passed to all
90
 * // subclasses.
91
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
92
 *
93
 * // Pass array of subcommands we need to factory
94
 * $svn = VersionControl_SVN::factory(array('info'), $options);
95
 *
96
 * // Define any switches and aguments we may need
97
 * $switches = array('R' => true);
98
 * $args = array('/path/to/working_copy');
99
 *
100
 * // Run command
101
 * if ($output = $svn->info->run($args, $switches)) {
102
 *     print_r($output);
103
 * } else {
104
 *     if (count($errs = $svnstack->getErrors())) {
105
 *         foreach ($errs as $err) {
106
 *             echo '<br />'.$err['message']."<br />\n";
107
 *             echo "Command used: " . $err['params']['cmd'];
108
 *         }
109
 *     }
110
 * }
111
 * ?>
112
 * </code>
113
 *
114
 * Note: Subversion does not offer an XML output option for this subcommand
115
 *
116
 * @package  VersionControl_SVN
117
 * @version  0.3.4
118
 * @category SCM
119
 * @author   Clay Loveless <clay@killersoft.com>
120
 */
121
class VersionControl_SVN_Info extends VersionControl_SVN
122
{
123
    /**
124
     * Valid switches for svn info
125
     *
126
     * @var     array
127
     * @access  public
128
     */
129
    var $valid_switches = array('R',
130
                                'recursive',
131
                                'targets',
132
                                'config-dir',
133
                                'config_dir',
134
                                'username',
135
                                'password'
136
                                );
137
 
138
 
139
    /**
140
     * Command-line arguments that should be passed
141
     * <b>outside</b> of those specified in {@link switches}.
142
     *
143
     * @var     array
144
     * @access  public
145
     */
146
    var $args = array();
147
 
148
    /**
149
     * Minimum number of args required by this subcommand.
150
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
151
     * Subversion Complete Reference for details on arguments for this subcommand.
152
     * @var     int
153
     * @access  public
154
     */
155
    var $min_args = 0;
156
 
157
    /**
158
     * Switches required by this subcommand.
159
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
160
     * Subversion Complete Reference for details on arguments for this subcommand.
161
     * @var     array
162
     * @access  public
163
     */
164
    var $required_switches = array();
165
 
166
    /**
167
     * Use exec or passthru to get results from command.
168
     * @var     bool
169
     * @access  public
170
     */
171
    var $passthru = false;
172
 
173
    /**
174
     * Prepare the svn subcommand switches.
175
     *
176
     * Defaults to non-interactive mode, and will auto-set the
177
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
178
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
179
     *
180
     * @param   void
181
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
182
     *                 for error details, if any.
183
     */
184
    function prepare()
185
    {
186
        $meets_requirements = $this->checkCommandRequirements();
187
        if (!$meets_requirements) {
188
            return false;
189
        }
190
 
191
        $valid_switches     = $this->valid_switches;
192
        $switches           = $this->switches;
193
        $args               = $this->args;
194
        $fetchmode          = $this->fetchmode;
195
        $invalid_switches   = array();
196
        $_switches          = '';
197
 
198
        foreach ($switches as $switch => $val) {
199
            if (in_array($switch, $valid_switches)) {
200
                $switch = str_replace('_', '-', $switch);
201
                switch ($switch) {
202
                    case 'targets':
203
                    case 'username':
204
                    case 'password':
205
                    case 'config-dir':
206
                        $_switches .= "--$switch $val ";
207
                        break;
208
                    case 'recursive':
209
                        if ($val === true) {
210
                            $_switches .= "--$switch ";
211
                        }
212
                        break;
213
                    case 'R':
214
                        if ($val === true) {
215
                            $_switches .= "-$switch ";
216
                        }
217
                        break;
218
                    default:
219
                        // that's all, folks!
220
                        break;
221
                }
222
            } else {
223
                $invalid_switches[] = $switch;
224
            }
225
        }
226
 
227
        $_switches = trim($_switches);
228
        $this->_switches = $_switches;
229
 
230
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
231
        if (!empty($args)) {
232
            $cmd .= ' '. join(' ', $args);
233
        }
234
 
235
        $this->_prepped_cmd = $cmd;
236
        $this->prepared = true;
237
 
238
        $invalid = count($invalid_switches);
239
        if ($invalid > 0) {
240
            $params['was'] = 'was';
241
            $params['is_invalid_switch'] = 'is an invalid switch';
242
            if ($invalid > 1) {
243
                $params['was'] = 'were';
244
                $params['is_invalid_switch'] = 'are invalid switches';
245
            }
246
            $params['list'] = $invalid_switches;
247
            $params['switches'] = $switches;
248
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
249
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
250
        }
251
        return true;
252
    }
253
 
254
    // }}}
255
    // {{{ parseOutput()
256
 
257
    /**
258
     * Handles output parsing of standard and verbose output of command.
259
     *
260
     * @param   array   $out    Array of output captured by exec command in {@link run}.
261
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
262
     *                  if desired fetchmode is not available.
263
     * @access  public
264
     */
265
    function parseOutput($out)
266
    {
267
        $fetchmode = $this->fetchmode;
268
        switch($fetchmode) {
269
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
270
                return join("\n", $out);
271
                break;
272
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
273
                // Temporary, see parseOutputArray below
274
                return join("\n", $out);
275
                break;
276
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
277
                // Temporary, will return object-ified array from
278
                // parseOutputArray
279
                return join("\n", $out);
280
                break;
281
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
282
                // Temporary, will eventually build an XML string
283
                // with XML_Util or XML_Tree
284
                return join("\n", $out);
285
                break;
286
            default:
287
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
288
                return join("\n", $out);
289
                break;
290
        }
291
    }
292
 
293
    /**
294
     * Helper method for parseOutput that parses output into an associative array
295
     *
296
     * @todo Finish this method! : )
297
     */
298
    function parseOutputArray($out)
299
    {
300
        $parsed = array();
301
    }
302
}
303
 
304
/// }}}
305
?>