o2system /
spl
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the O2System Framework package. |
||
| 4 | * |
||
| 5 | * For the full copyright and license information, please view the LICENSE |
||
| 6 | * file that was distributed with this source code. |
||
| 7 | * |
||
| 8 | * @author Steeve Andrian Salim |
||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
| 10 | */ |
||
| 11 | |||
| 12 | // ------------------------------------------------------------------------ |
||
| 13 | |||
| 14 | namespace O2System\Spl\Containers\DataStructures; |
||
| 15 | |||
| 16 | // ------------------------------------------------------------------------ |
||
| 17 | |||
| 18 | use O2System\Spl\Info\SplClassInfo; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Class SplServiceRegistry |
||
| 22 | * |
||
| 23 | * @package O2System\Spl\Containers\DataStructures |
||
| 24 | */ |
||
| 25 | class SplServiceRegistry extends SplClassInfo |
||
| 26 | {
|
||
| 27 | /** |
||
| 28 | * Service Singleton Instance |
||
| 29 | * |
||
| 30 | * @var object |
||
| 31 | */ |
||
| 32 | private $instance; |
||
| 33 | |||
| 34 | public function __construct($service) |
||
| 35 | {
|
||
| 36 | if (is_object($service)) {
|
||
| 37 | $this->instance = $service; |
||
| 38 | $service = get_class($service); |
||
| 39 | } |
||
| 40 | |||
| 41 | parent::__construct($service); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getClassName() |
||
| 45 | {
|
||
| 46 | return get_class_name($this->name); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 47 | } |
||
| 48 | |||
| 49 | public function &getInstance() |
||
| 50 | {
|
||
| 51 | if (empty($this->instance)) {
|
||
| 52 | if (null !== ($constructor = $this->getConstructor())) {
|
||
| 53 | $args = func_get_args(); |
||
| 54 | |||
| 55 | if (count($args)) {
|
||
| 56 | $this->instance = $this->newInstance(); |
||
| 57 | } else {
|
||
| 58 | $this->instance = $this->newInstanceArgs(func_get_args()); |
||
| 59 | } |
||
| 60 | } else {
|
||
| 61 | $this->instance = $this->newInstanceWithoutConstructor(); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | return $this->instance; |
||
| 66 | } |
||
| 67 | } |