From 8594dc068af5519c1d2c22dea6c75409ad52ebe7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 13 Nov 2014 13:16:49 +0100 Subject: [PATCH] CLI/Webserver Setup: Rename publicPath to documentRoot refs #6120 --- .../application/clicommands/ConfigCommand.php | 5 +- modules/setup/library/Setup/Webserver.php | 81 +++++++------------ .../setup/library/Setup/Webserver/Apache.php | 5 +- .../setup/library/Setup/Webserver/Nginx.php | 4 +- 4 files changed, 33 insertions(+), 62 deletions(-) diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php index c4e4c1520..1a328d01d 100644 --- a/modules/setup/application/clicommands/ConfigCommand.php +++ b/modules/setup/application/clicommands/ConfigCommand.php @@ -100,15 +100,14 @@ class ConfigCommand extends Command } catch (ProgrammingError $e) { $this->fail($this->translate('Unknown type') . ': ' . $type); } - $webserver->setApp($this->app); if (($path = $this->params->get('path', '/icingaweb')) === null) { $this->fail($this->translate('argument --path is mandatory.')); } - if (($publicPath = $this->params->get('publicPath', $webserver->getPublicPath())) === null) { + if (($documentRoot = $this->params->get('documentRoot', $webserver->getDocumentRoot())) === null) { $this->fail($this->translate('argument --publicPath is mandatory.')); } $webserver->setWebPath($path); - $webserver->setPublicPath($publicPath); + $webserver->setDocumentRoot($documentRoot); $config = $webserver->generate() . "\n"; if (($file = $this->params->get('file')) !== null) { if (file_exists($file) === true) { diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php index 708c366b8..5cffe349c 100644 --- a/modules/setup/library/Setup/Webserver.php +++ b/modules/setup/library/Setup/Webserver.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Setup; -use Icinga\Application\ApplicationBootstrap; +use Icinga\Application\Icinga; use Icinga\Exception\ProgrammingError; /** @@ -12,6 +12,13 @@ use Icinga\Exception\ProgrammingError; */ abstract class Webserver { + /** + * Document root + * + * @var string + */ + protected $documentRoot; + /** * Web path * @@ -19,20 +26,6 @@ abstract class Webserver */ protected $webPath; - /** - * System path to public documents - * - * @var string - */ - protected $publicPath; - - /** - * Application - * - * @var ApplicationBootstrap - */ - protected $app; - /** * Create instance by type name * @@ -62,13 +55,13 @@ abstract class Webserver $searchTokens = array( '{webPath}', - '{publicPath}', + '{documentRoot}', '{configPath}', ); $replaceTokens = array( $this->getWebPath(), - $this->getPublicPath(), - $this->getApp()->getConfigDir() + $this->getDocumentRoot(), + Icinga::app()->getConfigDir() ); $template = str_replace($searchTokens, $replaceTokens, $template); return $template; @@ -102,58 +95,38 @@ abstract class Webserver } /** - * @param string $publicPath + * Set the document root + * + * @param string $documentRoot + * + * @return $this */ - public function setPublicPath($publicPath) + public function setDocumentRoot($documentRoot) { - $this->publicPath = $publicPath; + $this->documentRoot = (string) $documentRoot; + return $this; } /** - * Detect public root + * Detect the document root * * @return string */ - public function detectPublicPath() + public function detectDocumentRoot() { - $applicationPath = $this->getApp()->getApplicationDir(); - $applicationPath = dirname($applicationPath) . DIRECTORY_SEPARATOR . 'public'; - if (is_dir($applicationPath) === true) { - return $applicationPath; - } - return null; + return Icinga::app()->getBaseDir('public'); } /** - * Getter for public root + * Get the document root * * @return string */ - public function getPublicPath() + public function getDocumentRoot() { - if ($this->publicPath === null) { - $this->publicPath = $this->detectPublicPath(); + if ($this->documentRoot === null) { + $this->documentRoot = $this->detectDocumentRoot(); } - return $this->publicPath; - } - - /** - * Setter for application bootstrap - * - * @param ApplicationBootstrap $app - */ - public function setApp(ApplicationBootstrap $app) - { - $this->app = $app; - } - - /** - * Getter for application bootstrap - * - * @return ApplicationBootstrap - */ - public function getApp() - { - return $this->app; + return $this->documentRoot; } } diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php index a565b9510..e25182fdf 100644 --- a/modules/setup/library/Setup/Webserver/Apache.php +++ b/modules/setup/library/Setup/Webserver/Apache.php @@ -17,9 +17,9 @@ class Apache extends Webserver protected function getTemplate() { return <<<'EOD' -Alias {webPath} "{publicPath}" +Alias {webPath} "{documentRoot}" - + Options SymLinksIfOwnerMatch AllowOverride None @@ -54,7 +54,6 @@ Alias {webPath} "{publicPath}" DirectoryIndex error_norewrite.html ErrorDocument 404 /error_norewrite.html - EOD; diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php index 4725f4808..4885dc03b 100644 --- a/modules/setup/library/Setup/Webserver/Nginx.php +++ b/modules/setup/library/Setup/Webserver/Nginx.php @@ -24,11 +24,11 @@ location ~ ^{webPath}/index\.php(.*)$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; - fastcgi_param SCRIPT_FILENAME {publicPath}/index.php; + fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php; } location ~ ^{webPath}(.+)? { - alias {publicPath}; + alias {documentRoot}; index index.php; try_files $1 $uri $uri/ {webPath}/index.php$is_args$args; }