1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Composite Utils package. |
4
|
|
|
* |
5
|
|
|
* (c) Emily Shepherd <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the |
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @package spaark/composite-utils |
11
|
|
|
* @author Emily Shepherd <[email protected]> |
12
|
|
|
* @license MIT |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Spaark\CompositeUtils\Traits; |
16
|
|
|
|
17
|
|
|
use Spaark\CompositeUtils\Factory\Reflection\ReflectionCompositeFactory; |
18
|
|
|
use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Classes with this trait have a ReflectionComposite |
22
|
|
|
*/ |
23
|
|
|
trait HasReflectorTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The reflection information for this composite |
27
|
|
|
* |
28
|
|
|
* @var ReflectionComposite |
29
|
|
|
*/ |
30
|
|
|
protected static $reflectionComposite; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns the ReflectionComposite for this object, or constructs |
34
|
|
|
* one on the fly if one does not yet exist, using a |
35
|
|
|
* ReflectionCompositeFactory |
36
|
|
|
* |
37
|
|
|
* @return ReflectionComposite |
38
|
|
|
*/ |
39
|
7 |
|
protected static function getReflectionComposite() |
40
|
|
|
{ |
41
|
7 |
|
if (!static::$reflectionComposite) |
42
|
|
|
{ |
43
|
|
|
static::$reflectionComposite = |
44
|
2 |
|
ReflectionCompositeFactory::fromClassName |
45
|
|
|
( |
46
|
|
|
get_called_class() |
47
|
|
|
) |
48
|
2 |
|
->build(); |
49
|
|
|
} |
50
|
|
|
|
51
|
7 |
|
return static::$reflectionComposite; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the default ReflectionComposite for this class |
56
|
|
|
*/ |
57
|
|
|
protected static function setDefaultReflectionComposite |
58
|
|
|
( |
59
|
|
|
ReflectionComposite $defaultReflectionComposite |
60
|
|
|
) |
61
|
|
|
{ |
62
|
|
|
static::$reflectionComposite = $defaultReflectionComposite; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|