<?php/* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. *//* * Users of PHP 5.2 should be able to run the requirements checks. * This is why the file and all classes must be compatible with PHP 5.2+ * (e.g. not using namespaces and closures). * * ************** CAUTION ************** * * DO NOT EDIT THIS FILE as it will be overridden by Composer as part of * the installation/update process. The original file resides in the * SensioDistributionBundle. * * ************** CAUTION ************** *//** * Represents a single PHP requirement, e.g. an installed extension. * It can be a mandatory requirement or an optional recommendation. * There is a special subclass, named PhpIniRequirement, to check a php.ini configuration. * * @author Tobias Schultze <http://tobion.de> */classRequirement{private$fulfilled;private$testMessage;private$helpText;private$helpHtml;private$optional;/** * Constructor that initializes the requirement. * * @param bool $fulfilled Whether the requirement is fulfilled * @param string $testMessage The message for testing the requirement * @param string $helpHtml The help text formatted in HTML for resolving the problem * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement */publicfunction__construct($fulfilled,$testMessage,$helpHtml,$helpText=null,$optional=false){$this->fulfilled=(bool)$fulfilled;$this->testMessage=(string)$testMessage;$this->helpHtml=(string)$helpHtml;$this->helpText=null===$helpText?strip_tags($this->helpHtml):(string)$helpText;$this->optional=(bool)$optional;}/** * Returns whether the requirement is fulfilled. * * @return bool true if fulfilled, otherwise false */publicfunctionisFulfilled(){return$this->fulfilled;}/** * Returns the message for testing the requirement. * * @return string The test message */publicfunctiongetTestMessage(){return$this->testMessage;}/** * Returns the help text for resolving the problem. * * @return string The help text */publicfunctiongetHelpText(){return$this->helpText;}/** * Returns the help text formatted in HTML. * * @return string The HTML help */publicfunctiongetHelpHtml(){return$this->helpHtml;}/** * Returns whether this is only an optional recommendation and not a mandatory requirement. * * @return bool true if optional, false if mandatory */publicfunctionisOptional(){return$this->optional;}}/** * Represents a PHP requirement in form of a php.ini configuration. * * @author Tobias Schultze <http://tobion.de> */classPhpIniRequirementextendsRequirement{/** * Constructor that initializes the requirement. * * @param string $cfgName The configuration name used for ini_get() * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. * @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) * @param string|null $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement */publicfunction__construct($cfgName,$evaluation,$approveCfgAbsence=false,$testMessage=null,$helpHtml=null,$helpText=null,$optional=false){$cfgValue=ini_get($cfgName);if(is_callable($evaluation)){if(null===$testMessage||null===$helpHtml){thrownewInvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.');}$fulfilled=call_user_func($evaluation,$cfgValue);}else{if(null===$testMessage){$testMessage=sprintf('%s %s be %s in php.ini',$cfgName,$optional?'should':'must',$evaluation?'enabled':'disabled');}if(null===$helpHtml){$helpHtml=sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.',$cfgName,$evaluation?'on':'off');}$fulfilled=$evaluation==$cfgValue;}parent::__construct($fulfilled||($approveCfgAbsence&&false===$cfgValue),$testMessage,$helpHtml,$helpText,$optional);}}/** * A RequirementCollection represents a set of Requirement instances. * * @author Tobias Schultze <http://tobion.de> */classRequirementCollectionimplementsIteratorAggregate{/** * @var Requirement[] */private$requirements=array();/** * Gets the current RequirementCollection as an Iterator. * * @return Traversable A Traversable interface */publicfunctiongetIterator(){returnnewArrayIterator($this->requirements);}/** * Adds a Requirement. * * @param Requirement $requirement A Requirement instance */publicfunctionadd(Requirement$requirement){$this->requirements[]=$requirement;}/** * Adds a mandatory requirement. * * @param bool $fulfilled Whether the requirement is fulfilled * @param string $testMessage The message for testing the requirement * @param string $helpHtml The help text formatted in HTML for resolving the problem * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) */publicfunctionaddRequirement($fulfilled,$testMessage,$helpHtml,$helpText=null){$this->add(newRequirement($fulfilled,$testMessage,$helpHtml,$helpText,false));}/** * Adds an optional recommendation. * * @param bool $fulfilled Whether the recommendation is fulfilled * @param string $testMessage The message for testing the recommendation * @param string $helpHtml The help text formatted in HTML for resolving the problem * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) */publicfunctionaddRecommendation($fulfilled,$testMessage,$helpHtml,$helpText=null){$this->add(newRequirement($fulfilled,$testMessage,$helpHtml,$helpText,true));}/** * Adds a mandatory requirement in form of a php.ini configuration. * * @param string $cfgName The configuration name used for ini_get() * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) */publicfunctionaddPhpIniRequirement($cfgName,$evaluation,$approveCfgAbsence=false,$testMessage=null,$helpHtml=null,$helpText=null){$this->add(newPhpIniRequirement($cfgName,$evaluation,$approveCfgAbsence,$testMessage,$helpHtml,$helpText,false));}/** * Adds an optional recommendation in form of a php.ini configuration. * * @param string $cfgName The configuration name used for ini_get() * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) */publicfunctionaddPhpIniRecommendation($cfgName,$evaluation,$approveCfgAbsence=false,$testMessage=null,$helpHtml=null,$helpText=null){$this->add(newPhpIniRequirement($cfgName,$evaluation,$approveCfgAbsence,$testMessage,$helpHtml,$helpText,true));}/** * Adds a requirement collection to the current set of requirements. * * @param RequirementCollection $collection A RequirementCollection instance */publicfunctionaddCollection(RequirementCollection$collection){$this->requirements=array_merge($this->requirements,$collection->all());}/** * Returns both requirements and recommendations. * * @return Requirement[] */publicfunctionall(){return$this->requirements;}/** * Returns all mandatory requirements. * * @return Requirement[] */publicfunctiongetRequirements(){$array=array();foreach($this->requirementsas$req){if(!$req->isOptional()){$array[]=$req;}}return$array;}/** * Returns the mandatory requirements that were not met. * * @return Requirement[] */publicfunctiongetFailedRequirements(){$array=array();foreach($this->requirementsas$req){if(!$req->isFulfilled()&&!$req->isOptional()){$array[]=$req;}}return$array;}/** * Returns all optional recommendations. * * @return Requirement[] */publicfunctiongetRecommendations(){$array=array();foreach($this->requirementsas$req){if($req->isOptional()){$array[]=$req;}}return$array;}/** * Returns the recommendations that were not met. * * @return Requirement[] */publicfunctiongetFailedRecommendations(){$array=a