forked from kevinowino869/mitrobill
update PEAR
This commit is contained in:
@ -2,17 +2,18 @@
|
||||
|
||||
/**
|
||||
* RouterOS API client implementation.
|
||||
*
|
||||
|
||||
*
|
||||
* RouterOS is the flag product of the company MikroTik and is a powerful router software. One of its many abilities is to allow control over it via an API. This package provides a client for that API, in turn allowing you to use PHP to control RouterOS hosts.
|
||||
*
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
*
|
||||
* @category Net
|
||||
* @package PEAR2_Net_RouterOS
|
||||
* @author Vasil Rangelov <boen.robot@gmail.com>
|
||||
* @copyright 2011 Vasil Rangelov
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version 1.0.0b5
|
||||
* @version 1.0.0b6
|
||||
* @link http://pear2.php.net/PEAR2_Net_RouterOS
|
||||
*/
|
||||
/**
|
||||
@ -32,7 +33,7 @@ use Exception as E;
|
||||
|
||||
/**
|
||||
* Represents a RouterOS response.
|
||||
*
|
||||
*
|
||||
* @category Net
|
||||
* @package PEAR2_Net_RouterOS
|
||||
* @author Vasil Rangelov <boen.robot@gmail.com>
|
||||
@ -41,22 +42,22 @@ use Exception as E;
|
||||
*/
|
||||
class Response extends Message
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* The last response for a request.
|
||||
*/
|
||||
const TYPE_FINAL = '!done';
|
||||
|
||||
|
||||
/**
|
||||
* A response with data.
|
||||
*/
|
||||
const TYPE_DATA = '!re';
|
||||
|
||||
|
||||
/**
|
||||
* A response signifying error.
|
||||
*/
|
||||
const TYPE_ERROR = '!trap';
|
||||
|
||||
|
||||
/**
|
||||
* A response signifying a fatal error, due to which the connection would be
|
||||
* terminated.
|
||||
@ -64,28 +65,32 @@ class Response extends Message
|
||||
const TYPE_FATAL = '!fatal';
|
||||
|
||||
/**
|
||||
* @var array An array of unrecognized words in network order.
|
||||
* An array of unrecognized words in network order.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $unrecognizedWords = array();
|
||||
|
||||
/**
|
||||
* @var string The response type.
|
||||
* The response type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_type;
|
||||
|
||||
/**
|
||||
* Extracts a new response from a communicator.
|
||||
*
|
||||
* @param Communicator $com The communicator from which to extract
|
||||
*
|
||||
* @param Communicator $com The communicator from which to extract
|
||||
* the new response.
|
||||
* @param bool $asStream Whether to populate the argument values
|
||||
* @param bool $asStream Whether to populate the argument values
|
||||
* with streams instead of strings.
|
||||
* @param int $sTimeout If a response is not immediatly
|
||||
* available, wait this many seconds. If NULL, wait indefinetly.
|
||||
* @param int $usTimeout Microseconds to add to the waiting time.
|
||||
* @param Registry $reg An optional registry to sync the
|
||||
* @param int $sTimeout If a response is not immediately
|
||||
* available, wait this many seconds. If NULL, wait indefinitely.
|
||||
* @param int|null $usTimeout Microseconds to add to the waiting time.
|
||||
* @param Registry|null $reg An optional registry to sync the
|
||||
* response with.
|
||||
*
|
||||
*
|
||||
* @see getType()
|
||||
* @see getArgument()
|
||||
*/
|
||||
@ -120,12 +125,12 @@ class Response extends Message
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->_type = $response->_type;
|
||||
$this->attributes = $response->attributes;
|
||||
$this->unrecognizedWords = $response->unrecognizedWords;
|
||||
$this->setTag($response->getTag());
|
||||
|
||||
|
||||
if (!$asStream) {
|
||||
foreach ($this->attributes as $name => $value) {
|
||||
$this->setAttribute(
|
||||
@ -139,23 +144,23 @@ class Response extends Message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts a new response from a communicator.
|
||||
*
|
||||
*
|
||||
* This is the function that performs the actual receiving, while the
|
||||
* constructor is also involved in locks and registry sync.
|
||||
*
|
||||
*
|
||||
* @param Communicator $com The communicator from which to extract
|
||||
* the new response.
|
||||
* @param bool $asStream Whether to populate the argument values
|
||||
* with streams instead of strings.
|
||||
* @param int $sTimeout If a response is not immediatly
|
||||
* available, wait this many seconds. If NULL, wait indefinetly.
|
||||
* @param int $sTimeout If a response is not immediately
|
||||
* available, wait this many seconds. If NULL, wait indefinitely.
|
||||
* Note that if an empty sentence is received, the timeout will be
|
||||
* reset for another sentence receiving.
|
||||
* @param int $usTimeout Microseconds to add to the waiting time.
|
||||
*
|
||||
* @param int|null $usTimeout Microseconds to add to the waiting time.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _receive(
|
||||
@ -228,12 +233,13 @@ class Response extends Message
|
||||
|
||||
/**
|
||||
* Sets the response type.
|
||||
*
|
||||
*
|
||||
* Sets the response type. Valid values are the TYPE_* constants.
|
||||
*
|
||||
*
|
||||
* @param string $type The new response type.
|
||||
*
|
||||
*
|
||||
* @return $this The response object.
|
||||
*
|
||||
* @see getType()
|
||||
*/
|
||||
protected function setType($type)
|
||||
@ -257,8 +263,9 @@ class Response extends Message
|
||||
|
||||
/**
|
||||
* Gets the response type.
|
||||
*
|
||||
*
|
||||
* @return string The response type.
|
||||
*
|
||||
* @see setType()
|
||||
*/
|
||||
public function getType()
|
||||
@ -268,12 +275,13 @@ class Response extends Message
|
||||
|
||||
/**
|
||||
* Gets the value of an argument.
|
||||
*
|
||||
*
|
||||
* @param string $name The name of the argument.
|
||||
*
|
||||
*
|
||||
* @return string|resource|null The value of the specified argument.
|
||||
* Returns NULL if such an argument is not set.
|
||||
* @deprecated 1.0.0b5 Use {@link static::getProperty()} instead.
|
||||
*
|
||||
* @deprecated 1.0.0b5 Use {@link static::getProperty()} instead.
|
||||
* This method will be removed upon final release, and is currently
|
||||
* left standing merely because it can't be easily search&replaced in
|
||||
* existing code, due to the fact the name "getArgument()" is shared
|
||||
@ -293,9 +301,9 @@ class Response extends Message
|
||||
|
||||
/**
|
||||
* Gets the value of a property.
|
||||
*
|
||||
*
|
||||
* @param string $name The name of the property.
|
||||
*
|
||||
*
|
||||
* @return string|resource|null The value of the specified property.
|
||||
* Returns NULL if such a property is not set.
|
||||
*/
|
||||
@ -306,30 +314,11 @@ class Response extends Message
|
||||
|
||||
/**
|
||||
* Gets a list of unrecognized words.
|
||||
*
|
||||
* @return array The list of unrecognized words.
|
||||
*
|
||||
* @return string[] The list of unrecognized words.
|
||||
*/
|
||||
public function getUnrecognizedWords()
|
||||
{
|
||||
return $this->unrecognizedWords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of arguments or words.
|
||||
*
|
||||
* @param int $mode The counter mode.
|
||||
* Either COUNT_NORMAL or COUNT_RECURSIVE.
|
||||
* When in normal mode, counts the number of arguments.
|
||||
* When in recursive mode, counts the number of API words.
|
||||
*
|
||||
* @return int The number of arguments/words.
|
||||
*/
|
||||
public function count($mode = COUNT_NORMAL)
|
||||
{
|
||||
$result = parent::count($mode);
|
||||
if ($mode !== COUNT_NORMAL) {
|
||||
$result += count($this->unrecognizedWords);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user