Hoa central
Collection.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Praspel\Model;
38 
39 use Hoa\Iterator;
40 use Hoa\Praspel;
41 use Hoa\Visitor;
42 
52  implements Visitor\Element,
54  \ArrayAccess,
55  \Countable
56 {
62  protected $_clauses = [];
63 
69  protected $_mapping = [];
70 
76  protected $_clause = null;
77 
83  protected $_postClone = null;
84 
85 
86 
94  public function __construct(Clause $clause, \Closure $postClone = null)
95  {
96  $this->_clause = $clause;
97  $this->_postClone = $postClone;
98 
99  return;
100  }
101 
108  public function offsetExists($offset)
109  {
110  return false !== array_key_exists($offset, $this->_clauses);
111  }
112 
119  public function offsetGet($offset)
120  {
121  if (false === $this->offsetExists($offset)) {
122  $clause = $this->getClause();
123  $this->_clauses[$offset] = clone $clause;
124  $this->_mapping[] = &$this->_clauses[$offset];
125  $postClone = $this->getPostClone();
126 
127  if (null !== $postClone) {
128  $postClone($this->_clauses[$offset], $offset);
129  }
130  }
131 
132  return $this->_clauses[$offset];
133  }
134 
141  public function get($offset)
142  {
143  return $this->offsetGet($offset);
144  }
145 
152  public function getNth($position)
153  {
154  if (!isset($this->_mapping[$position])) {
155  return null;
156  }
157 
158  return $this->_mapping[$position];
159  }
160 
167  public function offsetSet($offset, $value)
168  {
169  throw new Praspel\Exception\Model('Operation denied.', 0);
170  }
171 
178  public function offsetUnset($offset)
179  {
180  throw new Praspel\Exception\Model('Operation denied.', 1);
181  }
182 
188  protected function getClause()
189  {
190  return $this->_clause;
191  }
192 
198  protected function getPostClone()
199  {
200  return $this->_postClone;
201  }
202 
208  public function getIterator()
209  {
210  return new Iterator\Map($this->_clauses);
211  }
212 
218  public function count()
219  {
220  return count($this->_clauses);
221  }
222 
231  public function accept(
232  Visitor\Visit $visitor,
233  &$handle = null,
234  $eldnah = null
235  ) {
236  return $visitor->visit($this, $handle, $eldnah);
237  }
238 }
__construct(Clause $clause,\Closure $postClone=null)
Definition: Collection.php:94
offsetSet($offset, $value)
Definition: Collection.php:167
accept(Visitor\Visit $visitor, &$handle=null, $eldnah=null)
Definition: Collection.php:231