AbstractController::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Del\Common\ZF1\Controller;
4
5
use Del\Common\ContainerService;
6
use Exception;
7
use Zend_Auth;
8
use Zend_Controller_Action;
9
use Zend_Layout;
10
11
class AbstractController extends Zend_Controller_Action
12
{
13
    protected $container;
14
15
    public function init()
16
    {
17
        $this->container = ContainerService::getInstance()->getContainer();
18
    }
19
20
    /**
21
     * @param $key
22
     * @return mixed
23
     */
24
    public function getContainerObject($key)
25
    {
26
        return $this->container[$key];
27
    }
28
29
    /**
30
     *
31
     */
32
    public function sendJSONResponse(array $array)
33
    {
34
        Zend_Layout::getMvcInstance()->disableLayout();
35
        $this->_helper->viewRenderer->setNoRender();
36
        $this->getResponse()->setHeader('Content-Type', 'application/json');
37
        $this->_helper->json($array);
38
    }
39
40
    public function getIdentity()
41
    {
42
        if(Zend_Auth::getInstance()->hasIdentity()) {
43
            return Zend_Auth::getInstance()->getIdentity();
44
        }
45
        throw new Exception('No Identity.');
46
    }
47
48
    /**
49
     * @return Zend_Controller_Request_Http
50
     */
51
    public function getRequest()
52
    {
53
        return parent::getRequest();
54
    }
55
}