PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/pear/VersionControl/SVN/Mkdir.php

http://akelosframework.googlecode.com/
PHP | 345 lines | 124 code | 16 blank | 205 comment | 9 complexity | 6980ed3a874477de522bdd3469105481 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 5 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2004, 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: Mkdir.php 42 2004-04-26 09:39:59Z clay $
  45. //
  46. /**
  47. * @package VersionControl_SVN
  48. * @category VersionControl
  49. * @author Clay Loveless <clay@killersoft.com>
  50. */
  51. /**
  52. * Subversion Mkdir command manager class
  53. *
  54. * Create a new directory under version control.
  55. *
  56. * From svn mkdir --help:
  57. *
  58. * usage: 1. mkdir PATH...
  59. * 2. mkdir URL...
  60. *
  61. * Create version controlled directories.
  62. *
  63. * 1. Each directory specified by a working copy PATH is created locally
  64. * and scheduled for addition upon the next commit.
  65. *
  66. * 2. Each directory specified by a URL is created in the repository via
  67. * an immediate commit.
  68. *
  69. * In both cases, all the intermediate directories must already exist.
  70. *
  71. * New directories must include a message option
  72. * (either with 'm', 'message', 'file' or 'F' keys), when the directory is
  73. * created directly in the repository, as that results in an immediate commit.
  74. *
  75. * $switches is an array containing one or more command line options
  76. * defined by the following associative keys:
  77. *
  78. * <code>
  79. *
  80. * $switches = array(
  81. * 'm [message]' => 'Specified commit message',
  82. * // either 'm' or 'message' may be used
  83. * 'F [file]' => 'Read commit message data from specified file',
  84. * // either 'F' or 'file' may be used
  85. * 'q [quiet]' => true|false,
  86. * // prints as little as possible
  87. * 'force-log' => true|false,
  88. * // force validity of log message source
  89. * 'username' => 'Subversion repository login',
  90. * 'password' => 'Subversion repository password',
  91. * 'no-auth-cache' => true|false,
  92. * // Do not cache authentication tokens
  93. * 'encoding' => 'ARG',
  94. * // treat value as being in charset encoding ARG
  95. * 'config-dir' => 'Path to a Subversion configuration directory'
  96. * );
  97. *
  98. * </code>
  99. *
  100. * Note: Subversion does not offer an XML output option for this subcommand
  101. *
  102. * The non-interactive option available on the command-line
  103. * svn client may also be set (true|false), but it is set to true by default.
  104. *
  105. * The editor-cmd option available on the command-line svn client is not available
  106. * since this class does not operate as an interactive shell session.
  107. *
  108. * Usage example:
  109. * <code>
  110. * <?php
  111. * require_once 'VersionControl/SVN.php';
  112. *
  113. * // Setup error handling -- always a good idea!
  114. * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
  115. *
  116. * // Set up runtime options. Will be passed to all
  117. * // subclasses.
  118. * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
  119. *
  120. * // Pass array of subcommands we need to factory
  121. * $svn = VersionControl_SVN::factory(array('mkdir'), $options);
  122. *
  123. * // Define any switches and aguments we may need
  124. * $switches = array('m' => 'Let\'s make a hole here ...', 'username' => 'user', 'password' => 'pass');
  125. * $args = array('svn://svn.example.com/repos/TestProj/trunk/newdir');
  126. *
  127. * // Run command
  128. * if ($output = $svn->mkdir->run($args, $switches)) {
  129. * print_r($output);
  130. * } else {
  131. * if (count($errs = $svnstack->getErrors())) {
  132. * foreach ($errs as $err) {
  133. * echo '<br />'.$err['message']."<br />\n";
  134. * echo "Command used: " . $err['params']['cmd'];
  135. * }
  136. * }
  137. * }
  138. * ?>
  139. * </code>
  140. *
  141. * @package VersionControl_SVN
  142. * @version @version@
  143. * @category SCM
  144. * @author Clay Loveless <clay@killersoft.com>
  145. */
  146. class VersionControl_SVN_Mkdir extends VersionControl_SVN
  147. {
  148. /**
  149. * Valid switches for svn mkdir
  150. *
  151. * @var array
  152. * @access public
  153. */
  154. var $valid_switches = array('m',
  155. 'message',
  156. 'q',
  157. 'quiet',
  158. 'F',
  159. 'file',
  160. 'username',
  161. 'password',
  162. 'no-auth-cache',
  163. 'no_auth_cache',
  164. 'non-interactive',
  165. 'non_interactive',
  166. 'config-dir',
  167. 'config_dir',
  168. 'encoding',
  169. 'force-log',
  170. 'force_log'
  171. );
  172. /**
  173. * Command-line arguments that should be passed
  174. * <b>outside</b> of those specified in {@link switches}.
  175. *
  176. * @var array
  177. * @access public
  178. */
  179. var $args = array();
  180. /**
  181. * Minimum number of args required by this subcommand.
  182. * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
  183. * Subversion Complete Reference for details on arguments for this subcommand.
  184. * @var int
  185. * @access public
  186. */
  187. var $min_args = 1;
  188. /**
  189. * Switches required by this subcommand.
  190. * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
  191. * Subversion Complete Reference for details on arguments for this subcommand.
  192. * @var array
  193. * @access public
  194. */
  195. var $required_switches = array('m|message|F|file');
  196. /**
  197. * Prepare the svn subcommand switches.
  198. *
  199. * Defaults to non-interactive mode, and will auto-set the
  200. * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
  201. * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
  202. *
  203. * @param void
  204. * @return int true on success, false on failure. Check PEAR_ErrorStack
  205. * for error details, if any.
  206. */
  207. function prepare()
  208. {
  209. $meets_requirements = $this->checkCommandRequirements();
  210. if (!$meets_requirements) {
  211. return false;
  212. }
  213. $valid_switches = $this->valid_switches;
  214. $switches = $this->switches;
  215. $args = $this->args;
  216. $fetchmode = $this->fetchmode;
  217. $invalid_switches = array();
  218. $_switches = '';
  219. foreach ($switches as $switch => $val) {
  220. if (in_array($switch, $valid_switches)) {
  221. $switch = str_replace('_', '-', $switch);
  222. switch ($switch) {
  223. case 'username':
  224. case 'password':
  225. case 'encoding':
  226. case 'config-dir':
  227. $_switches .= "--$switch $val ";
  228. break;
  229. case 'F':
  230. case 'm':
  231. $_switches .= "-$switch \"$val\" ";
  232. break;
  233. case 'file':
  234. case 'message':
  235. $_switches .= "--$switch \"$val\" ";
  236. break;
  237. case 'quiet':
  238. case 'non-interactive':
  239. case 'force-log':
  240. case 'no-auth-cache':
  241. if ($val === true) {
  242. $_switches .= "--$switch ";
  243. }
  244. break;
  245. case 'q':
  246. if ($val === true) {
  247. $_switches .= "-$switch ";
  248. }
  249. break;
  250. default:
  251. // that's all, folks!
  252. break;
  253. }
  254. } else {
  255. $invalid_switches[] = $switch;
  256. }
  257. }
  258. $_switches = trim($_switches);
  259. $this->_switches = $_switches;
  260. $cmd = "$this->svn_path $this->_svn_cmd $_switches";
  261. if (!empty($args)) {
  262. $cmd .= ' '. join(' ', $args);
  263. }
  264. $this->_prepped_cmd = $cmd;
  265. $this->prepared = true;
  266. $invalid = count($invalid_switches);
  267. if ($invalid > 0) {
  268. $params['was'] = 'was';
  269. $params['is_invalid_switch'] = 'is an invalid switch';
  270. if ($invalid > 1) {
  271. $params['was'] = 'were';
  272. $params['is_invalid_switch'] = 'are invalid switches';
  273. }
  274. $params['list'] = $invalid_switches;
  275. $params['switches'] = $switches;
  276. $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
  277. $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
  278. }
  279. return true;
  280. }
  281. // }}}
  282. // {{{ parseOutput()
  283. /**
  284. * Handles output parsing of standard and verbose output of command.
  285. *
  286. * @param array $out Array of output captured by exec command in {@link run}.
  287. * @return mixed Returns output requested by fetchmode (if available), or raw output
  288. * if desired fetchmode is not available.
  289. * @access public
  290. */
  291. function parseOutput($out)
  292. {
  293. $fetchmode = $this->fetchmode;
  294. switch($fetchmode) {
  295. case VERSIONCONTROL_SVN_FETCHMODE_RAW:
  296. return join("\n", $out);
  297. break;
  298. case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
  299. // Temporary, see parseOutputArray below
  300. return join("\n", $out);
  301. break;
  302. case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
  303. // Temporary, will return object-ified array from
  304. // parseOutputArray
  305. return join("\n", $out);
  306. break;
  307. case VERSIONCONTROL_SVN_FETCHMODE_XML:
  308. // Temporary, will eventually build an XML string
  309. // with XML_Util or XML_Tree
  310. return join("\n", $out);
  311. break;
  312. default:
  313. // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
  314. return join("\n", $out);
  315. break;
  316. }
  317. }
  318. /**
  319. * Helper method for parseOutput that parses output into an associative array
  320. *
  321. * @todo Finish this method! : )
  322. */
  323. function parseOutputArray($out)
  324. {
  325. $parsed = array();
  326. }
  327. }
  328. // }}}
  329. ?>