Skip to content

Commit 0f4e219

Browse files
committed
CS fixes;
Fixed notice when regenerating package.xml; Lots of other changes (see RELEASE-0.2.2)
1 parent 4a35686 commit 0f4e219

32 files changed

+213
-137
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ php:
33
- 5.3
44
- 5.4
55
- 5.5
6+
- 5.6
7+
- 7.0
68
before_script:
79
- pyrus install -p pyrus.net/Pyrus_Developer-alpha
810
- pyrus install PEAR2_Autoload-alpha

RELEASE-0.2.2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* Brought fixes from PEAR_Console_CommandLine 1.2.2, namely
2+
- xmlschema.rng is looked for in more locations (though this package also includes a lookup first on Pyrus' folder layout, and also respects the PHP_PEAR_DATA_DIR environment variable's value, and fixes the error message when the file is not found in any location)
3+
- Package dependencies include DOM (though this package includes it as an optional dependency, because it's only needed when getting definitions from an XML file; not when constructing them "manually; Also, the "xml" extension is not used, so it's not included here)
4+
- Fixed comparrisons in PHP7
5+
- Replaced static with private variables
6+
* Made this package PSR-4 compatible, while preserving PSR-0 compatibility by moving MessageProvider_Default into it's own MessageProvider sub-namespace, and renaming the class itself to DefaultProvider to avoid it having a reserved word ("default") as its name.
7+
* CS fixes.

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"require": {
2828
"php": ">=5.3.0"
2929
},
30+
"suggest": {
31+
"ext-dom": "Required when parsing definitions from an XML file"
32+
},
3033
"autoload": {
3134
"psr-0": {
3235
"PEAR2\\Console\\CommandLine": "src/"

package.xml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ Main features:
3434
<email>[email protected]</email>
3535
<active>yes</active>
3636
</helper>
37-
<date>2014-06-22</date>
38-
<time>23:21:23</time>
37+
<date>2016-11-09</date>
38+
<time>02:01:33</time>
3939
<version>
40-
<release>0.2.1</release>
40+
<release>0.2.2</release>
4141
<api>0.1.0</api>
4242
</version>
4343
<stability>
4444
<release>alpha</release>
4545
<api>alpha</api>
4646
</stability>
4747
<license uri="http://opensource.org/licenses/mit-license.php">MIT License</license>
48-
<notes>* Added a composer.json, and this package to packagist.org.
49-
* Fixed GitHub issue #2: columnWrap() in Default Renderer eats up lines with only a EOL.
50-
* Fixed validation of XML definition files: The directory of the RNG schema was wrong.
51-
* Fixed test suite errors, including namespace related ones and adding Travis-CI configuration.
52-
* Removed PEAR2\Exception dependency - This package's exception directly inherits from the root Exception.
53-
* CS fixes.
54-
</notes>
48+
<notes>* Brought fixes from PEAR_Console_CommandLine 1.2.2, namely
49+
- xmlschema.rng is looked for in more locations (though this package also includes a lookup first on Pyrus' folder layout, and also respects the PHP_PEAR_DATA_DIR environment variable's value, and fixes the error message when the file is not found in any location)
50+
- Package dependencies include DOM (though this package includes it as an optional dependency, because it's only needed when getting definitions from an XML file; not when constructing them &quot;manually; Also, the &quot;xml&quot; extension is not used, so it's not included here)
51+
- Fixed comparrisons in PHP7
52+
- Replaced static with private variables
53+
* Made this package PSR-4 compatible, while preserving PSR-0 compatibility by moving MessageProvider_Default into it's own MessageProvider sub-namespace, and renaming the class itself to DefaultProvider to avoid it having a reserved word (&quot;default&quot;) as its name.
54+
* CS fixes.</notes>
5555
<contents>
5656
<dir name="/">
5757
<dir name="data" baseinstalldir="/">
@@ -116,7 +116,7 @@ Main features:
116116
</file>
117117
</dir>
118118
<dir name="MessageProvider">
119-
<file role="php" name="Default.php">
119+
<file role="php" name="DefaultProvider.php">
120120
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
121121
</file>
122122
</dir>
@@ -162,6 +162,7 @@ Main features:
162162
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
163163
</file>
164164
<file role="php" name="XmlParser.php">
165+
<tasks:replace type="pear-config" to="data_dir" from="@data_dir@"/>
165166
<tasks:replace type="package-info" to="version" from="GIT: $Id$"/>
166167
</file>
167168
</dir>
@@ -245,6 +246,9 @@ Main features:
245246
<name>PEAR2_Autoload</name>
246247
<channel>pear2.php.net</channel>
247248
</package>
249+
<extension>
250+
<name>dom</name>
251+
</extension>
248252
</optional>
249253
</dependencies>
250254
<phprelease>
@@ -276,7 +280,7 @@ Main features:
276280
<install name="src/PEAR2/Console/CommandLine/Element.php" as="PEAR2/Console/CommandLine/Element.php"/>
277281
<install name="src/PEAR2/Console/CommandLine/Exception.php" as="PEAR2/Console/CommandLine/Exception.php"/>
278282
<install name="src/PEAR2/Console/CommandLine/MessageProvider.php" as="PEAR2/Console/CommandLine/MessageProvider.php"/>
279-
<install name="src/PEAR2/Console/CommandLine/MessageProvider/Default.php" as="PEAR2/Console/CommandLine/MessageProvider/Default.php"/>
283+
<install name="src/PEAR2/Console/CommandLine/MessageProvider/DefaultProvider.php" as="PEAR2/Console/CommandLine/MessageProvider/DefaultProvider.php"/>
280284
<install name="src/PEAR2/Console/CommandLine/Option.php" as="PEAR2/Console/CommandLine/Option.php"/>
281285
<install name="src/PEAR2/Console/CommandLine/Outputter.php" as="PEAR2/Console/CommandLine/Outputter.php"/>
282286
<install name="src/PEAR2/Console/CommandLine/Outputter/Default.php" as="PEAR2/Console/CommandLine/Outputter/Default.php"/>

packagexmlsetup.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
'type' => 'pear-config',
5252
'to' => 'php_dir'
5353
),
54+
'@data_dir@' => array(
55+
'type' => 'pear-config',
56+
'to' => 'data_dir'
57+
),
5458
'GIT: $Id$' => array(
5559
'type' => 'package-info',
5660
'to' => 'version'
@@ -75,7 +79,7 @@
7579
$cTasksNs = $compatible ? $compatible->getTasksNs() : '';
7680
$oldCwd = getcwd();
7781
chdir(__DIR__);
78-
$package->setRawRelease('php', null);
82+
$package->setRawRelease('php', '');
7983
$release = $package->getReleaseToInstall('php');
8084
foreach (new RecursiveIteratorIterator(
8185
new RecursiveDirectoryIterator(

src/PEAR2/Console/CommandLine.php

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CommandLine
5959
* Error messages.
6060
*
6161
* @var array $errors Error messages
62+
*
6263
* @todo move this to PEAR2\Console\CommandLine\MessageProvider
6364
*/
6465
public static $errors = array(
@@ -130,7 +131,7 @@ class CommandLine
130131
/**
131132
* The command line parser renderer instance.
132133
*
133-
* @var object that implements PEAR2\Console\CommandLine\Renderer interface
134+
* @var PEAR2\Console\CommandLine\Renderer a renderer
134135
*/
135136
public $renderer = false;
136137

@@ -144,7 +145,7 @@ class CommandLine
144145
/**
145146
* The command line message provider instance.
146147
*
147-
* @var PEAR2\Console\CommandLine\MessageProvider A message provider instance
148+
* @var PEAR2\Console\CommandLine\MessageProvider A message provider
148149
*/
149150
public $message_provider = false;
150151

@@ -191,6 +192,7 @@ class CommandLine
191192
* convenience.
192193
*
193194
* @var PEAR2\Console\CommandLine The parent instance
195+
*
194196
* @todo move CommandLine::parent to CommandLine\Command
195197
*/
196198
public $parent = false;
@@ -272,7 +274,7 @@ class CommandLine
272274
* </code>
273275
*
274276
* @var array
275-
* @see PEAR2\Console\CommandLine\MessageProvider_Default
277+
* @see PEAR2\Console\CommandLine\MessageProvider\DefaultProvider
276278
*/
277279
public $messages = array();
278280

@@ -286,6 +288,9 @@ class CommandLine
286288
*/
287289
private $_dispatchLater = array();
288290

291+
private $_lastopt = false;
292+
private $_stopflag = false;
293+
289294
// }}}
290295
// __construct() {{{
291296

@@ -345,7 +350,7 @@ public function __construct(array $params = array())
345350
// set default instances
346351
$this->renderer = new CommandLine\Renderer_Default($this);
347352
$this->outputter = new CommandLine\Outputter_Default();
348-
$this->message_provider = new CommandLine\MessageProvider_Default();
353+
$this->message_provider = new CommandLine\MessageProvider\DefaultProvider();
349354
}
350355

351356
// }}}
@@ -481,6 +486,7 @@ public static function fromXmlString($string)
481486
* @param array $params An array containing the argument attributes
482487
*
483488
* @return PEAR2\Console\CommandLine\Argument the added argument
489+
*
484490
* @see PEAR2\Console\CommandLine\Argument
485491
*/
486492
public function addArgument($name, $params = array())
@@ -842,6 +848,7 @@ public static function registerAction($name, $class)
842848
* @param array $params An array of search=>replaces entries
843849
*
844850
* @return void
851+
*
845852
* @todo remove Console::triggerError() and use exceptions only
846853
*/
847854
public static function triggerError($msgId, $level, $params=array())
@@ -912,7 +919,7 @@ public function parse($userArgc=null, $userArgv=null)
912919
// Check if an invalid subcommand was specified. If there are
913920
// subcommands and no arguments, but an argument was provided, it is
914921
// an invalid subcommand.
915-
if ( count($this->commands) > 0
922+
if (count($this->commands) > 0
916923
&& count($this->args) === 0
917924
&& count($args) > 0
918925
) {
@@ -925,7 +932,7 @@ public function parse($userArgc=null, $userArgv=null)
925932
}
926933
// if subcommand_required is set to true we must check that we have a
927934
// subcommand.
928-
if ( count($this->commands)
935+
if (count($this->commands)
929936
&& $this->subcommand_required
930937
&& !$result->command_name
931938
) {
@@ -989,23 +996,21 @@ public function parse($userArgc=null, $userArgv=null)
989996
*/
990997
protected function parseToken($token, $result, &$args, $argc)
991998
{
992-
static $lastopt = false;
993-
static $stopflag = false;
994999
$last = $argc === 0;
995-
if (!$stopflag && $lastopt) {
1000+
if (!$this->_stopflag && $this->_lastopt) {
9961001
if (substr($token, 0, 1) == '-') {
997-
if ($lastopt->argument_optional) {
998-
$this->_dispatchAction($lastopt, '', $result);
999-
if ($lastopt->action != 'StoreArray') {
1000-
$lastopt = false;
1002+
if ($this->_lastopt->argument_optional) {
1003+
$this->_dispatchAction($this->_lastopt, '', $result);
1004+
if ($this->_lastopt->action != 'StoreArray') {
1005+
$this->_lastopt = false;
10011006
}
1002-
} else if (isset($result->options[$lastopt->name])) {
1007+
} else if (isset($result->options[$this->_lastopt->name])) {
10031008
// case of an option that expect a list of args
1004-
$lastopt = false;
1009+
$this->_lastopt = false;
10051010
} else {
10061011
throw CommandLine\Exception::factory(
10071012
'OPTION_VALUE_REQUIRED',
1008-
array('name' => $lastopt->name),
1013+
array('name' => $this->_lastopt->name),
10091014
$this,
10101015
$this->messages
10111016
);
@@ -1015,31 +1020,31 @@ protected function parseToken($token, $result, &$args, $argc)
10151020
// is to consider that if there's already an element in the
10161021
// array, and the commandline expects one or more args, we
10171022
// leave last tokens to arguments
1018-
if ($lastopt->action == 'StoreArray'
1019-
&& !empty($result->options[$lastopt->name])
1023+
if ($this->_lastopt->action == 'StoreArray'
1024+
&& !empty($result->options[$this->_lastopt->name])
10201025
&& count($this->args) > ($argc + count($args))
10211026
) {
10221027
if (!is_null($token)) {
10231028
$args[] = $token;
10241029
}
10251030
return;
10261031
}
1027-
if (!is_null($token) || $lastopt->action == 'Password') {
1028-
$this->_dispatchAction($lastopt, $token, $result);
1032+
if (!is_null($token) || $this->_lastopt->action == 'Password') {
1033+
$this->_dispatchAction($this->_lastopt, $token, $result);
10291034
}
1030-
if ($lastopt->action != 'StoreArray') {
1031-
$lastopt = false;
1035+
if ($this->_lastopt->action != 'StoreArray') {
1036+
$this->_lastopt = false;
10321037
}
10331038
return;
10341039
}
10351040
}
1036-
if (!$stopflag && substr($token, 0, 2) == '--') {
1041+
if (!$this->_stopflag && substr($token, 0, 2) == '--') {
10371042
// a long option
10381043
$optkv = explode('=', $token, 2);
10391044
if (trim($optkv[0]) == '--') {
10401045
// the special argument "--" forces in all cases the end of
10411046
// option scanning.
1042-
$stopflag = true;
1047+
$this->_stopflag = true;
10431048
return;
10441049
}
10451050
$opt = $this->findOption($optkv[0]);
@@ -1072,14 +1077,14 @@ protected function parseToken($token, $result, &$args, $argc)
10721077
);
10731078
}
10741079
// we will have a value next time
1075-
$lastopt = $opt;
1080+
$this->_lastopt = $opt;
10761081
return;
10771082
}
10781083
if ($opt->action == 'StoreArray') {
1079-
$lastopt = $opt;
1084+
$this->_lastopt = $opt;
10801085
}
10811086
$this->_dispatchAction($opt, $value, $result);
1082-
} else if (!$stopflag && substr($token, 0, 1) == '-') {
1087+
} else if (!$this->_stopflag && substr($token, 0, 1) == '-') {
10831088
// a short option
10841089
$optname = substr($token, 0, 2);
10851090
if ($optname == '-') {
@@ -1100,7 +1105,7 @@ protected function parseToken($token, $result, &$args, $argc)
11001105
// in short: handle -f<value> and -f <value>
11011106
$next = substr($token, 2, 1);
11021107
// check if we must wait for a value
1103-
if ($next === false) {
1108+
if (!$next) {
11041109
if ($opt->expectsArgument()) {
11051110
if ($last && !$opt->argument_optional) {
11061111
throw CommandLine\Exception::factory(
@@ -1111,7 +1116,7 @@ protected function parseToken($token, $result, &$args, $argc)
11111116
);
11121117
}
11131118
// we will have a value next time
1114-
$lastopt = $opt;
1119+
$this->_lastopt = $opt;
11151120
return;
11161121
}
11171122
$value = false;
@@ -1136,7 +1141,7 @@ protected function parseToken($token, $result, &$args, $argc)
11361141
}
11371142
}
11381143
if ($opt->action == 'StoreArray') {
1139-
$lastopt = $opt;
1144+
$this->_lastopt = $opt;
11401145
}
11411146
$value = substr($token, 2);
11421147
}
@@ -1145,8 +1150,8 @@ protected function parseToken($token, $result, &$args, $argc)
11451150
// We have an argument.
11461151
// if we are in POSIX compliant mode, we must set the stop flag to
11471152
// true in order to stop option parsing.
1148-
if (!$stopflag && $this->force_posix) {
1149-
$stopflag = true;
1153+
if (!$this->_stopflag && $this->force_posix) {
1154+
$this->_stopflag = true;
11501155
}
11511156
if (!is_null($token)) {
11521157
$args[] = $token;

src/PEAR2/Console/CommandLine/Action.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
* through the world-wide-web at the following URI:
1212
* http://opensource.org/licenses/mit-license.php
1313
*
14-
* @category Console
14+
* @category Console
1515
* @package PEAR2\Console\CommandLine
1616
* @author David JEAN LOUIS <[email protected]>
1717
* @copyright 2007-2009 David JEAN LOUIS
18-
* @license http://opensource.org/licenses/mit-license.php MIT License
18+
* @license http://opensource.org/licenses/mit-license.php MIT License
1919
* @version GIT: $Id$
2020
* @link http://pear2.php.net/PEAR2_Console_CommandLine
2121
* @since File available since release 0.1.0
22+
*
2223
* @filesource
2324
*/
2425
namespace PEAR2\Console\CommandLine;

src/PEAR2/Console/CommandLine/Action/Callback.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
* through the world-wide-web at the following URI:
1212
* http://opensource.org/licenses/mit-license.php
1313
*
14-
* @category Console
14+
* @category Console
1515
* @package PEAR2\Console\CommandLine
1616
* @author David JEAN LOUIS <[email protected]>
1717
* @copyright 2007-2009 David JEAN LOUIS
18-
* @license http://opensource.org/licenses/mit-license.php MIT License
18+
* @license http://opensource.org/licenses/mit-license.php MIT License
1919
* @version GIT: $Id$
2020
* @link http://pear2.php.net/PEAR2_Console_CommandLine
2121
* @since File available since release 0.1.0
22+
*
2223
* @filesource
2324
*/
2425
namespace PEAR2\Console\CommandLine\Action;

0 commit comments

Comments
 (0)