Browse Source

code style and UI improvements to requirements checker

also changed PHP Intl support to optional.
tags/2.0.0-beta
Carsten Brandt 12 years ago
parent
commit
6a1b226cdb
  1. 32
      yii/requirements/YiiRequirementChecker.php
  2. 6
      yii/requirements/requirements.php
  3. 26
      yii/requirements/views/web/index.php

32
yii/requirements/YiiRequirementChecker.php

@ -16,7 +16,7 @@ if (version_compare(PHP_VERSION, '4.3', '<')) {
* *
* Example: * Example:
* *
* ~~~ * ~~~php
* require_once('path/to/YiiRequirementChecker.php'); * require_once('path/to/YiiRequirementChecker.php');
* $requirementsChecker = new YiiRequirementChecker(); * $requirementsChecker = new YiiRequirementChecker();
* $requirements = array( * $requirements = array(
@ -62,7 +62,7 @@ class YiiRequirementChecker
* If a string, it is treated as the path of the file, which contains the requirements; * If a string, it is treated as the path of the file, which contains the requirements;
* @return YiiRequirementChecker self instance. * @return YiiRequirementChecker self instance.
*/ */
function check($requirements) public function check($requirements)
{ {
if (is_string($requirements)) { if (is_string($requirements)) {
$requirements = require($requirements); $requirements = require($requirements);
@ -132,7 +132,7 @@ class YiiRequirementChecker
* ) * )
* </code> * </code>
*/ */
function getResult() public function getResult()
{ {
if (isset($this->result)) { if (isset($this->result)) {
return $this->result; return $this->result;
@ -145,7 +145,7 @@ class YiiRequirementChecker
* Renders the requirements check result. * Renders the requirements check result.
* The output will vary depending is a script running from web or from console. * The output will vary depending is a script running from web or from console.
*/ */
function render() public function render()
{ {
if (!isset($this->result)) { if (!isset($this->result)) {
$this->usageError('Nothing to render!'); $this->usageError('Nothing to render!');
@ -166,7 +166,7 @@ class YiiRequirementChecker
* @param string $compare comparison operator, by default '>=' * @param string $compare comparison operator, by default '>='
* @return boolean if PHP extension version matches. * @return boolean if PHP extension version matches.
*/ */
function checkPhpExtensionVersion($extensionName, $version, $compare = '>=') public function checkPhpExtensionVersion($extensionName, $version, $compare = '>=')
{ {
if (!extension_loaded($extensionName)) { if (!extension_loaded($extensionName)) {
return false; return false;
@ -183,7 +183,7 @@ class YiiRequirementChecker
* @param string $name configuration option name. * @param string $name configuration option name.
* @return boolean option is on. * @return boolean option is on.
*/ */
function checkPhpIniOn($name) public function checkPhpIniOn($name)
{ {
$value = ini_get($name); $value = ini_get($name);
if (empty($value)) { if (empty($value)) {
@ -197,7 +197,7 @@ class YiiRequirementChecker
* @param string $name configuration option name. * @param string $name configuration option name.
* @return boolean option is off. * @return boolean option is off.
*/ */
function checkPhpIniOff($name) public function checkPhpIniOff($name)
{ {
$value = ini_get($name); $value = ini_get($name);
if (empty($value)) { if (empty($value)) {
@ -214,7 +214,7 @@ class YiiRequirementChecker
* @param string $compare comparison operator, by default '>='. * @param string $compare comparison operator, by default '>='.
* @return boolean comparison result. * @return boolean comparison result.
*/ */
function compareByteSize($a, $b, $compare = '>=') public function compareByteSize($a, $b, $compare = '>=')
{ {
$compareExpression = '(' . $this->getByteSize($a) . $compare . $this->getByteSize($b) . ')'; $compareExpression = '(' . $this->getByteSize($a) . $compare . $this->getByteSize($b) . ')';
return $this->evaluateExpression($compareExpression); return $this->evaluateExpression($compareExpression);
@ -226,7 +226,7 @@ class YiiRequirementChecker
* @param string $verboseSize verbose size representation. * @param string $verboseSize verbose size representation.
* @return integer actual size in bytes. * @return integer actual size in bytes.
*/ */
function getByteSize($verboseSize) public function getByteSize($verboseSize)
{ {
if (empty($verboseSize)) { if (empty($verboseSize)) {
return 0; return 0;
@ -265,7 +265,7 @@ class YiiRequirementChecker
* @param string|null $max verbose file size maximum required value, pass null to skip maximum check. * @param string|null $max verbose file size maximum required value, pass null to skip maximum check.
* @return boolean success. * @return boolean success.
*/ */
function checkUploadMaxFileSize($min = null, $max = null) public function checkUploadMaxFileSize($min = null, $max = null)
{ {
$postMaxSize = ini_get('post_max_size'); $postMaxSize = ini_get('post_max_size');
$uploadMaxFileSize = ini_get('upload_max_filesize'); $uploadMaxFileSize = ini_get('upload_max_filesize');
@ -292,7 +292,7 @@ class YiiRequirementChecker
* @param boolean $_return_ whether the rendering result should be returned as a string * @param boolean $_return_ whether the rendering result should be returned as a string
* @return string the rendering result. Null if the rendering result is not required. * @return string the rendering result. Null if the rendering result is not required.
*/ */
function renderViewFile($_viewFile_, $_data_ = null, $_return_ = false) public function renderViewFile($_viewFile_, $_data_ = null, $_return_ = false)
{ {
// we use special variable names here to avoid conflict when extracting data // we use special variable names here to avoid conflict when extracting data
if (is_array($_data_)) { if (is_array($_data_)) {
@ -316,7 +316,7 @@ class YiiRequirementChecker
* @param int $requirementKey requirement key in the list. * @param int $requirementKey requirement key in the list.
* @return array normalized requirement. * @return array normalized requirement.
*/ */
function normalizeRequirement($requirement, $requirementKey = 0) public function normalizeRequirement($requirement, $requirementKey = 0)
{ {
if (!is_array($requirement)) { if (!is_array($requirement)) {
$this->usageError('Requirement must be an array!'); $this->usageError('Requirement must be an array!');
@ -354,7 +354,7 @@ class YiiRequirementChecker
* This method will then terminate the execution of the current application. * This method will then terminate the execution of the current application.
* @param string $message the error message * @param string $message the error message
*/ */
function usageError($message) public function usageError($message)
{ {
echo "Error: $message\n\n"; echo "Error: $message\n\n";
exit(1); exit(1);
@ -365,7 +365,7 @@ class YiiRequirementChecker
* @param string $expression a PHP expression to be evaluated. * @param string $expression a PHP expression to be evaluated.
* @return mixed the expression result. * @return mixed the expression result.
*/ */
function evaluateExpression($expression) public function evaluateExpression($expression)
{ {
return eval('return ' . $expression . ';'); return eval('return ' . $expression . ';');
} }
@ -374,7 +374,7 @@ class YiiRequirementChecker
* Returns the server information. * Returns the server information.
* @return string server information. * @return string server information.
*/ */
function getServerInfo() public function getServerInfo()
{ {
$info = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''; $info = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
return $info; return $info;
@ -384,7 +384,7 @@ class YiiRequirementChecker
* Returns the now date if possible in string representation. * Returns the now date if possible in string representation.
* @return string now date. * @return string now date.
*/ */
function getNowDate() public function getNowDate()
{ {
$nowDate = @strftime('%Y-%m-%d %H:%M', time()); $nowDate = @strftime('%Y-%m-%d %H:%M', time());
return $nowDate; return $nowDate;

6
yii/requirements/requirements.php

@ -1,6 +1,6 @@
<?php <?php
/** /**
* This is the Yii core requirements for the [[YiiRequirementChecker]] instance. * These are the Yii core requirements for the [[YiiRequirementChecker]] instance.
* These requirements are mandatory for any Yii application. * These requirements are mandatory for any Yii application.
* *
* @var $this YiiRequirementChecker * @var $this YiiRequirementChecker
@ -40,9 +40,9 @@ return array(
), ),
array( array(
'name' => 'Intl extension', 'name' => 'Intl extension',
'mandatory' => true, 'mandatory' => false,
'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2'), 'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2'),
'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support', 'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support',
'memo' => 'PHP Intl extension 1.0.2 or higher is required.' 'memo' => 'PHP Intl extension 1.0.2 or higher is required when you want to use <abbr title="Internationalized domain names">IDN</abbr>-feature of EmailValidator or UrlValidator.'
), ),
); );

26
yii/requirements/views/web/index.php

@ -8,7 +8,7 @@
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>Yii Application Requirement Checker</title> <title>Yii Application Requirement Checker</title>
<?php $this->renderViewFile(dirname(__FILE__).DIRECTORY_SEPARATOR.'css.php'); ?> <?php $this->renderViewFile(__DIR__ . '/css.php'); ?>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
@ -25,14 +25,26 @@
It checks if the server is running the right version of PHP, It checks if the server is running the right version of PHP,
if appropriate PHP extensions have been loaded, and if php.ini file settings are correct. if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.
</p> </p>
<p>
There are two kinds of requirements being checked. Mandatory requirements are those that have to be met
to allow Yii to work as expected. There are also some optional requirements beeing checked which will
show you a warning when they do not meet. You can use Yii framework without them but some specific
functionality may be not available in this case.
</p>
<h3>Conclusion</h3> <h3>Conclusion</h3>
<?php if ($summary['errors']>0): ?> <?php if ($summary['errors'] > 0): ?>
<strong class="text-error">Unfortunately your server configuration does not satisfy the requirements by this application.</strong> <div class="alert alert-error">
<?php elseif ($summary['warnings']>0): ?> <strong>Unfortunately your server configuration does not satisfy the requirements by this application.<br>Please refer to the table below for detailed explanation.</strong>
<strong class="text-warning">Your server configuration satisfies the minimum requirements by this application. Please pay attention to the warnings listed below if your application will use the corresponding features.</strong> </div>
<?php elseif ($summary['warnings'] > 0): ?>
<div class="alert alert-info">
<strong>Your server configuration satisfies the minimum requirements by this application.<br>Please pay attention to the warnings listed below and check if your application will use the corresponding features.</strong>
</div>
<?php else: ?> <?php else: ?>
<strong class="text-success">Congratulations! Your server configuration satisfies all requirements.</strong> <div class="alert alert-success">
<strong>Congratulations! Your server configuration satisfies all requirements.</strong>
</div>
<?php endif; ?> <?php endif; ?>
<h3>Details</h3> <h3>Details</h3>
@ -62,7 +74,7 @@
<hr> <hr>
<div class="footer"> <div class="footer">
<p>Server: <?php echo $this->getServerInfo().' '.$this->getNowDate(); ?></p> <p>Server: <?php echo $this->getServerInfo() . ' ' . $this->getNowDate(); ?></p>
<p>Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></p> <p>Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></p>
</div> </div>
</div> </div>

Loading…
Cancel
Save