Completed
Push — master ( 5c3876...859b6d )
by Thierry
01:35
created

CallableClass::pg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jaxon;
4
5
class CallableClass
6
{
7
    /**
8
     * The Jaxon response returned by all classes methods
9
     *
10
     * @var \Jaxon\Response\Response
11
     */
12
    public $response = null;
13
14
    /**
15
     * Get the view renderer
16
     *
17
     * @return \Jaxon\Utils\View\Renderer
18
     */
19
    public function view()
20
    {
21
        return jaxon()->view();
22
    }
23
24
    /**
25
     * Get the session manager
26
     *
27
     * @return \Jaxon\Contracts\Session
28
     */
29
    public function session()
30
    {
31
        return jaxon()->session();
32
    }
33
34
    /**
35
     * Get the request factory.
36
     *
37
     * @return \Jaxon\Request\Factory\CallableClass\Request
38
     */
39
    public function rq()
40
    {
41
        return jaxon()->di()->getCallableClassRequestFactory(get_class($this));
42
    }
43
44
    /**
45
     * Create a JQuery Element with a given selector, and link it to the response attribute.
46
     *
47
     * @param string        $sSelector            The jQuery selector
48
     * @param string        $sContext             A context associated to the selector
49
     *
50
     * @return \Jaxon\Response\Plugin\JQuery\Dom\Element
51
     */
52
    public function jq($sSelector = '', $sContext = '')
53
    {
54
        return $this->response->plugin('jquery')->element($sSelector, $sContext);
55
    }
56
57
    /**
58
     * Get an instance of a Jaxon class by name
59
     *
60
     * @param string $name the class name
61
     *
62
     * @return CallableClass|null the Jaxon class instance, or null
63
     */
64
    public function cl($name)
65
    {
66
        $xCallableObject = jaxon()->di()->getCallableRepository()->getCallableObject(get_class($this));
67
        $cFirstChar = substr($name, 0, 1);
68
        // If the class name starts with a dot, then find the class in the same full namespace as the caller
69
        if($cFirstChar == ':')
70
        {
71
            $name = $xCallableObject->getRootNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
72
        }
73
        // If the class name starts with a dot, then find the class in the same base namespace as the caller
74
        elseif($cFirstChar == '.')
75
        {
76
            $name = $xCallableObject->getNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
77
        }
78
        // Find the class instance
79
        return jaxon()->instance($name);
80
    }
81
82
   /**
83
     * Get the uploaded files
84
     *
85
     * @return array
86
     */
87
    public function files()
88
    {
89
        return jaxon()->upload()->files();
90
    }
91
}
92