Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Socket\Connection\Group Class Reference
Inheritance diagram for Hoa\Socket\Connection\Group:

Public Member Functions

 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $connection)
 
 offsetUnset ($offset)
 
 getIterator ()
 
 count ()
 
 merge (Handler $connection)
 
 run ()
 
 getFirstConnection ()
 

Protected Attributes

 $_connections = []
 

Detailed Description

Class .

Represent a group of connection handlers. Add semantics around Hoa.

Definition at line 50 of file Group.php.

Member Function Documentation

Hoa\Socket\Connection\Group::count ( )

Count number of declared connections.

Returns
int

Definition at line 151 of file Group.php.

152  {
153  return count($this->_connections);
154  }

Here is the caller graph for this function:

Hoa\Socket\Connection\Group::getFirstConnection ( )

Get the first declared connection (where other connections have been merged).

Returns

Definition at line 194 of file Group.php.

195  {
196  return $this[key($this->_connections)];
197  }

Here is the caller graph for this function:

Hoa\Socket\Connection\Group::getIterator ( )

Get iterator of all declared connections.

Returns

Definition at line 141 of file Group.php.

142  {
143  return new \ArrayIterator($this->_connections);
144  }
Hoa\Socket\Connection\Group::merge ( Handler  $connection)

Semantics alias of $this->offsetSet(null, $connection).

Parameters
\Hoa\Socket\Connection\Handler$connectionConnection (handler).
Returns

Definition at line 163 of file Group.php.

164  {
165  $this[] = $connection;
166 
167  return $this;
168  }
Hoa\Socket\Connection\Group::offsetExists (   $offset)

Check if a connection offset exists.

Parameters
mixed$offsetOffset.
Returns
bool

Definition at line 67 of file Group.php.

68  {
69  return true === array_key_exists($offset, $this->_connections);
70  }

Here is the caller graph for this function:

Hoa\Socket\Connection\Group::offsetGet (   $offset)

Get a specific connection.

Parameters
mixed$offsetOffset.
Returns

Definition at line 78 of file Group.php.

79  {
80  if (false === $this->offsetExists($offset)) {
81  return null;
82  }
83 
84  return $this->_connections[$offset];
85  }

Here is the call graph for this function:

Hoa\Socket\Connection\Group::offsetSet (   $offset,
  $connection 
)

Add a connection.

Parameters
mixed$offsetOffset.
\Hoa\Socket\Connection\Handler$connectionConnection (handler).
Returns
void
Exceptions

Definition at line 96 of file Group.php.

97  {
98  if (!($connection instanceof Handler)) {
99  throw new Socket\Exception(
100  '%s only accepts %s\Handler objects.',
101  0,
102  [__CLASS__, __NAMESPACE__]
103  );
104  }
105 
106  if (null === $offset) {
107  $this->_connections[] = $connection;
108  } else {
109  $this->_connections[$offset] = $connection;
110  }
111 
112  if (1 < count($this)) {
113  $this->getFirstConnection()->merge($connection);
114  }
115 
116  return;
117  }

Here is the call graph for this function:

Hoa\Socket\Connection\Group::offsetUnset (   $offset)

Nothing (not allowed).

Returns
void
Exceptions

Definition at line 125 of file Group.php.

126  {
127  throw new Socket\Exception(
128  'This operation is not allowed: you cannot unset a connection ' .
129  'from a group.',
130  1
131  );
132 
133  return;
134  }
Hoa\Socket\Connection\Group::run ( )

Run the group of connections.

Returns
void
Exceptions

Definition at line 176 of file Group.php.

177  {
178  if (0 === count($this)) {
179  throw new Socket\Exception(
180  'Nothing to run. You should merge a connection.',
181  2
182  );
183  }
184 
185  return $this->getFirstConnection()->run();
186  }

Here is the call graph for this function:

Member Data Documentation

Hoa\Socket\Connection\Group::$_connections = []
protected

Definition at line 57 of file Group.php.


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