SymfonyRequirements.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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 overriden 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 Boolean $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 Boolean $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 = (Boolean) $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 = (Boolean) $optional;
  53. }
  54. /**
  55. * Returns whether the requirement is fulfilled.
  56. *
  57. * @return Boolean 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 Boolean 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 Boolean|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 Boolean $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 Boolean $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. private $requirements = array();
  156. /**
  157. * Gets the current RequirementCollection as an Iterator.
  158. *
  159. * @return Traversable A Traversable interface
  160. */
  161. public function getIterator()
  162. {
  163. return new ArrayIterator($this->requirements);
  164. }
  165. /**
  166. * Adds a Requirement.
  167. *
  168. * @param Requirement $requirement A Requirement instance
  169. */
  170. public function add(Requirement $requirement)
  171. {
  172. $this->requirements[] = $requirement;
  173. }
  174. /**
  175. * Adds a mandatory requirement.
  176. *
  177. * @param Boolean $fulfilled Whether the requirement is fulfilled
  178. * @param string $testMessage The message for testing the requirement
  179. * @param string $helpHtml The help text formatted in HTML for resolving the problem
  180. * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
  181. */
  182. public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null)
  183. {
  184. $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false));
  185. }
  186. /**
  187. * Adds an optional recommendation.
  188. *
  189. * @param Boolean $fulfilled Whether the recommendation is fulfilled
  190. * @param string $testMessage The message for testing the recommendation
  191. * @param string $helpHtml The help text formatted in HTML for resolving the problem
  192. * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
  193. */
  194. public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null)
  195. {
  196. $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true));
  197. }
  198. /**
  199. * Adds a mandatory requirement in form of a php.ini configuration.
  200. *
  201. * @param string $cfgName The configuration name used for ini_get()
  202. * @param Boolean|callback $evaluation Either a Boolean indicating whether the configuration should evaluate to true or false,
  203. or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
  204. * @param Boolean $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
  205. This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
  206. Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
  207. * @param string $testMessage The message for testing the requirement (when null and $evaluation is a Boolean a default message is derived)
  208. * @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)
  209. * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
  210. */
  211. public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
  212. {
  213. $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false));
  214. }
  215. /**
  216. * Adds an optional recommendation in form of a php.ini configuration.
  217. *
  218. * @param string $cfgName The configuration name used for ini_get()
  219. * @param Boolean|callback $evaluation Either a Boolean indicating whether the configuration should evaluate to true or false,
  220. or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
  221. * @param Boolean $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
  222. This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
  223. Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
  224. * @param string $testMessage The message for testing the requirement (when null and $evaluation is a Boolean a default message is derived)
  225. * @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)
  226. * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
  227. */
  228. public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
  229. {
  230. $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true));
  231. }
  232. /**
  233. * Adds a requirement collection to the current set of requirements.
  234. *
  235. * @param RequirementCollection $collection A RequirementCollection instance
  236. */
  237. public function addCollection(RequirementCollection $collection)
  238. {
  239. $this->requirements = array_merge($this->requirements, $collection->all());
  240. }
  241. /**
  242. * Returns both requirements and recommendations.
  243. *
  244. * @return array Array of Requirement instances
  245. */
  246. public function all()
  247. {
  248. return $this->requirements;
  249. }
  250. /**
  251. * Returns all mandatory requirements.
  252. *
  253. * @return array Array of Requirement instances
  254. */
  255. public function getRequirements()
  256. {
  257. $array = array();
  258. foreach ($this->requirements as $req) {
  259. if (!$req->isOptional()) {
  260. $array[] = $req;
  261. }
  262. }
  263. return $array;
  264. }
  265. /**
  266. * Returns the mandatory requirements that were not met.
  267. *
  268. * @return array Array of Requirement instances
  269. */
  270. public function getFailedRequirements()
  271. {
  272. $array = array();
  273. foreach ($this->requirements as $req) {
  274. if (!$req->isFulfilled() && !$req->isOptional()) {
  275. $array[] = $req;
  276. }
  277. }
  278. return $array;
  279. }
  280. /**
  281. * Returns all optional recommmendations.
  282. *
  283. * @return array Array of Requirement instances
  284. */
  285. public function getRecommendations()
  286. {
  287. $array = array();
  288. foreach ($this->requirements as $req) {
  289. if ($req->isOptional()) {
  290. $array[] = $req;
  291. }
  292. }
  293. return $array;
  294. }
  295. /**
  296. * Returns the recommendations that were not met.
  297. *
  298. * @return array Array of Requirement instances
  299. */
  300. public function getFailedRecommendations()
  301. {
  302. $array = array();
  303. foreach ($this->requirements as $req) {
  304. if (!$req->isFulfilled() && $req->isOptional()) {
  305. $array[] = $req;
  306. }
  307. }
  308. return $array;
  309. }
  310. /**
  311. * Returns whether a php.ini configuration is not correct.
  312. *
  313. * @return Boolean php.ini configuration problem?
  314. */
  315. public function hasPhpIniConfigIssue()
  316. {
  317. foreach ($this->requirements as $req) {
  318. if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) {
  319. return true;
  320. }
  321. }
  322. return false;
  323. }
  324. /**
  325. * Returns the PHP configuration file (php.ini) path.
  326. *
  327. * @return string|false php.ini file path
  328. */
  329. public function getPhpIniConfigPath()
  330. {
  331. return get_cfg_var('cfg_file_path');
  332. }
  333. }
  334. /**
  335. * This class specifies all requirements and optional recommendations that
  336. * are necessary to run the Symfony Standard Edition.
  337. *
  338. * @author Tobias Schultze <http://tobion.de>
  339. * @author Fabien Potencier <fabien@symfony.com>
  340. */
  341. class SymfonyRequirements extends RequirementCollection
  342. {
  343. const REQUIRED_PHP_VERSION = '5.3.3';
  344. /**
  345. * Constructor that initializes the requirements.
  346. */
  347. public function __construct()
  348. {
  349. /* mandatory requirements follow */
  350. $installedPhpVersion = phpversion();
  351. $this->addRequirement(
  352. version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='),
  353. sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion),
  354. sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
  355. Before using Symfony, upgrade your PHP installation, preferably to the latest version.',
  356. $installedPhpVersion, self::REQUIRED_PHP_VERSION),
  357. sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)
  358. );
  359. $this->addRequirement(
  360. version_compare($installedPhpVersion, '5.3.16', '!='),
  361. 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it',
  362. 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)'
  363. );
  364. $this->addRequirement(
  365. is_dir(__DIR__.'/../vendor/composer'),
  366. 'Vendor libraries must be installed',
  367. 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. ' .
  368. 'Then run "<strong>php composer.phar install</strong>" to install them.'
  369. );
  370. $baseDir = basename(__DIR__);
  371. $this->addRequirement(
  372. is_writable(__DIR__.'/cache'),
  373. "$baseDir/cache/ directory must be writable",
  374. "Change the permissions of the \"<strong>$baseDir/cache/</strong>\" directory so that the web server can write into it."
  375. );
  376. $this->addRequirement(
  377. is_writable(__DIR__.'/logs'),
  378. "$baseDir/logs/ directory must be writable",
  379. "Change the permissions of the \"<strong>$baseDir/logs/</strong>\" directory so that the web server can write into it."
  380. );
  381. $this->addPhpIniRequirement(
  382. 'date.timezone', true, false,
  383. 'date.timezone setting must be set',
  384. 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).'
  385. );
  386. if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
  387. $timezones = array();
  388. foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
  389. foreach ($abbreviations as $abbreviation) {
  390. $timezones[$abbreviation['timezone_id']] = true;
  391. }
  392. }
  393. $this->addRequirement(
  394. isset($timezones[date_default_timezone_get()]),
  395. sprintf('Configured default timezone "%s" must be supported by your installation of PHP', date_default_timezone_get()),
  396. '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>.'
  397. );
  398. }
  399. $this->addRequirement(
  400. function_exists('json_encode'),
  401. 'json_encode() must be available',
  402. 'Install and enable the <strong>JSON</strong> extension.'
  403. );
  404. $this->addRequirement(
  405. function_exists('session_start'),
  406. 'session_start() must be available',
  407. 'Install and enable the <strong>session</strong> extension.'
  408. );
  409. $this->addRequirement(
  410. function_exists('ctype_alpha'),
  411. 'ctype_alpha() must be available',
  412. 'Install and enable the <strong>ctype</strong> extension.'
  413. );
  414. $this->addRequirement(
  415. function_exists('token_get_all'),
  416. 'token_get_all() must be available',
  417. 'Install and enable the <strong>Tokenizer</strong> extension.'
  418. );
  419. $this->addRequirement(
  420. function_exists('simplexml_import_dom'),
  421. 'simplexml_import_dom() must be available',
  422. 'Install and enable the <strong>SimpleXML</strong> extension.'
  423. );
  424. if (function_exists('apc_store') && ini_get('apc.enabled')) {
  425. if (version_compare($installedPhpVersion, '5.4.0', '>=')) {
  426. $this->addRequirement(
  427. version_compare(phpversion('apc'), '3.1.13', '>='),
  428. 'APC version must be at least 3.1.13 when using PHP 5.4',
  429. 'Upgrade your <strong>APC</strong> extension (3.1.13+).'
  430. );
  431. } else {
  432. $this->addRequirement(
  433. version_compare(phpversion('apc'), '3.0.17', '>='),
  434. 'APC version must be at least 3.0.17',
  435. 'Upgrade your <strong>APC</strong> extension (3.0.17+).'
  436. );
  437. }
  438. }
  439. $this->addPhpIniRequirement('detect_unicode', false);
  440. if (extension_loaded('suhosin')) {
  441. $this->addPhpIniRequirement(
  442. 'suhosin.executor.include.whitelist',
  443. create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'),
  444. false,
  445. 'suhosin.executor.include.whitelist must be configured correctly in php.ini',
  446. 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'
  447. );
  448. }
  449. if (extension_loaded('xdebug')) {
  450. $this->addPhpIniRequirement(
  451. 'xdebug.show_exception_trace', false, true
  452. );
  453. $this->addPhpIniRequirement(
  454. 'xdebug.scream', false, true
  455. );
  456. $this->addPhpIniRecommendation(
  457. 'xdebug.max_nesting_level',
  458. create_function('$cfgValue', 'return $cfgValue > 100;'),
  459. true,
  460. 'xdebug.max_nesting_level should be above 100 in php.ini',
  461. '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.'
  462. );
  463. }
  464. $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;
  465. $this->addRequirement(
  466. null !== $pcreVersion,
  467. 'PCRE extension must be available',
  468. 'Install the <strong>PCRE</strong> extension (version 8.0+).'
  469. );
  470. /* optional recommendations follow */
  471. $this->addRecommendation(
  472. file_get_contents(__FILE__) === file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'),
  473. 'Requirements file should be up-to-date',
  474. 'Your requirements file is outdated. Run composer install and re-check your configuration.'
  475. );
  476. $this->addRecommendation(
  477. version_compare($installedPhpVersion, '5.3.4', '>='),
  478. 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions',
  479. '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.'
  480. );
  481. $this->addRecommendation(
  482. version_compare($installedPhpVersion, '5.3.8', '>='),
  483. 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156',
  484. 'Install PHP 5.3.8 or newer if your project uses annotations.'
  485. );
  486. $this->addRecommendation(
  487. version_compare($installedPhpVersion, '5.4.0', '!='),
  488. 'You should not use PHP 5.4.0 due to the PHP bug #61453',
  489. '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.'
  490. );
  491. if (null !== $pcreVersion) {
  492. $this->addRecommendation(
  493. $pcreVersion >= 8.0,
  494. sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion),
  495. '<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.'
  496. );
  497. }
  498. $this->addRecommendation(
  499. class_exists('DomDocument'),
  500. 'PHP-XML module should be installed',
  501. 'Install and enable the <strong>PHP-XML</strong> module.'
  502. );
  503. $this->addRecommendation(
  504. function_exists('mb_strlen'),
  505. 'mb_strlen() should be available',
  506. 'Install and enable the <strong>mbstring</strong> extension.'
  507. );
  508. $this->addRecommendation(
  509. function_exists('iconv'),
  510. 'iconv() should be available',
  511. 'Install and enable the <strong>iconv</strong> extension.'
  512. );
  513. $this->addRecommendation(
  514. function_exists('utf8_decode'),
  515. 'utf8_decode() should be available',
  516. 'Install and enable the <strong>XML</strong> extension.'
  517. );
  518. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  519. $this->addRecommendation(
  520. function_exists('posix_isatty'),
  521. 'posix_isatty() should be available',
  522. 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).'
  523. );
  524. }
  525. $this->addRecommendation(
  526. class_exists('Locale'),
  527. 'intl extension should be available',
  528. 'Install and enable the <strong>intl</strong> extension (used for validators).'
  529. );
  530. if (class_exists('Collator')) {
  531. $this->addRecommendation(
  532. null !== new Collator('fr_FR'),
  533. 'intl extension should be correctly configured',
  534. 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'
  535. );
  536. }
  537. if (class_exists('Locale')) {
  538. if (defined('INTL_ICU_VERSION')) {
  539. $version = INTL_ICU_VERSION;
  540. } else {
  541. $reflector = new ReflectionExtension('intl');
  542. ob_start();
  543. $reflector->info();
  544. $output = strip_tags(ob_get_clean());
  545. preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
  546. $version = $matches[1];
  547. }
  548. $this->addRecommendation(
  549. version_compare($version, '4.0', '>='),
  550. 'intl ICU version should be at least 4+',
  551. 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
  552. );
  553. }
  554. $accelerator =
  555. (function_exists('apc_store') && ini_get('apc.enabled'))
  556. ||
  557. function_exists('eaccelerator_put') && ini_get('eaccelerator.enable')
  558. ||
  559. function_exists('xcache_set')
  560. ;
  561. $this->addRecommendation(
  562. $accelerator,
  563. 'a PHP accelerator should be installed',
  564. 'Install and enable a <strong>PHP accelerator</strong> like APC (highly recommended).'
  565. );
  566. $this->addPhpIniRecommendation('short_open_tag', false);
  567. $this->addPhpIniRecommendation('magic_quotes_gpc', false, true);
  568. $this->addPhpIniRecommendation('register_globals', false, true);
  569. $this->addPhpIniRecommendation('session.auto_start', false);
  570. $this->addRecommendation(
  571. class_exists('PDO'),
  572. 'PDO should be installed',
  573. 'Install <strong>PDO</strong> (mandatory for Doctrine).'
  574. );
  575. if (class_exists('PDO')) {
  576. $drivers = PDO::getAvailableDrivers();
  577. $this->addRecommendation(
  578. count($drivers),
  579. sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'),
  580. 'Install <strong>PDO drivers</strong> (mandatory for Doctrine).'
  581. );
  582. }
  583. }
  584. }