Merge branch 'feature/allow-module-developers-to-define-additional-static-files-9702'
resolves #9702
This commit is contained in:
commit
c289b2f1ef
|
@ -5,6 +5,9 @@ namespace Icinga\Application;
|
|||
|
||||
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
|
||||
*
|
||||
|
@ -16,6 +19,40 @@ require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
@ -26,10 +63,34 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
{
|
||||
return $this
|
||||
->setupZendAutoloader()
|
||||
->loadConfig()
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupRequest()
|
||||
->setupResponse()
|
||||
->setupTimezone()
|
||||
->setupModuleManager()
|
||||
->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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,6 +162,20 @@ class Module
|
|||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* The CSS/LESS files this module provides
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cssFiles = array();
|
||||
|
||||
/**
|
||||
* The Javascript files this module provides
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $jsFiles = array();
|
||||
|
||||
/**
|
||||
* Routes to add to the route chain
|
||||
*
|
||||
|
@ -388,6 +402,19 @@ class Module
|
|||
return $manager->getModule($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an additional CSS/LESS file
|
||||
*
|
||||
* @param string $path The path to the file, relative to self::$cssdir
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function provideCssFile($path)
|
||||
{
|
||||
$this->cssFiles[] = $this->cssdir . DIRECTORY_SEPARATOR . $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if module provides css
|
||||
*
|
||||
|
@ -395,7 +422,12 @@ class Module
|
|||
*/
|
||||
public function hasCss()
|
||||
{
|
||||
return file_exists($this->getCssFilename());
|
||||
if (file_exists($this->getCssFilename())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->launchConfigScript();
|
||||
return !empty($this->cssFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -408,6 +440,31 @@ class Module
|
|||
return $this->cssdir . '/module.less';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the CSS/LESS files this module provides
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCssFiles()
|
||||
{
|
||||
$files = $this->cssFiles;
|
||||
$files[] = $this->getCssFilename();
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an additional Javascript file
|
||||
*
|
||||
* @param string $path The path to the file, relative to self::$jsdir
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function provideJsFile($path)
|
||||
{
|
||||
$this->jsFiles[] = $this->jsdir . DIRECTORY_SEPARATOR . $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if module provides js
|
||||
*
|
||||
|
@ -415,7 +472,12 @@ class Module
|
|||
*/
|
||||
public function hasJs()
|
||||
{
|
||||
return file_exists($this->getJsFilename());
|
||||
if (file_exists($this->getJsFilename())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->launchConfigScript();
|
||||
return !empty($this->jsFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,6 +490,18 @@ class Module
|
|||
return $this->jsdir . '/module.js';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Javascript files this module provides
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsFiles()
|
||||
{
|
||||
$files = $this->jsFiles;
|
||||
$files[] = $this->getJsFilename();
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module name
|
||||
*
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Icinga\Application;
|
||||
|
||||
require_once __DIR__ . '/ApplicationBootstrap.php';
|
||||
require_once __DIR__ . '/EmbeddedWeb.php';
|
||||
|
||||
use Zend_Controller_Action_HelperBroker;
|
||||
use Zend_Controller_Front;
|
||||
|
@ -11,14 +11,11 @@ use Zend_Controller_Router_Route;
|
|||
use Zend_Layout;
|
||||
use Zend_Paginator;
|
||||
use Zend_View_Helper_PaginationControl;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\User;
|
||||
use Icinga\Util\TimezoneDetect;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Response;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Web\Session\Session as BaseSession;
|
||||
use Icinga\Web\View;
|
||||
|
@ -28,11 +25,11 @@ use Icinga\Web\View;
|
|||
*
|
||||
* Usage example:
|
||||
* <code>
|
||||
* use Icinga\Application\EmbeddedWeb;
|
||||
* EmbeddedWeb::start();
|
||||
* use Icinga\Application\Web;
|
||||
* Web::start();
|
||||
* </code>
|
||||
*/
|
||||
class Web extends ApplicationBootstrap
|
||||
class Web extends EmbeddedWeb
|
||||
{
|
||||
/**
|
||||
* View object
|
||||
|
@ -48,20 +45,6 @@ class Web extends ApplicationBootstrap
|
|||
*/
|
||||
private $frontController;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* Response
|
||||
*
|
||||
* @var Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Session object
|
||||
*
|
||||
|
@ -145,26 +128,6 @@ class Web extends ApplicationBootstrap
|
|||
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
|
||||
*
|
||||
|
@ -211,7 +174,7 @@ class Web extends ApplicationBootstrap
|
|||
$auth = Auth::getInstance();
|
||||
if ($auth->isAuthenticated()) {
|
||||
$user = $auth->getUser();
|
||||
$this->request->setUser($user);
|
||||
$this->getRequest()->setUser($user);
|
||||
$this->user = $user;
|
||||
}
|
||||
return $this;
|
||||
|
@ -239,28 +202,6 @@ class Web extends ApplicationBootstrap
|
|||
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
|
||||
*
|
||||
|
@ -269,7 +210,7 @@ class Web extends ApplicationBootstrap
|
|||
private function setupFrontController()
|
||||
{
|
||||
$this->frontController = Zend_Controller_Front::getInstance();
|
||||
$this->frontController->setRequest($this->request);
|
||||
$this->frontController->setRequest($this->getRequest());
|
||||
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
|
||||
$this->frontController->setParams(
|
||||
array(
|
||||
|
|
|
@ -42,17 +42,6 @@ class JavaScript
|
|||
'js/vendor/jquery.tipsy'
|
||||
);
|
||||
|
||||
public static function listModuleFiles()
|
||||
{
|
||||
$list = array();
|
||||
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
|
||||
if ($module->hasJs()) {
|
||||
$list[] = 'js/' . $name . '/module.js';
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function sendMinified()
|
||||
{
|
||||
return self::send(true);
|
||||
|
@ -86,7 +75,11 @@ class JavaScript
|
|||
|
||||
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
|
||||
if ($module->hasJs()) {
|
||||
$jsFiles[] = $module->getJsFilename();
|
||||
foreach ($module->getJsFiles() as $path) {
|
||||
if (file_exists($path)) {
|
||||
$jsFiles[] = $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$files = array_merge($vendorFiles, $jsFiles);
|
||||
|
@ -114,7 +107,7 @@ class JavaScript
|
|||
}
|
||||
|
||||
foreach ($jsFiles as $file) {
|
||||
$js .= file_get_contents($file);
|
||||
$js .= file_get_contents($file) . "\n\n\n";
|
||||
}
|
||||
|
||||
if ($minified) {
|
||||
|
|
|
@ -93,14 +93,21 @@ class LessCompiler
|
|||
public function addModule($name, $module)
|
||||
{
|
||||
if ($module->hasCss()) {
|
||||
$this->source .= "\n/* CSS: modules/$name/module.less */\n"
|
||||
$contents = array();
|
||||
foreach ($module->getCssFiles() as $path) {
|
||||
if (file_exists($path)) {
|
||||
$contents[] = "/* CSS: modules/$name/$path */\n" . file_get_contents($path);
|
||||
}
|
||||
}
|
||||
|
||||
$this->source .= ''
|
||||
. '.icinga-module.module-'
|
||||
. $name
|
||||
. " {\n"
|
||||
. file_get_contents($module->getCssFilename())
|
||||
. "}\n\n"
|
||||
;
|
||||
. join("\n\n", $contents)
|
||||
. "}\n\n";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,11 @@ class StyleSheet
|
|||
$files = $lessFiles;
|
||||
foreach ($app->getModuleManager()->getLoadedModules() as $name => $module) {
|
||||
if ($module->hasCss()) {
|
||||
$files[] = $module->getCssFilename();
|
||||
foreach ($module->getCssFiles() as $path) {
|
||||
if (file_exists($path)) {
|
||||
$files[] = $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue