PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/xampp/php/PEAR/VersionControl/SVN/Move.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site
PHP | 364 lines | 133 code | 17 blank | 214 comment | 9 complexity | 924bb1dc21aa1618ba94bc6bc3b1e679 MD5 | raw file
  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: Move.php 12 2007-09-17 20:20:11Z killersoft $
  45. //
  46. /**
  47. * @package VersionControl_SVN
  48. * @category VersionControl
  49. * @author Clay Loveless <clay@killersoft.com>
  50. */
  51. /**
  52. * Subversion Move command manager class
  53. *
  54. * Move and/or rename something in working copy or repository.
  55. *
  56. * Note: this subcommand is equivalent to a 'copy' and 'delete'.
  57. *
  58. * SRC and DST can both be working copy (WC) paths or URLs:
  59. * WC -> WC: move and schedule for addition (with history)
  60. * URL -> URL: complete server-side rename.
  61. *
  62. * Copies must include a message option (either with 'm', 'message', 'file' or 'F'
  63. * keys), but the message itself may be blank.
  64. *
  65. * $switches is an array containing one or more command line options
  66. * defined by the following associative keys:
  67. *
  68. * <code>
  69. *
  70. * $switches = array(
  71. * 'm [message]' => 'Specified commit message',
  72. * // either 'm' or 'message' may be used
  73. * 'F [file]' => 'Read commit message data from specified file',
  74. * // either 'F' or 'file' may be used
  75. * 'q [quiet]' => true|false,
  76. * // prints as little as possible
  77. * 'force' => true|false,
  78. * // force operation to run
  79. * 'r [revision]' => 'ARG (some commands also take ARG1:ARG2 range)
  80. * A revision argument can be one of:
  81. * NUMBER revision number
  82. * "{" DATE "}" revision at start of the date
  83. * "HEAD" latest in repository
  84. * "BASE" base rev of item's working copy
  85. * "COMMITTED" last commit at or before BASE
  86. * "PREV" revision just before COMMITTED',
  87. * // either 'r' or 'revision' may be used
  88. * 'force-log' => true|false,
  89. * // force validity of log message source
  90. * 'username' => 'Subversion repository login',
  91. * 'password' => 'Subversion repository password',
  92. * 'no-auth-cache' => true|false,
  93. * // Do not cache authentication tokens
  94. * 'encoding' => 'ARG',
  95. * // treat value as being in charset encoding ARG
  96. * 'config-dir' => 'Path to a Subversion configuration directory'
  97. * );
  98. *
  99. * </code>
  100. *
  101. * Note: Subversion does not offer an XML output option for this subcommand
  102. *
  103. * The non-interactive option available on the command-line
  104. * svn client may also be set (true|false), but it is set to true by default.
  105. *
  106. * The editor-cmd option available on the command-line svn client is not available
  107. * since this class does not operate as an interactive shell session.
  108. *
  109. * Usage example:
  110. * <code>
  111. * <?php
  112. * require_once 'VersionControl/SVN.php';
  113. *
  114. * // Setup error handling -- always a good idea!
  115. * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
  116. *
  117. * // Set up runtime options. Will be passed to all
  118. * // subclasses.
  119. * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
  120. *
  121. * // Pass array of subcommands we need to factory
  122. * $svn = VersionControl_SVN::factory(array('move'), $options);
  123. *
  124. * // Define any switches and aguments we may need
  125. * $switches = array('m' => 'Whoops! How did this get here?', 'username' => 'user', 'password' => 'pass');
  126. * $args = array(
  127. * 'svn://svn.example.com/repos/TestProj/trunk/somedir', // SRC
  128. * 'svn://svn.example.com/repos/TestProj/trunk/lowerlevel/somedir' // DST
  129. * );
  130. *
  131. * // Run command
  132. * if ($output = $svn->move->run($args, $switches)) {
  133. * print_r($output);
  134. * } else {
  135. * if (count($errs = $svnstack->getErrors())) {
  136. * foreach ($errs as $err) {
  137. * echo '<br />'.$err['message']."<br />\n";
  138. * echo "Command used: " . $err['params']['cmd'];
  139. * }
  140. * }
  141. * }
  142. * ?>
  143. * </code>
  144. *
  145. * @package VersionControl_SVN
  146. * @version 0.3.1
  147. * @category SCM
  148. * @author Clay Loveless <clay@killersoft.com>
  149. */
  150. class VersionControl_SVN_Move extends VersionControl_SVN
  151. {
  152. /**
  153. * Valid switches for svn move
  154. *
  155. * @var array
  156. * @access public
  157. */
  158. var $valid_switches = array('m',
  159. 'message',
  160. 'F',
  161. 'file',
  162. 'r',
  163. 'revision',
  164. 'q',
  165. 'quiet',
  166. 'force',
  167. 'username',
  168. 'password',
  169. 'no-auth-cache',
  170. 'no_auth_cache',
  171. 'non-interactive',
  172. 'non_interactive',
  173. 'config-dir',
  174. 'config_dir',
  175. 'encoding',
  176. 'force-log',
  177. 'force_log'
  178. );
  179. /**
  180. * Command-line arguments that should be passed
  181. * <b>outside</b> of those specified in {@link switches}.
  182. *
  183. * @var array
  184. * @access public
  185. */
  186. var $args = array();
  187. /**
  188. * Minimum number of args required by this subcommand.
  189. * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
  190. * Subversion Complete Reference for details on arguments for this subcommand.
  191. * @var int
  192. * @access public
  193. */
  194. var $min_args = 2;
  195. /**
  196. * Switches required by this subcommand.
  197. * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
  198. * Subversion Complete Reference for details on arguments for this subcommand.
  199. * @var array
  200. * @access public
  201. */
  202. var $required_switches = array('m|message|F|file');
  203. /**
  204. * Use exec or passthru to get results from command.
  205. * @var bool
  206. * @access public
  207. */
  208. var $passthru = false;
  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. $valid_switches = $this->valid_switches;
  227. $switches = $this->switches;
  228. $args = $this->args;
  229. $fetchmode = $this->fetchmode;
  230. $invalid_switches = array();
  231. $_switches = '';
  232. foreach ($switches as $switch => $val) {
  233. if (in_array($switch, $valid_switches)) {
  234. $switch = str_replace('_', '-', $switch);
  235. switch ($switch) {
  236. case 'revision':
  237. case 'username':
  238. case 'password':
  239. case 'encoding':
  240. case 'config-dir':
  241. $_switches .= "--$switch $val ";
  242. break;
  243. case 'r':
  244. $_switches .= "-$switch $val ";
  245. break;
  246. case 'F':
  247. case 'm':
  248. $_switches .= "-$switch \"$val\" ";
  249. break;
  250. case 'file':
  251. case 'message':
  252. $_switches .= "--$switch \"$val\" ";
  253. break;
  254. case 'quiet':
  255. case 'force':
  256. case 'non-interactive':
  257. case 'force-log':
  258. case 'no-auth-cache':
  259. if ($val === true) {
  260. $_switches .= "--$switch ";
  261. }
  262. break;
  263. case 'q':
  264. if ($val === true) {
  265. $_switches .= "-$switch ";
  266. }
  267. break;
  268. default:
  269. // that's all, folks!
  270. break;
  271. }
  272. } else {
  273. $invalid_switches[] = $switch;
  274. }
  275. }
  276. $_switches = trim($_switches);
  277. $this->_switches = $_switches;
  278. $cmd = "$this->svn_path $this->_svn_cmd $_switches";
  279. if (!empty($args)) {
  280. $cmd .= ' '. join(' ', $args);
  281. }
  282. $this->_prepped_cmd = $cmd;
  283. $this->prepared = true;
  284. $invalid = count($invalid_switches);
  285. if ($invalid > 0) {
  286. $params['was'] = 'was';
  287. $params['is_invalid_switch'] = 'is an invalid switch';
  288. if ($invalid > 1) {
  289. $params['was'] = 'were';
  290. $params['is_invalid_switch'] = 'are invalid switches';
  291. }
  292. $params['list'] = $invalid_switches;
  293. $params['switches'] = $switches;
  294. $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
  295. $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
  296. }
  297. return true;
  298. }
  299. // }}}
  300. // {{{ parseOutput()
  301. /**
  302. * Handles output parsing of standard and verbose output of command.
  303. *
  304. * @param array $out Array of output captured by exec command in {@link run}.
  305. * @return mixed Returns output requested by fetchmode (if available), or raw output
  306. * if desired fetchmode is not available.
  307. * @access public
  308. */
  309. function parseOutput($out)
  310. {
  311. $fetchmode = $this->fetchmode;
  312. switch($fetchmode) {
  313. case VERSIONCONTROL_SVN_FETCHMODE_RAW:
  314. return join("\n", $out);
  315. break;
  316. case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
  317. // Temporary, see parseOutputArray below
  318. return join("\n", $out);
  319. break;
  320. case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
  321. // Temporary, will return object-ified array from
  322. // parseOutputArray
  323. return join("\n", $out);
  324. break;
  325. case VERSIONCONTROL_SVN_FETCHMODE_XML:
  326. // Temporary, will eventually build an XML string
  327. // with XML_Util or XML_Tree
  328. return join("\n", $out);
  329. break;
  330. default:
  331. // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
  332. return join("\n", $out);
  333. break;
  334. }
  335. }
  336. /**
  337. * Helper method for parseOutput that parses output into an associative array
  338. *
  339. * @todo Finish this method! : )
  340. */
  341. function parseOutputArray($out)
  342. {
  343. $parsed = array();
  344. }
  345. }
  346. // }}}
  347. ?>