Bitrix-D7  20.0.0
collectionbase.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage sale
6  * @copyright 2001-2012 Bitrix
7  */
8 namespace Bitrix\Sale\Internals;
9 
11 
12 Loc::loadMessages(__FILE__);
13 
14 /**
15  * Class CollectionBase
16  * @package Bitrix\Sale\Internals
17  */
18 abstract class CollectionBase
19  implements \ArrayAccess, \Countable, \IteratorAggregate
20 {
21  protected $collection = array();
22 
23  /**
24  * @return \ArrayIterator
25  */
26  public function getIterator()
27  {
28  return new \ArrayIterator($this->collection);
29  }
30 
31 
32  /**
33  * Whether a offset exists
34  */
35  public function offsetExists($offset)
36  {
37  return isset($this->collection[$offset]) || array_key_exists($offset, $this->collection);
38  }
39 
40  /**
41  * Offset to retrieve
42  */
43  public function offsetGet($offset)
44  {
45  if (isset($this->collection[$offset]) || array_key_exists($offset, $this->collection))
46  {
47  return $this->collection[$offset];
48  }
49 
50  return null;
51  }
52 
53  /**
54  * Offset to set
55  */
56  public function offsetSet($offset, $value)
57  {
58  if($offset === null)
59  {
60  $this->collection[] = $value;
61  }
62  else
63  {
64  $this->collection[$offset] = $value;
65  }
66  }
67 
68  /**
69  * Offset to unset
70  */
71  public function offsetUnset($offset)
72  {
73  unset($this->collection[$offset]);
74  }
75 
76  /**
77  * Count elements of an object
78  */
79  public function count()
80  {
81  return count($this->collection);
82  }
83 
84  /**
85  * Return the current element
86  */
87  public function current()
88  {
89  return current($this->collection);
90  }
91 
92  /**
93  * Move forward to next element
94  */
95  public function next()
96  {
97  return next($this->collection);
98  }
99 
100  /**
101  * Return the key of the current element
102  */
103  public function key()
104  {
105  return key($this->collection);
106  }
107 
108  /**
109  * Checks if current position is valid
110  */
111  public function valid()
112  {
113  $key = $this->key();
114  return $key !== null;
115  }
116 
117  /**
118  * Rewind the Iterator to the first element
119  */
120  public function rewind()
121  {
122  return reset($this->collection);
123  }
124 
125  /**
126  * Checks if collection is empty.
127  *
128  * @return bool
129  */
130  public function isEmpty()
131  {
132  return empty($this->collection);
133  }
134 }
Bitrix\Sale\Internals\CollectionBase\valid
valid()
Checks if current position is valid.
Definition: collectionbase.php:111
Bitrix\Sale\Internals\CollectionBase\rewind
rewind()
Rewind the Iterator to the first element.
Definition: collectionbase.php:120
Bitrix\Sale\Internals\CollectionBase\getIterator
getIterator()
Definition: collectionbase.php:26
Bitrix\Sale\Internals\CollectionBase
Definition: collectionbase.php:18
Bitrix\Sale\Internals\CollectionBase\offsetSet
offsetSet($offset, $value)
Offset to set.
Definition: collectionbase.php:56
Bitrix\Sale\Internals\CollectionBase\count
count()
Count elements of an object.
Definition: collectionbase.php:79
Bitrix\Sale\Internals\CollectionBase\$collection
$collection
Definition: collectionbase.php:21
Bitrix\Sale\Internals\CollectionBase\offsetUnset
offsetUnset($offset)
Offset to unset.
Definition: collectionbase.php:71
Bitrix\Sale\Internals
Definition: accountnumber.php:3
Bitrix\Sale\Internals\CollectionBase\offsetExists
offsetExists($offset)
Whether a offset exists.
Definition: collectionbase.php:35
Bitrix\Sale\Internals\CollectionBase\isEmpty
isEmpty()
Checks if collection is empty.
Definition: collectionbase.php:130
Bitrix\Main\Localization\Loc
Definition: loc.php:10
Bitrix\Sale\Internals\CollectionBase\key
key()
Return the key of the current element.
Definition: collectionbase.php:103
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Loads language messages for specified file in a lazy way.
Definition: loc.php:67
Bitrix\Sale\Internals\CollectionBase\current
current()
Return the current element.
Definition: collectionbase.php:87
Bitrix\Sale\Internals\CollectionBase\offsetGet
offsetGet($offset)
Offset to retrieve.
Definition: collectionbase.php:43
Bitrix\Sale\Internals\CollectionBase\next
next()
Move forward to next element.
Definition: collectionbase.php:95