Extend the Web bootstrapper from the EmbeddedWeb bootstrapper

In a embedded web environment we may also need a request and response.

refs #9702
This commit is contained in:
Johannes Meyer 2015-08-06 15:08:41 +02:00
parent 4c00d5effc
commit 59ef54314a
2 changed files with 68 additions and 66 deletions

View File

@ -5,6 +5,9 @@ namespace Icinga\Application;
require_once dirname(__FILE__) . '/ApplicationBootstrap.php'; require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
use Icinga\Web\Request;
use Icinga\Web\Response;
/** /**
* Use this if you want to make use of Icinga functionality in other web projects * Use this if you want to make use of Icinga functionality in other web projects
* *
@ -16,6 +19,40 @@ require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
*/ */
class EmbeddedWeb extends ApplicationBootstrap class EmbeddedWeb extends ApplicationBootstrap
{ {
/**
* Request object
*
* @var Request
*/
protected $request;
/**
* Response
*
* @var Response
*/
protected $response;
/**
* Get the request
*
* @return Request
*/
public function getRequest()
{
return $this->request;
}
/**
* Get the response
*
* @return Response
*/
public function getResponse()
{
return $this->response;
}
/** /**
* Embedded bootstrap parts * Embedded bootstrap parts
* *
@ -26,10 +63,34 @@ class EmbeddedWeb extends ApplicationBootstrap
{ {
return $this return $this
->setupZendAutoloader() ->setupZendAutoloader()
->loadConfig()
->setupErrorHandling() ->setupErrorHandling()
->loadConfig()
->setupRequest()
->setupResponse()
->setupTimezone() ->setupTimezone()
->setupModuleManager() ->setupModuleManager()
->loadEnabledModules(); ->loadEnabledModules();
} }
/**
* Set the request
*
* @return $this
*/
protected function setupRequest()
{
$this->request = new Request();
return $this;
}
/**
* Set the response
*
* @return $this
*/
protected function setupResponse()
{
$this->response = new Response();
return $this;
}
} }

View File

@ -3,7 +3,7 @@
namespace Icinga\Application; namespace Icinga\Application;
require_once __DIR__ . '/ApplicationBootstrap.php'; require_once __DIR__ . '/EmbeddedWeb.php';
use Zend_Controller_Action_HelperBroker; use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Front; use Zend_Controller_Front;
@ -11,14 +11,11 @@ use Zend_Controller_Router_Route;
use Zend_Layout; use Zend_Layout;
use Zend_Paginator; use Zend_Paginator;
use Zend_View_Helper_PaginationControl; use Zend_View_Helper_PaginationControl;
use Icinga\Application\Logger;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\User; use Icinga\User;
use Icinga\Util\TimezoneDetect; use Icinga\Util\TimezoneDetect;
use Icinga\Util\Translator; use Icinga\Util\Translator;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\Request;
use Icinga\Web\Response;
use Icinga\Web\Session; use Icinga\Web\Session;
use Icinga\Web\Session\Session as BaseSession; use Icinga\Web\Session\Session as BaseSession;
use Icinga\Web\View; use Icinga\Web\View;
@ -28,11 +25,11 @@ use Icinga\Web\View;
* *
* Usage example: * Usage example:
* <code> * <code>
* use Icinga\Application\EmbeddedWeb; * use Icinga\Application\Web;
* EmbeddedWeb::start(); * Web::start();
* </code> * </code>
*/ */
class Web extends ApplicationBootstrap class Web extends EmbeddedWeb
{ {
/** /**
* View object * View object
@ -48,20 +45,6 @@ class Web extends ApplicationBootstrap
*/ */
private $frontController; private $frontController;
/**
* Request object
*
* @var Request
*/
private $request;
/**
* Response
*
* @var Response
*/
protected $response;
/** /**
* Session object * Session object
* *
@ -145,26 +128,6 @@ class Web extends ApplicationBootstrap
return $this->frontController; return $this->frontController;
} }
/**
* Get the request
*
* @return Request
*/
public function getRequest()
{
return $this->request;
}
/**
* Get the response
*
* @return Response
*/
public function getResponse()
{
return $this->response;
}
/** /**
* Getter for view * Getter for view
* *
@ -211,7 +174,7 @@ class Web extends ApplicationBootstrap
$auth = Auth::getInstance(); $auth = Auth::getInstance();
if ($auth->isAuthenticated()) { if ($auth->isAuthenticated()) {
$user = $auth->getUser(); $user = $auth->getUser();
$this->request->setUser($user); $this->getRequest()->setUser($user);
$this->user = $user; $this->user = $user;
} }
return $this; return $this;
@ -239,28 +202,6 @@ class Web extends ApplicationBootstrap
return $this; return $this;
} }
/**
* Set the request
*
* @return $this
*/
private function setupRequest()
{
$this->request = new Request();
return $this;
}
/**
* Set the response
*
* @return $this
*/
protected function setupResponse()
{
$this->response = new Response();
return $this;
}
/** /**
* Instantiate front controller * Instantiate front controller
* *
@ -269,7 +210,7 @@ class Web extends ApplicationBootstrap
private function setupFrontController() private function setupFrontController()
{ {
$this->frontController = Zend_Controller_Front::getInstance(); $this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->setRequest($this->request); $this->frontController->setRequest($this->getRequest());
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers')); $this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
$this->frontController->setParams( $this->frontController->setParams(
array( array(