Completed
Push — master ( 3c2ce2...009b85 )
by Derek Stephen
05:24
created

AbstractController::sendJSONResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
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
}