[icinga-checkins] icinga.org: icingaweb2/master: CLI/Webserver Setup: Rename publicPath to documentRoot

git at icinga.org git at icinga.org
Thu Nov 13 15:10:33 CET 2014


Module: icingaweb2
Branch: master
Commit: 8594dc068af5519c1d2c22dea6c75409ad52ebe7
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=8594dc068af5519c1d2c22dea6c75409ad52ebe7

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Thu Nov 13 13:16:49 2014 +0100

CLI/Webserver Setup: Rename publicPath to documentRoot

refs #6120

---

 .../application/clicommands/ConfigCommand.php      |    5 +-
 modules/setup/library/Setup/Webserver.php          |   75 +++++++-------------
 modules/setup/library/Setup/Webserver/Apache.php   |    5 +-
 modules/setup/library/Setup/Webserver/Nginx.php    |    4 +-
 4 files changed, 30 insertions(+), 59 deletions(-)

diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php
index c4e4c15..1a328d0 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 708c366..5cffe34 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;
 
 /**
@@ -13,25 +13,18 @@ use Icinga\Exception\ProgrammingError;
 abstract class Webserver
 {
     /**
-     * Web path
+     * Document root
      *
      * @var string
      */
-    protected $webPath;
+    protected $documentRoot;
 
     /**
-     * System path to public documents
+     * Web path
      *
      * @var string
      */
-    protected $publicPath;
-
-    /**
-     * Application
-     *
-     * @var ApplicationBootstrap
-     */
-    protected $app;
+    protected $webPath;
 
     /**
      * 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 a565b95..e25182f 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}"
 
-<Directory "{publicPath}">
+<Directory "{documentRoot}">
     Options SymLinksIfOwnerMatch
     AllowOverride None
 
@@ -54,7 +54,6 @@ Alias {webPath} "{publicPath}"
         DirectoryIndex error_norewrite.html
         ErrorDocument 404 /error_norewrite.html
     </IfModule>
-
 </Directory>
 EOD;
 
diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php
index 4725f48..4885dc0 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;
 }



More information about the icinga-checkins mailing list