PEAR2_Net_RouterOS  1.0.0b5
A MikroTik RouterOS client
 All Data Structures Namespaces Files Functions Variables Pages
ResponseCollection Class Reference
+ Inheritance diagram for ResponseCollection:
+ Collaboration diagram for ResponseCollection:

Public Member Functions

 __construct (array $responses)
 Creates a new collection. More...
 
 __invoke ($offset=null)
 A shorthand gateway. More...
 
 setIndex ($name)
 Sets a property to be usable as a key in the collection. More...
 
 getIndex ()
 Gets the name of the property used as an index. More...
 
 toArray ($useIndex=false)
 Gets the whole collection as an array. More...
 
 count ($mode=COUNT_NORMAL)
 Counts the responses/words in the collection. More...
 
 offsetExists ($offset)
 Checks if an offset exists. More...
 
 offsetGet ($offset)
 Gets a Response from a specified offset. More...
 
 offsetSet ($offset, $value)
 N/A. More...
 
 offsetUnset ($offset)
 N/A. More...
 
 rewind ()
 Resets the pointer to 0, and returns the first response. More...
 
 seek ($position)
 Moves the position pointer to a specified position. More...
 
 next ()
 Moves the pointer forward by 1, and gets the next response. More...
 
 current ()
 Gets the response at the current pointer position. More...
 
 prev ()
 Moves the pointer backwards by 1, and gets the previous response. More...
 
 end ()
 Moves the pointer to the last valid position, and returns the last response. More...
 
 key ()
 Gets the key at the current pointer position. More...
 
 valid ()
 Checks if the pointer is still pointing to an existing offset. More...
 
 getPropertyMap ()
 Gets all distinct property names. More...
 
 getAllOfType ($type)
 Gets all responses of a specified type. More...
 
 getAllTagged ($tag)
 Gets all responses with a specified tag. More...
 
 orderBy (array $criteria)
 Order resones by criteria. More...
 
 __call ($method, array $args)
 Calls a method of the response pointed by the pointer. More...
 

Protected Member Functions

 compare (Response $itemA, Response $itemB)
 Compares two respones. More...
 

Protected Attributes

 $responses = array()
 
 $responseTypes = array()
 
 $responseTags = array()
 
 $responsesIndex = array()
 
 $propertyMap = null
 
 $position = 0
 
 $index = null
 
 $compareBy = array()
 

Detailed Description

Definition at line 60 of file ResponseCollection.php.

Constructor & Destructor Documentation

__construct ( array  $responses)

Creates a new collection.

Parameters
array$responsesAn array of responses, in network order.

Definition at line 118 of file ResponseCollection.php.

Member Function Documentation

__call (   $method,
array  $args 
)

Calls a method of the response pointed by the pointer.

Calls a method of the response pointed by the pointer. This is a magic PHP method, thanks to which any function you call on the collection that is not defined will be redirected to the response.

Parameters
string$methodThe name of the method to call.
array$argsThe arguments to pass to the method.
Returns
mixed Whatever the called function returns.

Definition at line 510 of file ResponseCollection.php.

__invoke (   $offset = null)

A shorthand gateway.

This is a magic PHP method that allows you to call the object as a function. Depending on the argument given, one of the other functions in the class is invoked and its returned value is returned by this function.

Parameters
int | string | null$offsetThe offset of the response to seek to. If the offset is negative, seek to that relative to the end. If the collection is indexed, you can also supply a value to seek to. Setting NULL will get the current response's interator.
Returns
Response The Response at the specified index, last reponse if no index is provided or FALSE if the index is invalid or the collection is empty.

Definition at line 146 of file ResponseCollection.php.

array Criterias used by link compare ( Response  $itemA,
Response  $itemB 
)
protected

Compares two respones.

between two respones.

Compares two respones, based on criteria defined in static::$compareBy.

Parameters
Response$itemAThe response to compare.
Response$itemBThe response to compare $a against.
Returns
int Returns 0 if the two respones are equal according to every criteria specified, -1 if $a should be placed before $b, and 1 if $b should be placed before $a.

See orderBy() for a detailed description of this array's format.

Definition at line 531 of file ResponseCollection.php.

count (   $mode = COUNT_NORMAL)

Counts the responses/words in the collection.

Parameters
int$modeThe counter mode. Either COUNT_NORMAL or COUNT_RECURSIVE. When in normal mode, counts the number of responses. When in recursive mode, counts the total number of API words.
Returns
int The number of responses in the collection.

Definition at line 226 of file ResponseCollection.php.

current ( )

Gets the response at the current pointer position.

Returns
Response The response at the current pointer position, or FALSE if the position is not valid.

Definition at line 356 of file ResponseCollection.php.

end ( )

Moves the pointer to the last valid position, and returns the last response.

Returns
Response The last response in the collection, or FALSE if the collection is empty.

Definition at line 380 of file ResponseCollection.php.

getAllOfType (   $type)

Gets all responses of a specified type.

Parameters
string$typeThe response type to filter by. Valid values are the Response::TYPE_* constants.
Returns
static A new collection with responses of the specified type.

Definition at line 442 of file ResponseCollection.php.

getAllTagged (   $tag)

Gets all responses with a specified tag.

Parameters
string$tagThe tag to filter by.
Returns
static A new collection with responses having the specified tag.

Definition at line 459 of file ResponseCollection.php.

getIndex ( )

Gets the name of the property used as an index.

Returns
string|null Name of property used as index. NULL when disabled.

Definition at line 189 of file ResponseCollection.php.

getPropertyMap ( )

Gets all distinct property names.

Gets all distinct property names across all responses.

Returns
array An array with all distinct property names as keys, and the indexes at which they occur as values.

Definition at line 415 of file ResponseCollection.php.

key ( )

Gets the key at the current pointer position.

Returns
int The key at the current pointer position, i.e. the pointer position itself, or FALSE if the position is not valid.

Definition at line 392 of file ResponseCollection.php.

next ( )

Moves the pointer forward by 1, and gets the next response.

Returns
Response The next Response object, or FALSE if the position is not valid.

Definition at line 344 of file ResponseCollection.php.

offsetExists (   $offset)

Checks if an offset exists.

Parameters
int | string$offsetThe offset to check. If the collection is indexed, you can also supply a value to check. Note that negative numeric offsets are NOT accepted.
Returns
bool TRUE if the offset exists, FALSE otherwise.

Definition at line 248 of file ResponseCollection.php.

offsetGet (   $offset)

Gets a Response from a specified offset.

Parameters
int | string$offsetThe offset of the desired response. If the collection is indexed, you can also supply the value to search for.
Returns
Response The response at the specified offset.

Definition at line 263 of file ResponseCollection.php.

offsetSet (   $offset,
  $value 
)

N/A.

This method exists only because it is required for ArrayAccess. The collection is read only.

Parameters
int | string$offsetN/A
Response$valueN/A
Returns
void (PHPMD.UnusedFormalParameter)

Definition at line 284 of file ResponseCollection.php.

offsetUnset (   $offset)

N/A.

This method exists only because it is required for ArrayAccess. The collection is read only.

Parameters
int | string$offsetN/A
Returns
void (PHPMD.UnusedFormalParameter)

Definition at line 300 of file ResponseCollection.php.

orderBy ( array  $criteria)

Order resones by criteria.

Parameters
mixed[]$criteria The criteria to order respones by. It takes the form of an array where each key is the name of the property to use as (N+1)th sorting key. The value of each member can be either NULL (for that property, sort normally in ascending order), a single sort order constant (SORT_ASC or SORT_DESC) to sort normally in the specified order, an array where the first member is an order constant, and the second one is sorting flags (same as built in PHP array functions) or a callback. If a callback is provided, it must accept two arguments (the two values to be compared), and return -1, 0 or 1 if the first value is respectively less than, equal to or greather than the second one. Each key of $criteria can also be numeric, in which case the value is the name of the property, and sorting is done normally in ascending order.
Returns
static A new collection with the responses sorted in the specified order.

Definition at line 490 of file ResponseCollection.php.

prev ( )

Moves the pointer backwards by 1, and gets the previous response.

Returns
Response The next Response object, or FALSE if the position is not valid.

Definition at line 367 of file ResponseCollection.php.

rewind ( )

Resets the pointer to 0, and returns the first response.

Returns
Response The first response in the collection, or FALSE if the collection is empty.

Definition at line 311 of file ResponseCollection.php.

seek (   $position)

Moves the position pointer to a specified position.

Parameters
int | string$positionThe position to move to. If the collection is indexed, you can also supply a value to move the pointer to. A non-existent index will move the pointer to "-1".
Returns
Response The Response at the specified position, or FALSE if the specified position is not valid.

Definition at line 326 of file ResponseCollection.php.

setIndex (   $name)

Sets a property to be usable as a key in the collection.

Parameters
string | null$nameThe name of the property to use. Future calls that accept a position will then also be able to search values of that property for a matching value. Specifying NULL will disable such lookups (as is by default). Note that in case this value occures multiple times within the collection, only the last matching response will be accessible by that value.
Returns
$this The object itself.

Definition at line 166 of file ResponseCollection.php.

toArray (   $useIndex = false)

Gets the whole collection as an array.

Parameters
bool$useIndexWhether to use the index values as keys for the resulting array.
Returns
array An array with all responses, in network order.

Definition at line 202 of file ResponseCollection.php.

valid ( )

Checks if the pointer is still pointing to an existing offset.

Returns
bool TRUE if the pointer is valid, FALSE otherwise.

Definition at line 402 of file ResponseCollection.php.

Field Documentation

$compareBy = array()
protected

Definition at line 111 of file ResponseCollection.php.

$index = null
protected

Definition at line 104 of file ResponseCollection.php.

$position = 0
protected

Definition at line 99 of file ResponseCollection.php.

$propertyMap = null
protected

Definition at line 94 of file ResponseCollection.php.

$responses = array()
protected

Definition at line 66 of file ResponseCollection.php.

$responsesIndex = array()
protected

Definition at line 87 of file ResponseCollection.php.

$responseTags = array()
protected

Definition at line 76 of file ResponseCollection.php.

$responseTypes = array()
protected

Definition at line 71 of file ResponseCollection.php.


The documentation for this class was generated from the following file: