* * 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 */ class Requirement { 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 */ public function __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 */ public function isFulfilled() { return $this->fulfilled; } /** * Returns the message for testing the requirement. * * @return string The test message */ public function getTestMessage() { return $this->testMessage; } /** * Returns the help text for resolving the problem. * * @return string The help text */ public function getHelpText() { return $this->helpText; } /** * Returns the help text formatted in HTML. * * @return string The HTML help */ public function getHelpHtml() { return $this->helpHtml; } /** * Returns whether this is only an optional recommendation and not a mandatory requirement. * * @return bool true if optional, false if mandatory */ public function isOptional() { return $this->optional; } } /** * Represents a PHP requirement in form of a php.ini configuration. * * @author Tobias Schultze */ class PhpIniRequirement extends Requirement { /** * 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 */ public function __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) { throw new InvalidArgumentException('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 %s to %s in php.ini*.', $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 */ class RequirementCollection implements IteratorAggregate { /** * @var Requirement[] */ private $requirements = array(); /** * Gets the current RequirementCollection as an Iterator. * * @return Traversable A Traversable interface */ public function getIterator() { return new ArrayIterator($this->requirements); } /** * Adds a Requirement. * * @param Requirement $requirement A Requirement instance */ public function add(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) */ public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null) { $this->add(new Requirement($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 $help