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