annotate app/SymfonyRequirements.php @ 1:f38015048f48 tip

Added GPL
author Daniel Wolff
date Sat, 13 Feb 2016 20:43:38 +0100
parents 493bcb69166c
children
rev   line source
Daniel@0 1 <?php
Daniel@0 2
Daniel@0 3 /*
Daniel@0 4 * This file is part of the Symfony package.
Daniel@0 5 *
Daniel@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Daniel@0 7 *
Daniel@0 8 * For the full copyright and license information, please view the LICENSE
Daniel@0 9 * file that was distributed with this source code.
Daniel@0 10 */
Daniel@0 11
Daniel@0 12 /*
Daniel@0 13 * Users of PHP 5.2 should be able to run the requirements checks.
Daniel@0 14 * This is why the file and all classes must be compatible with PHP 5.2+
Daniel@0 15 * (e.g. not using namespaces and closures).
Daniel@0 16 *
Daniel@0 17 * ************** CAUTION **************
Daniel@0 18 *
Daniel@0 19 * DO NOT EDIT THIS FILE as it will be overridden by Composer as part of
Daniel@0 20 * the installation/update process. The original file resides in the
Daniel@0 21 * SensioDistributionBundle.
Daniel@0 22 *
Daniel@0 23 * ************** CAUTION **************
Daniel@0 24 */
Daniel@0 25
Daniel@0 26 /**
Daniel@0 27 * Represents a single PHP requirement, e.g. an installed extension.
Daniel@0 28 * It can be a mandatory requirement or an optional recommendation.
Daniel@0 29 * There is a special subclass, named PhpIniRequirement, to check a php.ini configuration.
Daniel@0 30 *
Daniel@0 31 * @author Tobias Schultze <http://tobion.de>
Daniel@0 32 */
Daniel@0 33 class Requirement
Daniel@0 34 {
Daniel@0 35 private $fulfilled;
Daniel@0 36 private $testMessage;
Daniel@0 37 private $helpText;
Daniel@0 38 private $helpHtml;
Daniel@0 39 private $optional;
Daniel@0 40
Daniel@0 41 /**
Daniel@0 42 * Constructor that initializes the requirement.
Daniel@0 43 *
Daniel@0 44 * @param bool $fulfilled Whether the requirement is fulfilled
Daniel@0 45 * @param string $testMessage The message for testing the requirement
Daniel@0 46 * @param string $helpHtml The help text formatted in HTML for resolving the problem
Daniel@0 47 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 48 * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
Daniel@0 49 */
Daniel@0 50 public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false)
Daniel@0 51 {
Daniel@0 52 $this->fulfilled = (bool) $fulfilled;
Daniel@0 53 $this->testMessage = (string) $testMessage;
Daniel@0 54 $this->helpHtml = (string) $helpHtml;
Daniel@0 55 $this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText;
Daniel@0 56 $this->optional = (bool) $optional;
Daniel@0 57 }
Daniel@0 58
Daniel@0 59 /**
Daniel@0 60 * Returns whether the requirement is fulfilled.
Daniel@0 61 *
Daniel@0 62 * @return bool true if fulfilled, otherwise false
Daniel@0 63 */
Daniel@0 64 public function isFulfilled()
Daniel@0 65 {
Daniel@0 66 return $this->fulfilled;
Daniel@0 67 }
Daniel@0 68
Daniel@0 69 /**
Daniel@0 70 * Returns the message for testing the requirement.
Daniel@0 71 *
Daniel@0 72 * @return string The test message
Daniel@0 73 */
Daniel@0 74 public function getTestMessage()
Daniel@0 75 {
Daniel@0 76 return $this->testMessage;
Daniel@0 77 }
Daniel@0 78
Daniel@0 79 /**
Daniel@0 80 * Returns the help text for resolving the problem
Daniel@0 81 *
Daniel@0 82 * @return string The help text
Daniel@0 83 */
Daniel@0 84 public function getHelpText()
Daniel@0 85 {
Daniel@0 86 return $this->helpText;
Daniel@0 87 }
Daniel@0 88
Daniel@0 89 /**
Daniel@0 90 * Returns the help text formatted in HTML.
Daniel@0 91 *
Daniel@0 92 * @return string The HTML help
Daniel@0 93 */
Daniel@0 94 public function getHelpHtml()
Daniel@0 95 {
Daniel@0 96 return $this->helpHtml;
Daniel@0 97 }
Daniel@0 98
Daniel@0 99 /**
Daniel@0 100 * Returns whether this is only an optional recommendation and not a mandatory requirement.
Daniel@0 101 *
Daniel@0 102 * @return bool true if optional, false if mandatory
Daniel@0 103 */
Daniel@0 104 public function isOptional()
Daniel@0 105 {
Daniel@0 106 return $this->optional;
Daniel@0 107 }
Daniel@0 108 }
Daniel@0 109
Daniel@0 110 /**
Daniel@0 111 * Represents a PHP requirement in form of a php.ini configuration.
Daniel@0 112 *
Daniel@0 113 * @author Tobias Schultze <http://tobion.de>
Daniel@0 114 */
Daniel@0 115 class PhpIniRequirement extends Requirement
Daniel@0 116 {
Daniel@0 117 /**
Daniel@0 118 * Constructor that initializes the requirement.
Daniel@0 119 *
Daniel@0 120 * @param string $cfgName The configuration name used for ini_get()
Daniel@0 121 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
Daniel@0 122 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
Daniel@0 123 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
Daniel@0 124 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Daniel@0 125 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
Daniel@0 126 * @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
Daniel@0 127 * @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)
Daniel@0 128 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 129 * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
Daniel@0 130 */
Daniel@0 131 public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false)
Daniel@0 132 {
Daniel@0 133 $cfgValue = ini_get($cfgName);
Daniel@0 134
Daniel@0 135 if (is_callable($evaluation)) {
Daniel@0 136 if (null === $testMessage || null === $helpHtml) {
Daniel@0 137 throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.');
Daniel@0 138 }
Daniel@0 139
Daniel@0 140 $fulfilled = call_user_func($evaluation, $cfgValue);
Daniel@0 141 } else {
Daniel@0 142 if (null === $testMessage) {
Daniel@0 143 $testMessage = sprintf('%s %s be %s in php.ini',
Daniel@0 144 $cfgName,
Daniel@0 145 $optional ? 'should' : 'must',
Daniel@0 146 $evaluation ? 'enabled' : 'disabled'
Daniel@0 147 );
Daniel@0 148 }
Daniel@0 149
Daniel@0 150 if (null === $helpHtml) {
Daniel@0 151 $helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.',
Daniel@0 152 $cfgName,
Daniel@0 153 $evaluation ? 'on' : 'off'
Daniel@0 154 );
Daniel@0 155 }
Daniel@0 156
Daniel@0 157 $fulfilled = $evaluation == $cfgValue;
Daniel@0 158 }
Daniel@0 159
Daniel@0 160 parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional);
Daniel@0 161 }
Daniel@0 162 }
Daniel@0 163
Daniel@0 164 /**
Daniel@0 165 * A RequirementCollection represents a set of Requirement instances.
Daniel@0 166 *
Daniel@0 167 * @author Tobias Schultze <http://tobion.de>
Daniel@0 168 */
Daniel@0 169 class RequirementCollection implements IteratorAggregate
Daniel@0 170 {
Daniel@0 171 private $requirements = array();
Daniel@0 172
Daniel@0 173 /**
Daniel@0 174 * Gets the current RequirementCollection as an Iterator.
Daniel@0 175 *
Daniel@0 176 * @return Traversable A Traversable interface
Daniel@0 177 */
Daniel@0 178 public function getIterator()
Daniel@0 179 {
Daniel@0 180 return new ArrayIterator($this->requirements);
Daniel@0 181 }
Daniel@0 182
Daniel@0 183 /**
Daniel@0 184 * Adds a Requirement.
Daniel@0 185 *
Daniel@0 186 * @param Requirement $requirement A Requirement instance
Daniel@0 187 */
Daniel@0 188 public function add(Requirement $requirement)
Daniel@0 189 {
Daniel@0 190 $this->requirements[] = $requirement;
Daniel@0 191 }
Daniel@0 192
Daniel@0 193 /**
Daniel@0 194 * Adds a mandatory requirement.
Daniel@0 195 *
Daniel@0 196 * @param bool $fulfilled Whether the requirement is fulfilled
Daniel@0 197 * @param string $testMessage The message for testing the requirement
Daniel@0 198 * @param string $helpHtml The help text formatted in HTML for resolving the problem
Daniel@0 199 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 200 */
Daniel@0 201 public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null)
Daniel@0 202 {
Daniel@0 203 $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false));
Daniel@0 204 }
Daniel@0 205
Daniel@0 206 /**
Daniel@0 207 * Adds an optional recommendation.
Daniel@0 208 *
Daniel@0 209 * @param bool $fulfilled Whether the recommendation is fulfilled
Daniel@0 210 * @param string $testMessage The message for testing the recommendation
Daniel@0 211 * @param string $helpHtml The help text formatted in HTML for resolving the problem
Daniel@0 212 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 213 */
Daniel@0 214 public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null)
Daniel@0 215 {
Daniel@0 216 $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true));
Daniel@0 217 }
Daniel@0 218
Daniel@0 219 /**
Daniel@0 220 * Adds a mandatory requirement in form of a php.ini configuration.
Daniel@0 221 *
Daniel@0 222 * @param string $cfgName The configuration name used for ini_get()
Daniel@0 223 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
Daniel@0 224 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
Daniel@0 225 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
Daniel@0 226 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Daniel@0 227 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
Daniel@0 228 * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
Daniel@0 229 * @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)
Daniel@0 230 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 231 */
Daniel@0 232 public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
Daniel@0 233 {
Daniel@0 234 $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false));
Daniel@0 235 }
Daniel@0 236
Daniel@0 237 /**
Daniel@0 238 * Adds an optional recommendation in form of a php.ini configuration.
Daniel@0 239 *
Daniel@0 240 * @param string $cfgName The configuration name used for ini_get()
Daniel@0 241 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
Daniel@0 242 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
Daniel@0 243 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
Daniel@0 244 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Daniel@0 245 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
Daniel@0 246 * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
Daniel@0 247 * @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)
Daniel@0 248 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
Daniel@0 249 */
Daniel@0 250 public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
Daniel@0 251 {
Daniel@0 252 $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true));
Daniel@0 253 }
Daniel@0 254
Daniel@0 255 /**
Daniel@0 256 * Adds a requirement collection to the current set of requirements.
Daniel@0 257 *
Daniel@0 258 * @param RequirementCollection $collection A RequirementCollection instance
Daniel@0 259 */
Daniel@0 260 public function addCollection(RequirementCollection $collection)
Daniel@0 261 {
Daniel@0 262 $this->requirements = array_merge($this->requirements, $collection->all());
Daniel@0 263 }
Daniel@0 264
Daniel@0 265 /**
Daniel@0 266 * Returns both requirements and recommendations.
Daniel@0 267 *
Daniel@0 268 * @return array Array of Requirement instances
Daniel@0 269 */
Daniel@0 270 public function all()
Daniel@0 271 {
Daniel@0 272 return $this->requirements;
Daniel@0 273 }
Daniel@0 274
Daniel@0 275 /**
Daniel@0 276 * Returns all mandatory requirements.
Daniel@0 277 *
Daniel@0 278 * @return array Array of Requirement instances
Daniel@0 279 */
Daniel@0 280 public function getRequirements()
Daniel@0 281 {
Daniel@0 282 $array = array();
Daniel@0 283 foreach ($this->requirements as $req) {
Daniel@0 284 if (!$req->isOptional()) {
Daniel@0 285 $array[] = $req;
Daniel@0 286 }
Daniel@0 287 }
Daniel@0 288
Daniel@0 289 return $array;
Daniel@0 290 }
Daniel@0 291
Daniel@0 292 /**
Daniel@0 293 * Returns the mandatory requirements that were not met.
Daniel@0 294 *
Daniel@0 295 * @return array Array of Requirement instances
Daniel@0 296 */
Daniel@0 297 public function getFailedRequirements()
Daniel@0 298 {
Daniel@0 299 $array = array();
Daniel@0 300 foreach ($this->requirements as $req) {
Daniel@0 301 if (!$req->isFulfilled() && !$req->isOptional()) {
Daniel@0 302 $array[] = $req;
Daniel@0 303 }
Daniel@0 304 }
Daniel@0 305
Daniel@0 306 return $array;
Daniel@0 307 }
Daniel@0 308
Daniel@0 309 /**
Daniel@0 310 * Returns all optional recommendations.
Daniel@0 311 *
Daniel@0 312 * @return array Array of Requirement instances
Daniel@0 313 */
Daniel@0 314 public function getRecommendations()
Daniel@0 315 {
Daniel@0 316 $array = array();
Daniel@0 317 foreach ($this->requirements as $req) {
Daniel@0 318 if ($req->isOptional()) {
Daniel@0 319 $array[] = $req;
Daniel@0 320 }
Daniel@0 321 }
Daniel@0 322
Daniel@0 323 return $array;
Daniel@0 324 }
Daniel@0 325
Daniel@0 326 /**
Daniel@0 327 * Returns the recommendations that were not met.
Daniel@0 328 *
Daniel@0 329 * @return array Array of Requirement instances
Daniel@0 330 */
Daniel@0 331 public function getFailedRecommendations()
Daniel@0 332 {
Daniel@0 333 $array = array();
Daniel@0 334 foreach ($this->requirements as $req) {
Daniel@0 335 if (!$req->isFulfilled() && $req->isOptional()) {
Daniel@0 336 $array[] = $req;
Daniel@0 337 }
Daniel@0 338 }
Daniel@0 339
Daniel@0 340 return $array;
Daniel@0 341 }
Daniel@0 342
Daniel@0 343 /**
Daniel@0 344 * Returns whether a php.ini configuration is not correct.
Daniel@0 345 *
Daniel@0 346 * @return bool php.ini configuration problem?
Daniel@0 347 */
Daniel@0 348 public function hasPhpIniConfigIssue()
Daniel@0 349 {
Daniel@0 350 foreach ($this->requirements as $req) {
Daniel@0 351 if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) {
Daniel@0 352 return true;
Daniel@0 353 }
Daniel@0 354 }
Daniel@0 355
Daniel@0 356 return false;
Daniel@0 357 }
Daniel@0 358
Daniel@0 359 /**
Daniel@0 360 * Returns the PHP configuration file (php.ini) path.
Daniel@0 361 *
Daniel@0 362 * @return string|false php.ini file path
Daniel@0 363 */
Daniel@0 364 public function getPhpIniConfigPath()
Daniel@0 365 {
Daniel@0 366 return get_cfg_var('cfg_file_path');
Daniel@0 367 }
Daniel@0 368 }
Daniel@0 369
Daniel@0 370 /**
Daniel@0 371 * This class specifies all requirements and optional recommendations that
Daniel@0 372 * are necessary to run the Symfony Standard Edition.
Daniel@0 373 *
Daniel@0 374 * @author Tobias Schultze <http://tobion.de>
Daniel@0 375 * @author Fabien Potencier <fabien@symfony.com>
Daniel@0 376 */
Daniel@0 377 class SymfonyRequirements extends RequirementCollection
Daniel@0 378 {
Daniel@0 379 const REQUIRED_PHP_VERSION = '5.3.3';
Daniel@0 380
Daniel@0 381 /**
Daniel@0 382 * Constructor that initializes the requirements.
Daniel@0 383 */
Daniel@0 384 public function __construct()
Daniel@0 385 {
Daniel@0 386 /* mandatory requirements follow */
Daniel@0 387
Daniel@0 388 $installedPhpVersion = phpversion();
Daniel@0 389
Daniel@0 390 $this->addRequirement(
Daniel@0 391 version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='),
Daniel@0 392 sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion),
Daniel@0 393 sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
Daniel@0 394 Before using Symfony, upgrade your PHP installation, preferably to the latest version.',
Daniel@0 395 $installedPhpVersion, self::REQUIRED_PHP_VERSION),
Daniel@0 396 sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)
Daniel@0 397 );
Daniel@0 398
Daniel@0 399 $this->addRequirement(
Daniel@0 400 version_compare($installedPhpVersion, '5.3.16', '!='),
Daniel@0 401 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it',
Daniel@0 402 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)'
Daniel@0 403 );
Daniel@0 404
Daniel@0 405 $this->addRequirement(
Daniel@0 406 is_dir(__DIR__.'/../vendor/composer'),
Daniel@0 407 'Vendor libraries must be installed',
Daniel@0 408 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
Daniel@0 409 'Then run "<strong>php composer.phar install</strong>" to install them.'
Daniel@0 410 );
Daniel@0 411
Daniel@0 412 $cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache';
Daniel@0 413
Daniel@0 414 $this->addRequirement(
Daniel@0 415 is_writable($cacheDir),
Daniel@0 416 'app/cache/ or var/cache/ directory must be writable',
Daniel@0 417 'Change the permissions of either "<strong>app/cache/</strong>" or "<strong>var/cache/</strong>" directory so that the web server can write into it.'
Daniel@0 418 );
Daniel@0 419
Daniel@0 420 $logsDir = is_dir(__DIR__.'/../var/logs') ? __DIR__.'/../var/logs' : __DIR__.'/logs';
Daniel@0 421
Daniel@0 422 $this->addRequirement(
Daniel@0 423 is_writable($logsDir),
Daniel@0 424 'app/logs/ or var/logs/ directory must be writable',
Daniel@0 425 'Change the permissions of either "<strong>app/logs/</strong>" or "<strong>var/logs/</strong>" directory so that the web server can write into it.'
Daniel@0 426 );
Daniel@0 427
Daniel@0 428 $this->addPhpIniRequirement(
Daniel@0 429 'date.timezone', true, false,
Daniel@0 430 'date.timezone setting must be set',
Daniel@0 431 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).'
Daniel@0 432 );
Daniel@0 433
Daniel@0 434 if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
Daniel@0 435 $timezones = array();
Daniel@0 436 foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
Daniel@0 437 foreach ($abbreviations as $abbreviation) {
Daniel@0 438 $timezones[$abbreviation['timezone_id']] = true;
Daniel@0 439 }
Daniel@0 440 }
Daniel@0 441
Daniel@0 442 $this->addRequirement(
Daniel@0 443 isset($timezones[@date_default_timezone_get()]),
Daniel@0 444 sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()),
Daniel@0 445 'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.'
Daniel@0 446 );
Daniel@0 447 }
Daniel@0 448
Daniel@0 449 $this->addRequirement(
Daniel@0 450 function_exists('json_encode'),
Daniel@0 451 'json_encode() must be available',
Daniel@0 452 'Install and enable the <strong>JSON</strong> extension.'
Daniel@0 453 );
Daniel@0 454
Daniel@0 455 $this->addRequirement(
Daniel@0 456 function_exists('session_start'),
Daniel@0 457 'session_start() must be available',
Daniel@0 458 'Install and enable the <strong>session</strong> extension.'
Daniel@0 459 );
Daniel@0 460
Daniel@0 461 $this->addRequirement(
Daniel@0 462 function_exists('ctype_alpha'),
Daniel@0 463 'ctype_alpha() must be available',
Daniel@0 464 'Install and enable the <strong>ctype</strong> extension.'
Daniel@0 465 );
Daniel@0 466
Daniel@0 467 $this->addRequirement(
Daniel@0 468 function_exists('token_get_all'),
Daniel@0 469 'token_get_all() must be available',
Daniel@0 470 'Install and enable the <strong>Tokenizer</strong> extension.'
Daniel@0 471 );
Daniel@0 472
Daniel@0 473 $this->addRequirement(
Daniel@0 474 function_exists('simplexml_import_dom'),
Daniel@0 475 'simplexml_import_dom() must be available',
Daniel@0 476 'Install and enable the <strong>SimpleXML</strong> extension.'
Daniel@0 477 );
Daniel@0 478
Daniel@0 479 if (function_exists('apc_store') && ini_get('apc.enabled')) {
Daniel@0 480 if (version_compare($installedPhpVersion, '5.4.0', '>=')) {
Daniel@0 481 $this->addRequirement(
Daniel@0 482 version_compare(phpversion('apc'), '3.1.13', '>='),
Daniel@0 483 'APC version must be at least 3.1.13 when using PHP 5.4',
Daniel@0 484 'Upgrade your <strong>APC</strong> extension (3.1.13+).'
Daniel@0 485 );
Daniel@0 486 } else {
Daniel@0 487 $this->addRequirement(
Daniel@0 488 version_compare(phpversion('apc'), '3.0.17', '>='),
Daniel@0 489 'APC version must be at least 3.0.17',
Daniel@0 490 'Upgrade your <strong>APC</strong> extension (3.0.17+).'
Daniel@0 491 );
Daniel@0 492 }
Daniel@0 493 }
Daniel@0 494
Daniel@0 495 $this->addPhpIniRequirement('detect_unicode', false);
Daniel@0 496
Daniel@0 497 if (extension_loaded('suhosin')) {
Daniel@0 498 $this->addPhpIniRequirement(
Daniel@0 499 'suhosin.executor.include.whitelist',
Daniel@0 500 create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'),
Daniel@0 501 false,
Daniel@0 502 'suhosin.executor.include.whitelist must be configured correctly in php.ini',
Daniel@0 503 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'
Daniel@0 504 );
Daniel@0 505 }
Daniel@0 506
Daniel@0 507 if (extension_loaded('xdebug')) {
Daniel@0 508 $this->addPhpIniRequirement(
Daniel@0 509 'xdebug.show_exception_trace', false, true
Daniel@0 510 );
Daniel@0 511
Daniel@0 512 $this->addPhpIniRequirement(
Daniel@0 513 'xdebug.scream', false, true
Daniel@0 514 );
Daniel@0 515
Daniel@0 516 $this->addPhpIniRecommendation(
Daniel@0 517 'xdebug.max_nesting_level',
Daniel@0 518 create_function('$cfgValue', 'return $cfgValue > 100;'),
Daniel@0 519 true,
Daniel@0 520 'xdebug.max_nesting_level should be above 100 in php.ini',
Daniel@0 521 'Set "<strong>xdebug.max_nesting_level</strong>" to e.g. "<strong>250</strong>" in php.ini<a href="#phpini">*</a> to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.'
Daniel@0 522 );
Daniel@0 523 }
Daniel@0 524
Daniel@0 525 $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;
Daniel@0 526
Daniel@0 527 $this->addRequirement(
Daniel@0 528 null !== $pcreVersion,
Daniel@0 529 'PCRE extension must be available',
Daniel@0 530 'Install the <strong>PCRE</strong> extension (version 8.0+).'
Daniel@0 531 );
Daniel@0 532
Daniel@0 533 if (extension_loaded('mbstring')) {
Daniel@0 534 $this->addPhpIniRequirement(
Daniel@0 535 'mbstring.func_overload',
Daniel@0 536 create_function('$cfgValue', 'return (int) $cfgValue === 0;'),
Daniel@0 537 true,
Daniel@0 538 'string functions should not be overloaded',
Daniel@0 539 'Set "<strong>mbstring.func_overload</strong>" to <strong>0</strong> in php.ini<a href="#phpini">*</a> to disable function overloading by the mbstring extension.'
Daniel@0 540 );
Daniel@0 541 }
Daniel@0 542
Daniel@0 543 /* optional recommendations follow */
Daniel@0 544
Daniel@0 545 $this->addRecommendation(
Daniel@0 546 file_get_contents(__FILE__) === file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'),
Daniel@0 547 'Requirements file should be up-to-date',
Daniel@0 548 'Your requirements file is outdated. Run composer install and re-check your configuration.'
Daniel@0 549 );
Daniel@0 550
Daniel@0 551 $this->addRecommendation(
Daniel@0 552 version_compare($installedPhpVersion, '5.3.4', '>='),
Daniel@0 553 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions',
Daniel@0 554 'Your project might malfunction randomly due to PHP bug #52083 ("Notice: Trying to get property of non-object"). Install PHP 5.3.4 or newer.'
Daniel@0 555 );
Daniel@0 556
Daniel@0 557 $this->addRecommendation(
Daniel@0 558 version_compare($installedPhpVersion, '5.3.8', '>='),
Daniel@0 559 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156',
Daniel@0 560 'Install PHP 5.3.8 or newer if your project uses annotations.'
Daniel@0 561 );
Daniel@0 562
Daniel@0 563 $this->addRecommendation(
Daniel@0 564 version_compare($installedPhpVersion, '5.4.0', '!='),
Daniel@0 565 'You should not use PHP 5.4.0 due to the PHP bug #61453',
Daniel@0 566 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.'
Daniel@0 567 );
Daniel@0 568
Daniel@0 569 $this->addRecommendation(
Daniel@0 570 version_compare($installedPhpVersion, '5.4.11', '>='),
Daniel@0 571 'When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)',
Daniel@0 572 'Install PHP 5.4.11 or newer if your project uses the logout handler from the Symfony Security Component.'
Daniel@0 573 );
Daniel@0 574
Daniel@0 575 $this->addRecommendation(
Daniel@0 576 (version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<'))
Daniel@0 577 ||
Daniel@0 578 version_compare($installedPhpVersion, '5.4.8', '>='),
Daniel@0 579 'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909',
Daniel@0 580 'Install PHP 5.3.18+ or PHP 5.4.8+ if you want nice error messages for all fatal errors in the development environment.'
Daniel@0 581 );
Daniel@0 582
Daniel@0 583 if (null !== $pcreVersion) {
Daniel@0 584 $this->addRecommendation(
Daniel@0 585 $pcreVersion >= 8.0,
Daniel@0 586 sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion),
Daniel@0 587 '<strong>PCRE 8.0+</strong> is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.'
Daniel@0 588 );
Daniel@0 589 }
Daniel@0 590
Daniel@0 591 $this->addRecommendation(
Daniel@0 592 class_exists('DomDocument'),
Daniel@0 593 'PHP-DOM and PHP-XML modules should be installed',
Daniel@0 594 'Install and enable the <strong>PHP-DOM</strong> and the <strong>PHP-XML</strong> modules.'
Daniel@0 595 );
Daniel@0 596
Daniel@0 597 $this->addRecommendation(
Daniel@0 598 function_exists('mb_strlen'),
Daniel@0 599 'mb_strlen() should be available',
Daniel@0 600 'Install and enable the <strong>mbstring</strong> extension.'
Daniel@0 601 );
Daniel@0 602
Daniel@0 603 $this->addRecommendation(
Daniel@0 604 function_exists('iconv'),
Daniel@0 605 'iconv() should be available',
Daniel@0 606 'Install and enable the <strong>iconv</strong> extension.'
Daniel@0 607 );
Daniel@0 608
Daniel@0 609 $this->addRecommendation(
Daniel@0 610 function_exists('utf8_decode'),
Daniel@0 611 'utf8_decode() should be available',
Daniel@0 612 'Install and enable the <strong>XML</strong> extension.'
Daniel@0 613 );
Daniel@0 614
Daniel@0 615 $this->addRecommendation(
Daniel@0 616 function_exists('filter_var'),
Daniel@0 617 'filter_var() should be available',
Daniel@0 618 'Install and enable the <strong>filter</strong> extension.'
Daniel@0 619 );
Daniel@0 620
Daniel@0 621 if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
Daniel@0 622 $this->addRecommendation(
Daniel@0 623 function_exists('posix_isatty'),
Daniel@0 624 'posix_isatty() should be available',
Daniel@0 625 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).'
Daniel@0 626 );
Daniel@0 627 }
Daniel@0 628
Daniel@0 629 $this->addRecommendation(
Daniel@0 630 class_exists('Locale'),
Daniel@0 631 'intl extension should be available',
Daniel@0 632 'Install and enable the <strong>intl</strong> extension (used for validators).'
Daniel@0 633 );
Daniel@0 634
Daniel@0 635 if (class_exists('Collator')) {
Daniel@0 636 $this->addRecommendation(
Daniel@0 637 null !== new Collator('fr_FR'),
Daniel@0 638 'intl extension should be correctly configured',
Daniel@0 639 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'
Daniel@0 640 );
Daniel@0 641 }
Daniel@0 642
Daniel@0 643 if (class_exists('Locale')) {
Daniel@0 644 if (defined('INTL_ICU_VERSION')) {
Daniel@0 645 $version = INTL_ICU_VERSION;
Daniel@0 646 } else {
Daniel@0 647 $reflector = new ReflectionExtension('intl');
Daniel@0 648
Daniel@0 649 ob_start();
Daniel@0 650 $reflector->info();
Daniel@0 651 $output = strip_tags(ob_get_clean());
Daniel@0 652
Daniel@0 653 preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
Daniel@0 654 $version = $matches[1];
Daniel@0 655 }
Daniel@0 656
Daniel@0 657 $this->addRecommendation(
Daniel@0 658 version_compare($version, '4.0', '>='),
Daniel@0 659 'intl ICU version should be at least 4+',
Daniel@0 660 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
Daniel@0 661 );
Daniel@0 662 }
Daniel@0 663
Daniel@0 664 $accelerator =
Daniel@0 665 (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'))
Daniel@0 666 ||
Daniel@0 667 (extension_loaded('apc') && ini_get('apc.enabled'))
Daniel@0 668 ||
Daniel@0 669 (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable'))
Daniel@0 670 ||
Daniel@0 671 (extension_loaded('Zend OPcache') && ini_get('opcache.enable'))
Daniel@0 672 ||
Daniel@0 673 (extension_loaded('xcache') && ini_get('xcache.cacher'))
Daniel@0 674 ||
Daniel@0 675 (extension_loaded('wincache') && ini_get('wincache.ocenabled'))
Daniel@0 676 ;
Daniel@0 677
Daniel@0 678 $this->addRecommendation(
Daniel@0 679 $accelerator,
Daniel@0 680 'a PHP accelerator should be installed',
Daniel@0 681 'Install and/or enable a <strong>PHP accelerator</strong> (highly recommended).'
Daniel@0 682 );
Daniel@0 683
Daniel@0 684 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
Daniel@0 685 $this->addRecommendation(
Daniel@0 686 $this->getRealpathCacheSize() > 1000,
Daniel@0 687 'realpath_cache_size should be above 1024 in php.ini',
Daniel@0 688 'Set "<strong>realpath_cache_size</strong>" to e.g. "<strong>1024</strong>" in php.ini<a href="#phpini">*</a> to improve performance on windows.'
Daniel@0 689 );
Daniel@0 690 }
Daniel@0 691
Daniel@0 692 $this->addPhpIniRecommendation('short_open_tag', false);
Daniel@0 693
Daniel@0 694 $this->addPhpIniRecommendation('magic_quotes_gpc', false, true);
Daniel@0 695
Daniel@0 696 $this->addPhpIniRecommendation('register_globals', false, true);
Daniel@0 697
Daniel@0 698 $this->addPhpIniRecommendation('session.auto_start', false);
Daniel@0 699
Daniel@0 700 $this->addRecommendation(
Daniel@0 701 class_exists('PDO'),
Daniel@0 702 'PDO should be installed',
Daniel@0 703 'Install <strong>PDO</strong> (mandatory for Doctrine).'
Daniel@0 704 );
Daniel@0 705
Daniel@0 706 if (class_exists('PDO')) {
Daniel@0 707 $drivers = PDO::getAvailableDrivers();
Daniel@0 708 $this->addRecommendation(
Daniel@0 709 count($drivers) > 0,
Daniel@0 710 sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'),
Daniel@0 711 'Install <strong>PDO drivers</strong> (mandatory for Doctrine).'
Daniel@0 712 );
Daniel@0 713 }
Daniel@0 714 }
Daniel@0 715
Daniel@0 716 /**
Daniel@0 717 * Loads realpath_cache_size from php.ini and converts it to int.
Daniel@0 718 *
Daniel@0 719 * (e.g. 16k is converted to 16384 int)
Daniel@0 720 *
Daniel@0 721 * @return int
Daniel@0 722 */
Daniel@0 723 protected function getRealpathCacheSize()
Daniel@0 724 {
Daniel@0 725 $size = ini_get('realpath_cache_size');
Daniel@0 726 $size = trim($size);
Daniel@0 727 $unit = strtolower(substr($size, -1, 1));
Daniel@0 728 switch ($unit) {
Daniel@0 729 case 'g':
Daniel@0 730 return $size * 1024 * 1024 * 1024;
Daniel@0 731 case 'm':
Daniel@0 732 return $size * 1024 * 1024;
Daniel@0 733 case 'k':
Daniel@0 734 return $size * 1024;
Daniel@0 735 default:
Daniel@0 736 return (int) $size;
Daniel@0 737 }
Daniel@0 738 }
Daniel@0 739 }