Completed
Push — master ( 5bbdfe...13b325 )
by Mihail
04:51
created

Singleton::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Ffcms\Core\Traits;
4
5
/**
6
 * Class Singleton. Basic structure of singleton pattern.
7
 * @package Ffcms\Core\Traits
8
 */
9
trait Singleton
10
{
11
    protected static $instance;
12
13
    /**
14
     * @return static
15
     */
16
    final public static function instance()
17
    {
18
        if (!isset(static::$instance)) {
19
            static::$instance = new static;
20
            static::boot();
21
        }
22
        return static::$instance;
23
    }
24
    
25
    public static function boot() {}
26
27
    /**
28
     * Override constructor
29
     */
30
    final private function __construct() {
31
        $this->init();
32
    }
33
34
    // disable some magic
35
    protected function init() {}
36
    final private function __wakeup() {}
37
    final private function __clone() {}
38
}