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

AbstractController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 0
cbo 1
dl 0
loc 37
ccs 0
cts 22
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A getContainerObject() 0 4 1
A sendJSONResponse() 0 7 1
A getIdentity() 0 7 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
}