Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
SwitcherCollection.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Space\Toolbar\Switcher
;
4
5
use ArrayIterator;
6
use IteratorAggregate;
7
8
class
SwitcherCollection
implements
IteratorAggregate
9
{
10
private
array $items = [];
11
12
public
function
getIterator
(): ArrayIterator
13
{
14
return
new
ArrayIterator($this->items);
15
}
16
17
public
function
has
(
AbstractSwitcher
$switcher): bool
18
{
19
return
!empty(array_filter(
20
$this->items,
21
fn (
AbstractSwitcher
$item):
bool
=>
22
$this->isEquals($item, $switcher)
23
));
24
}
25
26
public
function
add
(
AbstractSwitcher
$switcher): static
27
{
28
if
($this->
has
($switcher))
29
{
30
return
$this;
31
}
32
33
$this->items[] = $switcher;
34
return
$this;
35
}
36
37
public
function
remove
(
AbstractSwitcher
$switcher): static
38
{
39
if
(!$this->
has
($switcher))
40
{
41
return
$this;
42
}
43
44
foreach
($this->items as $key => $item)
45
{
46
if
($this->isEquals($item, $switcher))
47
{
48
unset($this->items[$key]);
49
}
50
}
51
52
return
$this;
53
}
54
55
private
function
isEquals(
AbstractSwitcher
$a,
AbstractSwitcher
$b): bool
56
{
57
return
$a::class === $b::class
58
&& $a->
getUserId
() === $b->
getUserId
()
59
&& $a->
getSpaceId
() === $b->
getSpaceId
()
60
&& $a->
getCode
() === $b->
getCode
();
61
}
62
}
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher
Definition
AbstractSwitcher.php:12
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\getUserId
getUserId()
Definition
AbstractSwitcher.php:58
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\getSpaceId
getSpaceId()
Definition
AbstractSwitcher.php:63
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\getCode
getCode()
Definition
AbstractSwitcher.php:68
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherCollection
Definition
SwitcherCollection.php:9
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherCollection\has
has(AbstractSwitcher $switcher)
Definition
SwitcherCollection.php:17
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherCollection\add
add(AbstractSwitcher $switcher)
Definition
SwitcherCollection.php:26
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherCollection\getIterator
getIterator()
Definition
SwitcherCollection.php:12
Bitrix\Socialnetwork\Space\Toolbar\Switcher
Definition
AbstractSwitcher.php:3
modules
socialnetwork
lib
Space
Toolbar
Switcher
SwitcherCollection.php
Создано системой
1.10.0