Completed
Push — master ( 2cf3a8...d0ec23 )
by Derek Stephen
05:43
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
14
    /**
15
     * @param $key
16
     * @return mixed
17
     */
18
    public function getContainerObject($key)
19
    {
20
        return ContainerService::getInstance()->getContainer()[$key];
21
    }
22
23
    /**
24
     *
25
     */
26
    public function sendJSONResponse(array $array)
27
    {
28
        Zend_Layout::getMvcInstance()->disableLayout();
29
        $this->_helper->viewRenderer->setNoRender();
30
        $this->getResponse()->setHeader('Content-Type', 'application/json');
31
        $this->_helper->json($array);
32
    }
33
34
    public function getIdentity()
35
    {
36
        if(Zend_Auth::getInstance()->hasIdentity()) {
37
            return Zend_Auth::getInstance()->getIdentity();
38
        }
39
        throw new Exception('No Identity.');
40
    }
41
}