1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TCollectionSubscription classes |
4
|
|
|
* |
5
|
|
|
* @author Brad Anderson <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @link https://github.com/pradosoft/prado |
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Prado\Collections; |
12
|
|
|
|
13
|
|
|
use ArrayAccess; |
14
|
|
|
use WeakReference; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* TCollectionSubscription class. |
18
|
|
|
* |
19
|
|
|
* This class does the same thing as TArraySubscription except it does not pass |
20
|
|
|
* by reference. This will work with ArrayAccess objects but will not work with |
21
|
|
|
* PHP arrays. |
22
|
|
|
* |
23
|
|
|
* This has the property Collection that provides Array access without passing by |
24
|
|
|
* reference. |
25
|
|
|
* |
26
|
|
|
* @author Brad Anderson <[email protected]> |
27
|
|
|
* @since 4.2.3 |
28
|
|
|
*/ |
29
|
|
|
class TCollectionSubscription extends TArraySubscription |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
* @param ?ArrayAccess $collection The collection object being subscribed. |
34
|
|
|
* Default null. |
35
|
|
|
* @param mixed $key The key of the subscription item. Default null. |
36
|
|
|
* @param mixed $item The item being subscribed to the collection. |
37
|
|
|
* Default null. |
38
|
|
|
* @param null|float|int $priority The priority of the item. Default null. |
39
|
|
|
* @param null|bool|int $isAssociative Is the collection associative. this is |
40
|
|
|
* automatically set for TList and TMap. |
41
|
|
|
* @param ?bool $autoSubscribe Default null for autoSubscribing when there is a |
42
|
|
|
* key or item. |
43
|
|
|
*/ |
44
|
|
|
public function __construct(?ArrayAccess $collection = null, mixed $key = null, mixed $item = null, null|int|float $priority = null, null|bool|int $isAssociative = 1, ?bool $autoSubscribe = null) |
45
|
|
|
{ |
46
|
|
|
parent::__construct($collection, $key, $item, $priority, $isAssociative, $autoSubscribe); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The ArrayAccess collection for getting the array without pass by reference. |
51
|
|
|
* @param bool $weak Return the collection in as a WeakReference. |
52
|
|
|
*/ |
53
|
|
|
public function getCollection(bool $weak = false): null|ArrayAccess|WeakReference |
54
|
|
|
{ |
55
|
|
|
return $this->getArray($weak); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The ArrayAccess collection for setting the array without pass by reference. |
60
|
|
|
* @param ?ArrayAccess $value |
61
|
|
|
* @return static The current object. |
62
|
|
|
*/ |
63
|
|
|
public function setCollection(?ArrayAccess $value): static |
64
|
|
|
{ |
65
|
|
|
return $this->setArray($value); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|