Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement all known requirements as object
refs #8508
- Loading branch information
Johannes Meyer
committed
Feb 25, 2015
1 parent
24d0999
commit 04630a2
Showing
8 changed files
with
293 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
modules/setup/library/Setup/Requirement/ClassRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Application\Platform; | ||
use Icinga\Module\Setup\Requirement; | ||
|
||
class ClassRequirement extends Requirement | ||
{ | ||
protected function evaluate() | ||
{ | ||
$classNameOrPath = $this->getCondition(); | ||
if (Platform::classExists($classNameOrPath)) { | ||
$this->setStateText(sprintf( | ||
mt('setup', 'The %s is available.', 'setup.requirement.class'), | ||
$this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class') | ||
)); | ||
return true; | ||
} else { | ||
$this->setStateText(sprintf( | ||
mt('setup', 'The %s is missing.', 'setup.requirement.class'), | ||
$this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class') | ||
)); | ||
return false; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
modules/setup/library/Setup/Requirement/ConfigDirectoryRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Module\Setup\Requirement; | ||
|
||
class ConfigDirectoryRequirement extends Requirement | ||
{ | ||
public function getTitle() | ||
{ | ||
$title = parent::getTitle(); | ||
if ($title === null) { | ||
return mt('setup', 'Read- and writable configuration directory'); | ||
} | ||
|
||
return $title; | ||
} | ||
|
||
protected function evaluate() | ||
{ | ||
$path = $this->getCondition(); | ||
if (file_exists($path)) { | ||
$readable = is_readable($path); | ||
if ($readable && is_writable($path)) { | ||
$this->setStateText(sprintf(mt('setup', 'The directory %s is read- and writable.'), $path)); | ||
return true; | ||
} else { | ||
$this->setStateText(sprintf( | ||
$readable | ||
? mt('setup', 'The directory %s is not writable.') | ||
: mt('setup', 'The directory %s is not readable.'), | ||
$path | ||
)); | ||
return false; | ||
} | ||
} else { | ||
$this->setStateText(sprintf(mt('setup', 'The directory %s does not exist.'), $path)); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Application\Platform; | ||
use Icinga\Module\Setup\Requirement; | ||
|
||
class OSRequirement extends Requirement | ||
{ | ||
public function getTitle() | ||
{ | ||
$title = parent::getTitle(); | ||
if ($title === null) { | ||
return sprintf(mt('setup', '%s Platform'), ucfirst($this->getCondition())); | ||
} | ||
|
||
return $title; | ||
} | ||
|
||
protected function evaluate() | ||
{ | ||
$phpOS = Platform::getOperatingSystemName(); | ||
$this->setStateText(sprintf(mt('setup', 'You are running PHP on a %s system.'), ucfirst($phpOS))); | ||
return strtolower($phpOS) === strtolower($this->getCondition()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
modules/setup/library/Setup/Requirement/PhpConfigRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Application\Platform; | ||
use Icinga\Module\Setup\Requirement; | ||
|
||
class PhpConfigRequirement extends Requirement | ||
{ | ||
protected function evaluate() | ||
{ | ||
list($configDirective, $value) = $this->getCondition(); | ||
$configValue = Platform::getPhpConfig($configDirective); | ||
$this->setStateText( | ||
$configValue | ||
? sprintf(mt('setup', 'The PHP config `%s\' is set to "%s".'), $configDirective, $configValue) | ||
: sprintf(mt('setup', 'The PHP config `%s\' is not defined.'), $configDirective) | ||
); | ||
return is_bool($value) ? $configValue == $value : $configValue === $value; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
modules/setup/library/Setup/Requirement/PhpModuleRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Application\Platform; | ||
use Icinga\Module\Setup\Requirement; | ||
|
||
class PhpModuleRequirement extends Requirement | ||
{ | ||
public function getTitle() | ||
{ | ||
$title = parent::getTitle(); | ||
if ($title === $this->getAlias()) { | ||
if ($title === null) { | ||
$title = $this->getCondition(); | ||
} | ||
|
||
return sprintf(mt('setup', 'PHP Module: %s'), $title); | ||
} | ||
|
||
return $title; | ||
} | ||
|
||
protected function evaluate() | ||
{ | ||
$moduleName = $this->getCondition(); | ||
if (Platform::extensionLoaded($moduleName)) { | ||
$this->setStateText(sprintf( | ||
mt('setup', 'The PHP module %s is available.'), | ||
$this->getAlias() ?: $moduleName | ||
)); | ||
return true; | ||
} else { | ||
$this->setStateText(sprintf( | ||
mt('setup', 'The PHP module %s is missing.'), | ||
$this->getAlias() ?: $moduleName | ||
)); | ||
return false; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/setup/library/Setup/Requirement/PhpVersionRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Application\Platform; | ||
use Icinga\Module\Setup\Requirement; | ||
|
||
class PhpVersionRequirement extends Requirement | ||
{ | ||
public function getTitle() | ||
{ | ||
$title = parent::getTitle(); | ||
if ($title === null) { | ||
return mt('setup', 'PHP Version'); | ||
} | ||
|
||
return $title; | ||
} | ||
|
||
protected function evaluate() | ||
{ | ||
$phpVersion = Platform::getPhpVersion(); | ||
$this->setStateText(sprintf(mt('setup', 'You are running PHP version %s.'), $phpVersion)); | ||
list($operator, $requiredVersion) = $this->getCondition(); | ||
return version_compare($phpVersion, $requiredVersion, $operator); | ||
} | ||
} |
Oops, something went wrong.