We forgot to add includes/class_libsvn.php which makes all those previous commits...
[viewsvn.git] / includes / class_libsvn.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * LibSVN
24 *
25 * This is the command-line library system for Subversion. It handles all
26 * the actual lifting and executing.
27 *
28 * @author Blue Static
29 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
30 * @version $Revision$
31 * @package ViewSVN
32 *
33 */
34 class LibSVN
35 {
36 /**
37 * The path to the SVN binary
38 * @var string
39 */
40 private $path;
41
42 /**
43 * Constructor
44 */
45 public function __construct($path)
46 {
47 $this->path = $path;
48
49 $access = $this->run('--version');
50 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
51 {
52 throw new Exception(_('The SVN binary does not appear to be valid (it failed our tests)'));
53 }
54 }
55
56 // ###################################################################
57 /**
58 * Wrapper for escapeshellarg()
59 *
60 * @param string The argument
61 *
62 * @return string Cleaned argument
63 */
64 public function arg($argument)
65 {
66 return escapeshellarg($argument);
67 }
68
69 // ###################################################################
70 /**
71 * Wrapper for escapeshellcmd()
72 *
73 * @param string Command
74 *
75 * @return string Cleaned command
76 */
77 public function cmd($command)
78 {
79 return escapeshellcmd($command);
80 }
81
82 // ###################################################################
83 /**
84 * Executes a shell command and returns all the output
85 * as an array
86 *
87 * @param string UNIX command
88 * @param bool Turn the array of output into a string?
89 *
90 * @return array Output
91 */
92 public function run($command, $implode = false)
93 {
94 $start = microtime();
95
96 exec($this->path . ' ' . $command, $output);
97
98 BSRegister::Debug("exec(" . BSFunctions::FetchMicrotimeDiff($start) . "): $command");
99
100 if ($implode)
101 {
102 return implode("\n", $output);
103 }
104
105 return $output;
106 }
107 }
108
109 /*=====================================================================*\
110 || ###################################################################
111 || # $HeadURL$
112 || # $Id$
113 || ###################################################################
114 \*=====================================================================*/
115 ?>