SymfonyRequirements.php 33 KB

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