ServerGroveLiveChat /src/ServerGrove/SGLiveChatBundle/Controller/BaseController.php

Language PHP Lines 102
MD5 Hash 5e831762d1e02dc4c885bc40c7a9f4b8
Repository https://github.com/casoetan/ServerGroveLiveChat.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
<?php

namespace ServerGrove\SGLiveChatBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Session as SessionStorage;
use Doctrine\ODM\MongoDB\DocumentManager;

/**
 * Chat's base controller
 *
 * @author Ismael Ambrosi<ismael@servergrove.com>
 */
abstract class BaseController extends Controller
{

    private $request, $response, $session, $dm;

    /**
     * @return Symfony\Component\HttpFoundation\Request
     */
    public function getRequest()
    {
        if (is_null($this->request)) {
            $this->request = $this->get('request');
        }
        return $this->request;
    }

    /**
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function getResponse()
    {
        if (is_null($this->response)) {
            $this->response = new Response();
        }
        return $this->response;
    }

    /**
     * @return Symfony\Component\HttpFoundation\Session
     */
    public function getSessionStorage()
    {
        if (is_null($this->session)) {
            $this->session = $this->getRequest()->getSession();
        }
        return $this->session;
    }

    /**
     * @return Doctrine\ODM\MongoDB\DocumentManager
     */
    public function getDocumentManager()
    {
        if (is_null($this->dm)) {
            $this->dm = $this->get('doctrine.odm.mongodb.document_manager');
        }
        return $this->dm;
    }

    /**
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function renderTemplate($view, array $parameters = array())
    {
        return $this->render($view, $parameters, $this->getResponse());
    }

    /**
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function redirect($url, $status = 302)
    {
        $this->getResponse()->setRedirect($url, $status);
        return $this->getResponse();
    }

    /**
     * @return ServerGrove\SGLiveChatBundle\Document\Operator
     */
    protected function getOperator()
    {
        if (!$this->getSessionStorage()->has('_operator')) {
            return null;
        }
        return $this->getDocumentManager()->find('SGLiveChatBundle:Operator', $this->getSessionStorage()->get('_operator'));
    }

    /**
     * @return Symfony\Bundle\ZendBundle\Logger\Logger
     */
    protected function getLogger()
    {
        return $this->container->get('logger');
    }

}
Back to Top