Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 187 lines (179 sloc) 5.943 kB
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
1 <?php
2 /**
3 * This file is part of phpUnderControl.
de4b1c5 @manuelpichler - @category tag added.
manuelpichler authored
4 *
63462fc @manuelpichler - Minimum php version lowered from 5.2.4 to 5.2.0.
manuelpichler authored
5 * PHP Version 5.2.0
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
6 *
f6ab6b0 @manuelpichler - email address changed.
manuelpichler authored
7 * Copyright (c) 2007-2008, Manuel Pichler <mapi@phpundercontrol.org>.
cbbb1ac @manuelpichler - License changed to "New BSD"
manuelpichler authored
8 * All rights reserved.
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
9 *
cbbb1ac @manuelpichler - License changed to "New BSD"
manuelpichler authored
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
13 *
cbbb1ac @manuelpichler - License changed to "New BSD"
manuelpichler authored
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * * Neither the name of Manuel Pichler nor the names of his
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
de4b1c5 @manuelpichler - @category tag added.
manuelpichler authored
38 *
39 * @category QualityAssurance
438a68d @manuelpichler - Console stuff moved to it's own package.
manuelpichler authored
40 * @package Console
f6ab6b0 @manuelpichler - email address changed.
manuelpichler authored
41 * @author Manuel Pichler <mapi@phpundercontrol.org>
e88ee4d @manuelpichler - Copyright adjusted for 2008.
manuelpichler authored
42 * @copyright 2007-2008 Manuel Pichler. All rights reserved.
8a02dd8 @manuelpichler - Package structure changed.
manuelpichler authored
43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 * @version SVN: $Id$
45 * @link http://www.phpundercontrol.org/
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
46 */
47
48 /**
49 * Utility class that handles the command line arguments for this tool.
50 *
de4b1c5 @manuelpichler - @category tag added.
manuelpichler authored
51 * @category QualityAssurance
438a68d @manuelpichler - Console stuff moved to it's own package.
manuelpichler authored
52 * @package Console
f6ab6b0 @manuelpichler - email address changed.
manuelpichler authored
53 * @author Manuel Pichler <mapi@phpundercontrol.org>
e88ee4d @manuelpichler - Copyright adjusted for 2008.
manuelpichler authored
54 * @copyright 2007-2008 Manuel Pichler. All rights reserved.
8a02dd8 @manuelpichler - Package structure changed.
manuelpichler authored
55 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
56 * @version Release: @package_version@
57 * @link http://www.phpundercontrol.org/
0227194 @manuelpichler - package.xml file for phpUnderControl added.
manuelpichler authored
58 *
59 * @property-read string $command The specified command.
60 * @property-read array $options List of command line options.
61 * @property-read array $arguments List of command line arguments.
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
62 */
ec3cceb @manuelpichler - Source code restructured.
manuelpichler authored
63 class phpucConsoleArgs
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
64 {
65 /**
66 * List of properties read from the command line interface.
67 *
68 * @type array<mixed>
69 * @var array(string=>mixed) $properties
70 */
71 private $properties = array(
0227194 @manuelpichler - package.xml file for phpUnderControl added.
manuelpichler authored
72 'command' => null,
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
73 'options' => array(),
74 'arguments' => array()
75 );
76
77 /**
0b175b6 @manuelpichler - Console stuff refactored into an input parser and a cli input
manuelpichler authored
78 * Constructs a cli arguments object
79 *
80 * @param string $command The given command.
81 * @param array(string=>mixed) $options The given command line options.
82 * @param array(string=>string) $arguments The given command line arguments.
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
83 */
0b175b6 @manuelpichler - Console stuff refactored into an input parser and a cli input
manuelpichler authored
84 public function __construct( $command, array $options, array $arguments )
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
85 {
0b175b6 @manuelpichler - Console stuff refactored into an input parser and a cli input
manuelpichler authored
86 $this->properties = array(
87 'command' => $command,
88 'options' => $options,
89 'arguments' => $arguments
90 );
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
91 }
92
93 /**
ec3cceb @manuelpichler - Source code restructured.
manuelpichler authored
94 * Checks if a value for <b>$name</b> exists.
95 *
96 * @param string $name The argument identifier.
97 *
98 * @return boolean
99 */
100 public function hasArgument( $name )
101 {
102 return isset( $this->properties['arguments'][$name] );
103 }
104
105 /**
106 * Returns the value of the argument identified by <b>$name</b>.
107 *
108 * @param string $name The argument identifier.
109 *
110 * @return string
111 * @throws OutOfRangeException If no entry exists for $name.
112 */
113 public function getArgument( $name )
114 {
115 if ( $this->hasArgument( $name ) )
116 {
117 return $this->properties['arguments'][$name];
118 }
119 throw new OutOfRangeException(
120 sprintf( 'Unknown argument "%s"."', $name )
121 );
122 }
123
124 /**
125 * Checks if a value for <b>$name</b> exists.
126 *
127 * @param string $name The option identifier.
128 *
129 * @return boolean
130 */
131 public function hasOption( $name )
132 {
133 return isset( $this->properties['options'][$name] );
134 }
135
136 /**
137 * Returns the value of the option identified by <b>$name</b>.
138 *
139 * @param string $name The option identifier.
140 *
141 * @return string
142 * @throws OutOfRangeException If no entry exists for $name.
143 */
144 public function getOption( $name )
145 {
146 if ( $this->hasOption( $name ) )
147 {
148 return $this->properties['options'][$name];
149 }
150 throw new OutOfRangeException(
e5e0e17 @manuelpichler - New cli command clean added, that can delete old build artifacts an…
manuelpichler authored
151 sprintf( 'Unknown option "%s".', $name )
ec3cceb @manuelpichler - Source code restructured.
manuelpichler authored
152 );
153 }
154
155 /**
44e0ab8 @manuelpichler - Switch to pluggable cli interface.
manuelpichler authored
156 * Sets and option value.
157 *
158 * @param string $name The option identifier.
159 * @param string $value The option value.
160 *
161 * @return void
162 */
163 public function setOption( $name, $value )
164 {
165 $this->properties['options'][$name] = $value;
166 }
167
168 /**
77ac812 @sebastianbergmann - Restructure.
sebastianbergmann authored
169 * Magic property getter method.
170 *
171 * @param string $name The property name.
172 *
173 * @return mixed
174 * @throws OutOfRangeException If the requested property doesn't exist or
175 * is writonly.
176 */
177 public function __get( $name )
178 {
179 if ( array_key_exists( $name, $this->properties ) === true )
180 {
181 return $this->properties[$name];
182 }
183 throw new OutOfRangeException(
184 sprintf( 'Unknown or writonly property $%s.', $name )
185 );
186 }
187 }
Something went wrong with that request. Please try again.