forked from lesstif/php-JiraCloud-RESTAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicPropertiesTrait.php
More file actions
61 lines (54 loc) · 1.41 KB
/
Copy pathDynamicPropertiesTrait.php
File metadata and controls
61 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace JiraCloud;
/**
* Defines a trait that allows to dynamically assign properties to objects as this has been deprecated in PHP8.2.
*/
trait DynamicPropertiesTrait
{
/** @var array<string, mixed> */
protected array $dynamicProperties = [];
/**
* Attempts to retrieve a dynamic property from {@link static::$dynamicProperties}.
*
* @param string $name
*
* @return mixed The requested value if found, `null` otherwise.
*/
public function __get(string $name): mixed
{
return $this->dynamicProperties[$name] ?? null;
}
/**
* Returns whether the dynamic property `$name` is set (not `null`!) in {@link static::$dynamicProperties}.
*
* @param string $name
*
* @return bool
*/
public function __isset(string $name): bool
{
return isset($this->dynamicProperties[$name]);
}
/**
* Applies `$value` using `$name` as key on {@link static::$dynamicProperties}.
*
* @param string $name
* @param mixed $value
*
* @return void
*/
public function __set(string $name, mixed $value): void
{
$this->dynamicProperties[$name] = $value;
}
/**
* Accessor for {@link static::$dynamicProperties}.
*
* @return array
*/
public function getDynamicProperties(): array
{
return $this->dynamicProperties;
}
}