-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathStaticInstanceTrait.php
More file actions
42 lines (36 loc) · 1.06 KB
/
StaticInstanceTrait.php
File metadata and controls
42 lines (36 loc) · 1.06 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
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\base;
use Yii;
/**
* StaticInstanceTrait provides methods to satisfy [[StaticInstanceInterface]] interface.
*
* @see StaticInstanceInterface
*
* @author Paul Klimov <[email protected]>
* @since 2.0.13
*/
trait StaticInstanceTrait
{
/**
* @var static[] static instances in format: `[className => object]`
*/
private static $_instances = [];
/**
* Returns static class instance, which can be used to obtain meta information.
* @param bool $refresh whether to re-create static instance even, if it is already cached.
* @return static class instance.
*/
public static function instance($refresh = false)
{
$className = get_called_class();
if ($refresh || !isset(self::$_instances[$className])) {
self::$_instances[$className] = Yii::createObject($className);
}
return self::$_instances[$className];
}
}