Completed
Push — master ( 0b8712...2f8bc7 )
by Mihail
04:21
created

DynamicGlobal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 3
c 5
b 2
f 0
lcom 0
cbo 1
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 4 1
A __get() 0 5 1
A __isset() 0 4 1
1
<?php
2
3
namespace Ffcms\Core\Traits;
4
5
use Ffcms\Core\Template\Variables;
6
7
/**
8
 * Special street magic class for extending MVC model usage $this->undefined from any places.
9
 * Class DynamicProperty
10
 * @package Ffcms\Core\Arch\Constructors
11
 */
12
trait DynamicGlobal
13
{
14
    /**
15
     * Set global variable for magic callback on MVC apps $this->var = value
16
     * @param $var
17
     * @param $value
18
     */
19
    final public function __set($var, $value)
20
    {
21
        Variables::instance()->setGlobal($var, $value);
22
    }
23
24
    /**
25
     * Get variable from MVC model on magic callback $this->var
26
     * @param $var
27
     * @return mixed
28
     */
29
    final public function __get($var)
30
    {
31
        $globals = Variables::instance()->getGlobalsArray();
32
        return $globals[$var];
33
    }
34
35
    /**
36
     * Check if global variable exists for isset and empty methods. In php 7.0.6 without this definition warning occurred.
37
     * @param string $var
38
     * @return bool
39
     */
40
    final public function __isset($var)
41
    {
42
        return Variables::instance()->issetGlobal($var);
43
    }
44
}