-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aware.php
34 lines (31 loc) · 863 Bytes
/
Aware.php
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
<?php
/**
* @link https://github.com/ryanve/traits
*/
namespace traits;
use \ReflectionClass;
trait Aware {
/**
* @return ReflectionClass
*/
static function reflect($class = null) {
return new ReflectionClass(null === $class ? get_called_class() : $class);
}
/**
* @description Create a new instance of the current class.
* @return object
*/
static function instantiate() {
return static::reflect()->newInstanceArgs(func_get_args());
}
/**
* @description Get or set the current context. For this to work, the calling
* class must call `static::context($this)` in its constructor or elsewhere.
* @return object
*/
static function context($ob = null) {
static $curr;
$class = __CLASS__;
return $curr = null === $ob ? ($curr ?: new $class) : ($ob instanceof $class ? $ob : new $class($ob));
}
}