Skip to content

Commit c2fa0ae

Browse files
committed
Added Util::prepareScript() and made Util::exec() use it;
Added the ability of Util::add() and Util::set()/Util::edit() to accept flags as array values with a numeric key; Util::filePutContents() with NULL as data now causes the removal of a file with that name (+ verification of successful deletion) - it previously caused an error; Adjusted the methods of ResponseCollection that return a new collection to use "new static" instead of "new ResponseCollection", allowing potential extensions of ResponseCollection; Fixed Communicator::verifyLengthSupport() - it's 0xFFFFFFFF (8 "F"s), not 0xFFFFFFF (7 "F"s); Doc fixes.
1 parent 01f78ca commit c2fa0ae

File tree

7 files changed

+264
-96
lines changed

7 files changed

+264
-96
lines changed

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function getCharset($charsetType)
341341
* one last time after that with a response that notifies about the
342342
* canceling.
343343
*
344-
* @return self|Client The client object.
344+
* @return $this The client object.
345345
* @see completeRequest()
346346
* @see loop()
347347
* @see cancelRequest()

src/PEAR2/Net/RouterOS/Communicator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function sendWord($word)
391391
* supplied stream must be seekable.
392392
*
393393
* @param string $prefix A string to prepend before the stream contents.
394-
* @param resource $stream The stream to send.
394+
* @param resource $stream The seekable stream to send.
395395
*
396396
* @return int The number of bytes sent.
397397
* @see sendWord()
@@ -441,7 +441,7 @@ public function sendWordFromStream($prefix, $stream)
441441
*
442442
* Verifies if the specified length is supported by the API. Throws a
443443
* {@link LengthException} if that's not the case. Currently, RouterOS
444-
* supports words up to 0xFFFFFFF in length, so that's the only check
444+
* supports words up to 0xFFFFFFFF in length, so that's the only check
445445
* performed.
446446
*
447447
* @param int $length The length to verify.
@@ -450,9 +450,9 @@ public function sendWordFromStream($prefix, $stream)
450450
*/
451451
protected static function verifyLengthSupport($length)
452452
{
453-
if ($length > 0xFFFFFFF) {
453+
if ($length > 0xFFFFFFFF) {
454454
throw new LengthException(
455-
'Words with length above 0xFFFFFFF are not supported.',
455+
'Words with length above 0xFFFFFFFF are not supported.',
456456
LengthException::CODE_UNSUPPORTED,
457457
null,
458458
$length

src/PEAR2/Net/RouterOS/Message.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ public function getAllArguments()
163163
/**
164164
* Sets an argument for the message.
165165
*
166-
* @param string $name Name of the argument.
167-
* @param string $value Value of the argument. Setting the value to NULL
168-
* removes an argument of this name.
166+
* @param string $name Name of the argument.
167+
* @param string|resource|null $value Value of the argument as a string or
168+
* seekable stream.
169+
* Setting the value to NULL removes an argument of this name.
170+
* If a seekable stream is provided, it is sent from its current
171+
* posistion to its end, and the pointer is seeked back to its current
172+
* position after sending.
173+
* Non seekable streams, as well as all other types, are casted to a
174+
* string.
169175
*
170176
* @return self|Message The message object.
171177
* @see getArgument()

src/PEAR2/Net/RouterOS/Query.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected static function sanitizeAction($action)
114114
* @param string $action One of the ACTION_* constants. Describes the
115115
* operation to perform.
116116
*
117-
* @return self|Query The query object.
117+
* @return static The query object.
118118
*/
119119
public static function where(
120120
$name,
@@ -128,7 +128,7 @@ public static function where(
128128
/**
129129
* Negates the query.
130130
*
131-
* @return self|Query The query object.
131+
* @return $this The query object.
132132
*/
133133
public function not()
134134
{
@@ -139,13 +139,18 @@ public function not()
139139
/**
140140
* Adds a condition as an alternative to the query.
141141
*
142-
* @param string $name The name of the property to test.
143-
* @param string $value The value to test against. Not required for
144-
* existence tests.
145-
* @param string $action One of the ACTION_* constants. Describes the
146-
* operation to perform.
142+
* @param string $name The name of the property to test.
143+
* @param string|resource|null $value Value of the property as a string or
144+
* seekable stream. Not required for existence tests.
145+
* If a seekable stream is provided, it is sent from its current
146+
* posistion to its end, and the pointer is seeked back to its current
147+
* position after sending.
148+
* Non seekable streams, as well as all other types, are casted to a
149+
* string.
150+
* @param string $action One of the ACTION_* constants.
151+
* Describes the operation to perform.
147152
*
148-
* @return self|Query The query object.
153+
* @return $this The query object.
149154
*/
150155
public function orWhere($name, $value = null, $action = self::ACTION_EXIST)
151156
{
@@ -156,13 +161,18 @@ public function orWhere($name, $value = null, $action = self::ACTION_EXIST)
156161
/**
157162
* Adds a condition in addition to the query.
158163
*
159-
* @param string $name The name of the property to test.
160-
* @param string $value The value to test against. Not required for
161-
* existence tests.
162-
* @param string $action One of the ACTION_* constants. Describes the
163-
* operation to perform.
164+
* @param string $name The name of the property to test.
165+
* @param string|resource|null $value Value of the property as a string or
166+
* seekable stream. Not required for existence tests.
167+
* If a seekable stream is provided, it is sent from its current
168+
* posistion to its end, and the pointer is seeked back to its current
169+
* position after sending.
170+
* Non seekable streams, as well as all other types, are casted to a
171+
* string.
172+
* @param string $action One of the ACTION_* constants.
173+
* Describes the operation to perform.
164174
*
165-
* @return self|Query The query object.
175+
* @return $this The query object.
166176
*/
167177
public function andWhere($name, $value = null, $action = self::ACTION_EXIST)
168178
{
@@ -227,13 +237,18 @@ private function _send(Communicator $com)
227237
/**
228238
* Adds a condition.
229239
*
230-
* @param string $name The name of the property to test.
231-
* @param string $value The value to test against. Not required for
232-
* existence tests.
233-
* @param string $action One of the ACTION_* constants. Describes the
234-
* operation to perform.
240+
* @param string $name The name of the property to test.
241+
* @param string|resource|null $value Value of the property as a string or
242+
* seekable stream. Not required for existence tests.
243+
* If a seekable stream is provided, it is sent from its current
244+
* posistion to its end, and the pointer is seeked back to its current
245+
* position after sending.
246+
* Non seekable streams, as well as all other types, are casted to a
247+
* string.
248+
* @param string $action One of the ACTION_* constants.
249+
* Describes the operation to perform.
235250
*
236-
* @return self|Query The query object.
251+
* @return $this The query object.
237252
*/
238253
protected function addWhere($name, $value, $action)
239254
{

src/PEAR2/Net/RouterOS/Request.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __invoke($arg = null)
114114
*
115115
* @param string $command The command to send.
116116
*
117-
* @return self|Request The request object.
117+
* @return $this The request object.
118118
* @see getCommand()
119119
* @see setArgument()
120120
*/
@@ -177,7 +177,7 @@ public function getCommand()
177177
* @param Query $query The query to be set. Setting NULL will remove the
178178
* currently associated query.
179179
*
180-
* @return self|Request The request object.
180+
* @return $this The request object.
181181
* @see getQuery()
182182
*/
183183
public function setQuery(Query $query = null)
@@ -205,7 +205,7 @@ public function getQuery()
205205
*
206206
* @param string $tag The tag to set.
207207
*
208-
* @return self|Request The request object.
208+
* @return $this The request object.
209209
* @see getTag()
210210
*/
211211
public function setTag($tag)
@@ -216,11 +216,17 @@ public function setTag($tag)
216216
/**
217217
* Sets an argument for the request.
218218
*
219-
* @param string $name Name of the argument.
220-
* @param string $value Value of the argument. Setting the value to NULL
221-
* removes an argument of this name.
219+
* @param string $name Name of the argument.
220+
* @param string|resource|null $value Value of the argument as a string or
221+
* seekable stream.
222+
* Setting the value to NULL removes an argument of this name.
223+
* If a seekable stream is provided, it is sent from its current
224+
* posistion to its end, and the pointer is seeked back to its current
225+
* position after sending.
226+
* Non seekable streams, as well as all other types, are casted to a
227+
* string.
222228
*
223-
* @return self|Request The request object.
229+
* @return $this The request object.
224230
* @see getArgument()
225231
*/
226232
public function setArgument($name, $value = '')
@@ -231,7 +237,7 @@ public function setArgument($name, $value = '')
231237
/**
232238
* Removes all arguments from the request.
233239
*
234-
* @return self|Request The request object.
240+
* @return $this The request object.
235241
*/
236242
public function removeAllArguments()
237243
{

src/PEAR2/Net/RouterOS/ResponseCollection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function getArgumentMap()
311311
* @param string $type The response type to filter by. Valid values are the
312312
* Response::TYPE_* constants.
313313
*
314-
* @return ResponseCollection A new collection with responses of the
314+
* @return static A new collection with responses of the
315315
* specified type.
316316
*/
317317
public function getAllOfType($type)
@@ -320,15 +320,15 @@ public function getAllOfType($type)
320320
foreach (array_keys($this->responseTypes, $type, true) as $index) {
321321
$result[] = $this->responses[$index];
322322
}
323-
return new ResponseCollection($result);
323+
return new static($result);
324324
}
325325

326326
/**
327327
* Gets all responses with a specified tag.
328328
*
329329
* @param string $tag The tag to filter by.
330330
*
331-
* @return ResponseCollection A new collection with responses having the
331+
* @return static A new collection with responses having the
332332
* specified tag.
333333
*/
334334
public function getAllTagged($tag)
@@ -337,7 +337,7 @@ public function getAllTagged($tag)
337337
foreach (array_keys($this->responseTags, $tag, true) as $index) {
338338
$result[] = $this->responses[$index];
339339
}
340-
return new ResponseCollection($result);
340+
return new static($result);
341341
}
342342

343343
/**

0 commit comments

Comments
 (0)