CLI/Webserver Setup: Rename publicPath to documentRoot

refs #6120
This commit is contained in:
Eric Lippmann 2014-11-13 13:16:49 +01:00
parent 0d4ed40cb2
commit 8594dc068a
4 changed files with 33 additions and 62 deletions

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}