Completed
Push — prototype ( 3bfdd7...aec713 )
by Peter
07:47
created

DebuggerTrait::debugR()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Application\Traits;
12
13
use WebinoAppLib\Application;
14
use WebinoAppLib\Service\DebuggerInterface;
15
use WebinoAppLib\Service\NullDebugger;
16
17
/**
18
 * Trait Debugger
19
 */
20
trait DebuggerTrait
21
{
22
    /**
23
     * @var DebuggerInterface
24
     */
25
    private $debugger;
26
27
    /**
28
     * @param string $name
29
     * @param mixed $service
30
     */
31
    abstract protected function setServicesService($name, $service);
32
33
    /**
34
     * Set optional service from services into application
35
     *
36
     * @param string $service Service name
37
     */
38
    abstract protected function optionalService($service);
39
40
    /**
41
     * @return object|DebuggerInterface
42
     */
43
    public function getDebugger()
44
    {
45
        if (null === $this->debugger) {
46
            $this->optionalService(Application::DEBUGGER);
47
            if (null === $this->debugger) {
48
                $this->setDebugger(new NullDebugger);
49
            }
50
            $this->setServicesService(Application::DEBUGGER, $this->debugger);
51
        }
52
        return $this->debugger;
53
    }
54
55
    /**
56
     * @param object|DebuggerInterface $debugger
57
     */
58
    protected function setDebugger(DebuggerInterface $debugger)
59
    {
60
        $this->debugger = $debugger;
61
    }
62
63
    /**
64
     * Debug a variable
65
     *
66
     * @param mixed|null $var Variable to dump, or null to return debugger.
67
     * @param bool|false $return Return variable dump as string.
68
     * @return mixed|\WebinoAppLib\Debugger\DebuggingInterface
69
     */
70
    public function debug($var = null, $return = false)
71
    {
72
        if (null === $var) {
73
            return $this->getDebugger();
74
        }
75
        return $this->getDebugger()->dump($var, $return);
76
    }
77
78
    /**
79
     * Returns variable dump
80
     *
81
     * @param mixed $var
82
     * @return mixed|\WebinoAppLib\Debugger\DebuggingInterface
83
     */
84
    public function debugR($var)
85
    {
86
        return $this->debug($var, true);
87
    }
88
}
89