Skip to content

Commit da26eec

Browse files
committed
Added Util::count();
Initial support for colors at the console; CS fixes;
1 parent 3bc379c commit da26eec

20 files changed

+464
-201
lines changed

bin/roscon.php

Lines changed: 198 additions & 66 deletions
Large diffs are not rendered by default.

catalog.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

data/roscon.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<command>
33
<description>RouterOS API console.</description>
4-
<version>@PACKAGE_VERSION@</version>
4+
<version>GIT: $Id$</version>
55
<argument name="hostname">
66
<description>Hostname of the RouterOS to connect to.</description>
77
</argument>
@@ -49,6 +49,11 @@ Defaults to PHP's default_socket_timeout ini option.</description>
4949
<description>Turn on verbose output.</description>
5050
<action>StoreTrue</action>
5151
</option>
52+
<option name="colors">
53+
<long_name>--colors</long_name>
54+
<description>Turn on color output.</description>
55+
<action>StoreTrue</action>
56+
</option>
5257
<option name="size">
5358
<short_name>-w</short_name>
5459
<long_name>--width</long_name>

examples/callback-and-loop.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
$client = new Client('192.168.0.1', 'admin');
77

88
//Custom function, defined specifically for the example
9-
function responseHandler($response)
10-
{
9+
$responseHandler = function ($response) {
1110
if ($response->getType() === Response::TYPE_FINAL) {
1211
echo "{$response->getTag()} is done.\n";
1312
}
14-
}
13+
};
1514

1615
$addRequest = new Request('/ip/arp/add');
1716

1817
$addRequest->setArgument('address', '192.168.0.100');
1918
$addRequest->setArgument('mac-address', '00:00:00:00:00:01');
2019
$addRequest->setTag('arp1');
21-
$client->sendAsync($addRequest, 'responseHandler');
20+
$client->sendAsync($addRequest, $responseHandler);
2221

2322
$addRequest->setArgument('address', '192.168.0.101');
2423
$addRequest->setArgument('mac-address', '00:00:00:00:00:02');
2524
$addRequest->setTag('arp2');
26-
$client->sendAsync($addRequest, 'responseHandler');
25+
$client->sendAsync($addRequest, $responseHandler);
2726

2827
$client->loop();
2928
//Example output:

extrasetup.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
3+
/**
4+
* extrasetup.php for PEAR2_Net_RouterOS.
5+
*
6+
* PHP version 5.3
7+
*
8+
* @category Net
9+
* @package PEAR2_Net_RouterOS
10+
* @author Vasil Rangelov <boen.robot@gmail.com>
11+
* @copyright 2011 Vasil Rangelov
12+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
13+
* @version GIT: $Id$
14+
* @link http://pear2.php.net/PEAR2_Net_RouterOS
15+
*/
16+
217
$extrafiles = array();
318
$phpDir = Pyrus\Config::current()->php_dir;
419
$packages = array('PEAR2/Autoload', 'PEAR2/Cache/SHM', 'PEAR2/Net/Transmitter');
@@ -7,16 +22,14 @@
722
chdir($phpDir);
823
foreach ($packages as $pkg) {
924
if (is_dir($pkg)) {
10-
foreach (
11-
new RecursiveIteratorIterator(
12-
new RecursiveDirectoryIterator(
13-
$pkg,
14-
RecursiveDirectoryIterator::UNIX_PATHS
15-
| RecursiveDirectoryIterator::SKIP_DOTS
16-
),
17-
RecursiveIteratorIterator::LEAVES_ONLY
18-
) as $path
19-
) {
25+
foreach (new RecursiveIteratorIterator(
26+
new RecursiveDirectoryIterator(
27+
$pkg,
28+
RecursiveDirectoryIterator::UNIX_PATHS
29+
| RecursiveDirectoryIterator::SKIP_DOTS
30+
),
31+
RecursiveIteratorIterator::LEAVES_ONLY
32+
) as $path) {
2033
$extrafiles['src/' . $path->getPathname()] = $path->getRealPath();
2134
}
2235
}

packagexmlsetup.php

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<?php
2+
3+
/**
4+
* packagexmlsetup.php for PEAR2_Net_RouterOS.
5+
*
6+
* PHP version 5.3
7+
*
8+
* @category Net
9+
* @package PEAR2_Net_RouterOS
10+
* @author Vasil Rangelov <boen.robot@gmail.com>
11+
* @copyright 2011 Vasil Rangelov
12+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
13+
* @version GIT: $Id$
14+
* @link http://pear2.php.net/PEAR2_Net_RouterOS
15+
*/
16+
17+
/**
18+
* References the package in $package
19+
*/
220
use Pyrus\Developer\PackageFile\v2;
321

422
$packageGen = function (
@@ -16,32 +34,43 @@
1634
)
1735
)
1836
);
19-
20-
$srcFileTasks = array(
37+
$verTask = array(
2138
'tasks:replace' => array(
2239
array(
2340
'attribs' => array(
24-
'from' => '~~summary~~',
25-
'to' => 'summary',
26-
'type' => 'package-info'
27-
)
28-
),
29-
array(
30-
'attribs' => array(
31-
'from' => '~~description~~',
32-
'to' => 'description',
33-
'type' => 'package-info'
34-
)
35-
),
36-
array(
37-
'attribs' => array(
38-
'from' => 'GIT: $Id$',
39-
'to' => 'version',
40-
'type' => 'package-info'
41+
'from' => '../../PEAR2_Net_Transmitter.git/src/',
42+
'to' => 'php_dir',
43+
'type' => 'pear-config'
4144
)
4245
)
4346
)
4447
);
48+
$srcFileTasks = array_merge_recursive(
49+
array(
50+
'tasks:replace' => array(
51+
array(
52+
'attribs' => array(
53+
'from' => '~~summary~~',
54+
'to' => 'summary',
55+
'type' => 'package-info'
56+
)
57+
),
58+
array(
59+
'attribs' => array(
60+
'from' => '~~description~~',
61+
'to' => 'description',
62+
'type' => 'package-info'
63+
)
64+
)
65+
)
66+
),
67+
$verTask
68+
);
69+
70+
$package->files['data/roscon.xml'] = array_merge_recursive(
71+
$package->files['data/roscon.xml']->getArrayCopy(),
72+
$verTask
73+
);
4574

4675
$package->files['tests/bootstrap.php'] = array_merge_recursive(
4776
$package->files['tests/bootstrap.php']->getArrayCopy(),
@@ -67,22 +96,12 @@
6796
$package->files['docs/apigen.neon']->getArrayCopy(),
6897
$srcDirTask
6998
);
70-
7199
$package->files['docs/doxygen.ini'] = array_merge_recursive(
72100
$package->files['docs/doxygen.ini']->getArrayCopy(),
73101
$srcDirTask,
74-
array(
75-
'tasks:replace' => array(
76-
array(
77-
'attribs' => array(
78-
'from' => 'GIT: $Id$',
79-
'to' => 'version',
80-
'type' => 'package-info'
81-
)
82-
)
83-
)
84-
)
102+
$verTask
85103
);
104+
86105
$hasCompatible = null !== $compatible;
87106
if ($hasCompatible) {
88107
$compatible->license = $package->license;
@@ -121,31 +140,20 @@
121140
"doc/{$package->channel}/{$package->name}/doxygen.ini"
122141
]->getArrayCopy(),
123142
$srcDirTask,
124-
array(
125-
'tasks:replace' => array(
126-
array(
127-
'attribs' => array(
128-
'from' => 'GIT: $Id$',
129-
'to' => 'version',
130-
'type' => 'package-info'
131-
)
132-
)
133-
)
134-
)
143+
$verTask
135144
);
136145
}
137146

138147
$oldCwd = getcwd();
139148
chdir(__DIR__);
140-
foreach (
141-
new RecursiveIteratorIterator(
142-
new RecursiveDirectoryIterator(
143-
'src',
144-
RecursiveDirectoryIterator::UNIX_PATHS
145-
| RecursiveDirectoryIterator::SKIP_DOTS
146-
),
147-
RecursiveIteratorIterator::LEAVES_ONLY
148-
) as $path) {
149+
foreach (new RecursiveIteratorIterator(
150+
new RecursiveDirectoryIterator(
151+
'src',
152+
RecursiveDirectoryIterator::UNIX_PATHS
153+
| RecursiveDirectoryIterator::SKIP_DOTS
154+
),
155+
RecursiveIteratorIterator::LEAVES_ONLY
156+
) as $path) {
149157
$filename = $path->getPathname();
150158

151159
$package->files[$filename] = array_merge_recursive(
@@ -162,15 +170,14 @@
162170
}
163171
}
164172

165-
foreach (
166-
new RecursiveIteratorIterator(
167-
new RecursiveDirectoryIterator(
168-
'.',
169-
RecursiveDirectoryIterator::UNIX_PATHS
170-
| RecursiveDirectoryIterator::SKIP_DOTS
171-
),
172-
RecursiveIteratorIterator::LEAVES_ONLY
173-
) as $path) {
173+
foreach (new RecursiveIteratorIterator(
174+
new RecursiveDirectoryIterator(
175+
'.',
176+
RecursiveDirectoryIterator::UNIX_PATHS
177+
| RecursiveDirectoryIterator::SKIP_DOTS
178+
),
179+
RecursiveIteratorIterator::LEAVES_ONLY
180+
) as $path) {
174181
$filename = substr($path->getPathname(), 2);
175182

176183
if (isset($package->files[$filename])) {

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* Refers to the cryptography constants.
3030
*/
31-
use PEAR2\Net\Transmitter\NetworkStream AS N;
31+
use PEAR2\Net\Transmitter\NetworkStream as N;
3232

3333
/**
3434
* A RouterOS client.
@@ -206,7 +206,7 @@ public function __invoke($arg = null)
206206
*/
207207
public static function login(
208208
Communicator $com,
209-
$username,
209+
$username,
210210
$password = '',
211211
$timeout = null
212212
) {

src/PEAR2/Net/RouterOS/DataFlowException.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
namespace PEAR2\Net\RouterOS;
2222

23+
/**
24+
* Base of this class.
25+
*/
26+
use RuntimeException;
27+
2328
/**
2429
* Exception thrown when the request/response cycle goes an unexpected way.
2530
*
@@ -29,7 +34,7 @@
2934
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
3035
* @link http://pear2.php.net/PEAR2_Net_RouterOS
3136
*/
32-
class DataFlowException extends \RuntimeException implements Exception
37+
class DataFlowException extends RuntimeException implements Exception
3338
{
3439
const CODE_INVALID_CREDENTIALS = 10000;
3540
const CODE_TAG_REQUIRED = 10500;

src/PEAR2/Net/RouterOS/InvalidArgumentException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
namespace PEAR2\Net\RouterOS;
2222

23+
use InvalidArgumentException as I;
24+
2325
/**
2426
* Exception thrown when there's something wrong with message arguments.
2527
*
@@ -29,8 +31,7 @@
2931
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
3032
* @link http://pear2.php.net/PEAR2_Net_RouterOS
3133
*/
32-
class InvalidArgumentException extends \InvalidArgumentException
33-
implements Exception
34+
class InvalidArgumentException extends I implements Exception
3435
{
3536
const CODE_SEEKABLE_REQUIRED = 1100;
3637
const CODE_NAME_INVALID = 20100;
@@ -39,5 +40,4 @@ class InvalidArgumentException extends \InvalidArgumentException
3940
const CODE_CMD_INVALID = 40202;
4041
const CODE_NAME_UNPARSABLE = 41000;
4142
const CODE_VALUE_UNPARSABLE = 41001;
42-
4343
}

src/PEAR2/Net/RouterOS/LengthException.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
namespace PEAR2\Net\RouterOS;
2222

23+
/**
24+
* Base of this class.
25+
*/
26+
use LengthException;
27+
2328
/**
2429
* Exception thrown when there is a problem with a word's length.
2530
*
@@ -29,7 +34,7 @@
2934
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
3035
* @link http://pear2.php.net/PEAR2_Net_RouterOS
3136
*/
32-
class LengthException extends \LengthException implements Exception
37+
class LengthException extends LengthException implements Exception
3338
{
3439

3540
const CODE_UNSUPPORTED = 1200;

0 commit comments

Comments
 (0)