Source for file Command.php
Documentation is available at Command.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* VersionControl_SVN_Info allows for XML formatted output. XML_Parser is used to
* manipulate that output.
* +----------------------------------------------------------------------+
* | This LICENSE is in the BSD license style. |
* | http://www.opensource.org/licenses/bsd-license.php |
* | Redistribution and use in source and binary forms, with or without |
* | modification, are permitted provided that the following conditions |
* | * Redistributions of source code must retain the above copyright |
* | notice, this list of conditions and the following disclaimer. |
* | * Redistributions in binary form must reproduce the above |
* | copyright notice, this list of conditions and the following |
* | disclaimer in the documentation and/or other materials provided |
* | with the distribution. |
* | * Neither the name of Clay Loveless nor the names of contributors |
* | may be used to endorse or promote products derived from this |
* | software without specific prior written permission. |
* | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
* | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
* | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
* | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
* | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
* | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
* | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
* | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
* | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
* | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
* | POSSIBILITY OF SUCH DAMAGE. |
* +----------------------------------------------------------------------+
* @category VersionControl
* @package VersionControl_SVN
* @author Clay Loveless <clay@killersoft.com>
* @author Michiel Rook <mrook@php.net>
* @author Alexander Opitz <opitz.alexander@gmail.com>
* @copyright 2004-2007 Clay Loveless
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://pear.php.net/package/VersionControl_SVN
require_once 'VersionControl/SVN/Exception.php';
require_once 'System.php';
* Ground class for a SVN command.
* @category VersionControl
* @package VersionControl_SVN
* @author Clay Loveless <clay@killersoft.com>
* @author Michiel Rook <mrook@php.net>
* @author Alexander Opitz <opitz.alexander@gmail.com>
* @copyright 2004-2007 Clay Loveless
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://pear.php.net/package/VersionControl_SVN
* Indicates whether commands passed to the
* {@link http://www.php.net/exec exec()} function in the
* {@link run} method should be passed through
* {@link http://www.php.net/escapeshellcmd escapeshellcmd()}.
* NOTE: this variable is ignored on Windows machines!
* @var boolean $useEscapeshellcmd
* Use exec or passthru to get results from command.
* Location of the svn client binary installed as part of Subversion
* @var string $binaryPath
* Legacy / compatibility location of the svn client binary
* String to prepend to command string. Helpful for setting exec()
* environment variables, such as:
* export LANG=en_US.utf8 &&
* ... to support non-ASCII file and directory names.
* @var string $prependCmd
* Array of switches to use in building svn command
* Switches required by this subcommand.
* See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
* Subversion Complete Reference for details on arguments for this subcommand.
* @var array $requiredSwitches
* Runtime options being used.
* Command-line arguments that should be passed
* <b>outside</b> of those specified in {@link switches}.
* Minimum number of args required by this subcommand.
* See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
* Subversion Complete Reference for details on arguments for this subcommand.
* Preferred fetchmode. Note that not all subcommands have output available for
* each preferred fetchmode. The default cascade is:
* VERSIONCONTROL_SVN_FETCHMODE_ASSOC
* VERSIONCONTROL_SVN_FETCHMODE_RAW
* If the specified fetchmode isn't available, raw output will be returned.
public $fetchmode = VERSIONCONTROL_SVN_FETCHMODE_ASSOC;
* Default username to use for connections.
* Default password to use for connections.
* Default config-dir to use for connections.
* Default config-option to use for connections.
* @var string $configOption
* @var string $commandName
* Fully prepared command string.
* @var string $preparedCmd
* Keep track of whether XML output is available for a command
* Useable switches for command with parameters.
* Useable switches for command without parameters.
* Constructor. Can't be called directly as class is abstract.
* Allow for overriding of previously declared options.
* @param array $options An associative array of option names and
* @return VersionControl_SVN_Command Themself.
* @throws VersionControl_SVN_Exception If option isn't available.
$class = new ReflectionClass ($this);
foreach ($options as $option => $value) {
$property = $class->getProperty ($option);
} catch (ReflectionException $e) {
if (null !== $property && $property->isPublic ()) {
'"' . $option . '" is not a valid option',
* Prepare the command switches.
* This function should be overloaded by the command class.
* @throws VersionControl_SVN_Exception If preparing failed.
$invalidSwitches = array ();
foreach ($this->switches as $switch => $val) {
$cmdParts[] = $switchPrefix . $switch;
$invalidSwitches[] = $switch;
* Called after handling switches.
* @param array $invalidSwitches Invalid switches found while processing.
* @throws VersionControl_SVN_Exception If switch(s) is/are invalid.
$invalid = count($invalidSwitches);
$invalides = implode(',', $invalidSwitches);
$error = '"' . $invalides . '" are invalid switches';
$error = '"' . $invalides . '" is a invalid switch';
$error .= ' for class "' . get_class($this) . '".';
* Called before handling switches.
$this->switches['non-interactive'] = true;
protected function fillSwitch($switchName, $value)
if (!isset ($this->switches[$switchName])
* Standardized validation of requirements for a command class.
* @throws VersionControl_SVN_Exception If command requirements not resolved.
// Set up error push parameters to avoid any notices about undefined indexes
$params['options'] = $this->options;
$params['args'] = $this->args;
// Check for minimum arguments
'svn command requires at least ' . $this->minArgs . ' argument(s)',
// Check for presence of required switches
foreach ($reqsw as $req) {
$good_switches = explode('|', $req);
foreach ($good_switches as $gsw) {
if (isset ($switches[$gsw])) {
$missing[] = '('. $req. ')';
$num_missing = count($missing);
'svn command requires the following switch(es): ' . $missing,
* Run the command with the defined switches.
* @param array $args Arguments to pass to Subversion
* @param array $switches Switches to pass to Subversion
* @return mixed $fetchmode specified output on success.
* @throws VersionControl_SVN_Exception If command failed.
public function run($args = array (), $switches = array ())
// Always prepare, allows for obj re-use. (Request #5021)
// @var integer $returnVar Return number from shell execution.
// On Windows, don't use escapeshellcmd, and double-quote $cmd
// cmd /c ""C:\Program Files\SVN\bin\svn.exe" info "C:\Program Files\dev\trunk""
exec(" cmd /c \"$cmd 2>&1\"" , $out, $returnVar);
passthru(" cmd /c \"$cmd 2>&1\"" , $returnVar);
passthru("{ $this->prependCmd}$cmd 2>&1 ", $returnVar);
throw new VersionControl_SVN_Exception(
'Execution of command failed returning: ' . $returnVar
. "\n" . implode("\n", $out),
VersionControl_SVN_Exception::EXEC
* Handles output parsing of standard and verbose output of command.
* @param array $out Array of output captured by exec command in {@link run}
* @return mixed Returns output requested by fetchmode (if available), or
* raw output if desired fetchmode is not available.
public function parseOutput($out)
$dir = realpath(dirname(__FILE__)) . '/Parser/XML';
case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
$file = $dir . '/' . ucfirst($this->commandName) . '.php';
if (file_exists ($file)) {
$class = 'VersionControl_SVN_Parser_XML_'
$parsedData = $parser->getParsed (join ("\n", $out));
if ($this->fetchmode == VERSIONCONTROL_SVN_FETCHMODE_OBJECT ) {
return (object) $parsedData;
case VERSIONCONTROL_SVN_FETCHMODE_RAW:
case VERSIONCONTROL_SVN_FETCHMODE_XML:
// What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
Documentation generated on Sat, 09 Feb 2013 12:30:09 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|