@@ -168,6 +168,9 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $
168
168
*/
169
169
class RequirementCollection implements IteratorAggregate
170
170
{
171
+ /**
172
+ * @var Requirement[]
173
+ */
171
174
private $ requirements = array ();
172
175
173
176
/**
@@ -265,7 +268,7 @@ public function addCollection(RequirementCollection $collection)
265
268
/**
266
269
* Returns both requirements and recommendations.
267
270
*
268
- * @return array Array of Requirement instances
271
+ * @return Requirement[]
269
272
*/
270
273
public function all ()
271
274
{
@@ -275,7 +278,7 @@ public function all()
275
278
/**
276
279
* Returns all mandatory requirements.
277
280
*
278
- * @return array Array of Requirement instances
281
+ * @return Requirement[]
279
282
*/
280
283
public function getRequirements ()
281
284
{
@@ -292,7 +295,7 @@ public function getRequirements()
292
295
/**
293
296
* Returns the mandatory requirements that were not met.
294
297
*
295
- * @return array Array of Requirement instances
298
+ * @return Requirement[]
296
299
*/
297
300
public function getFailedRequirements ()
298
301
{
@@ -309,7 +312,7 @@ public function getFailedRequirements()
309
312
/**
310
313
* Returns all optional recommendations.
311
314
*
312
- * @return array Array of Requirement instances
315
+ * @return Requirement[]
313
316
*/
314
317
public function getRecommendations ()
315
318
{
@@ -326,7 +329,7 @@ public function getRecommendations()
326
329
/**
327
330
* Returns the recommendations that were not met.
328
331
*
329
- * @return array Array of Requirement instances
332
+ * @return Requirement[]
330
333
*/
331
334
public function getFailedRecommendations ()
332
335
{
@@ -376,7 +379,8 @@ public function getPhpIniConfigPath()
376
379
*/
377
380
class SymfonyRequirements extends RequirementCollection
378
381
{
379
- const REQUIRED_PHP_VERSION = '5.3.3 ' ;
382
+ const LEGACY_REQUIRED_PHP_VERSION = '5.3.3 ' ;
383
+ const REQUIRED_PHP_VERSION = '5.5.9 ' ;
380
384
381
385
/**
382
386
* Constructor that initializes the requirements.
@@ -386,16 +390,26 @@ public function __construct()
386
390
/* mandatory requirements follow */
387
391
388
392
$ installedPhpVersion = phpversion ();
393
+ $ requiredPhpVersion = $ this ->getPhpRequiredVersion ();
389
394
390
- $ this ->addRequirement (
391
- version_compare ($ installedPhpVersion , self ::REQUIRED_PHP_VERSION , '>= ' ),
392
- sprintf ('PHP version must be at least %s (%s installed) ' , self ::REQUIRED_PHP_VERSION , $ installedPhpVersion ),
393
- sprintf ('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
394
- Before using Symfony, upgrade your PHP installation, preferably to the latest version. ' ,
395
- $ installedPhpVersion , self ::REQUIRED_PHP_VERSION ),
396
- sprintf ('Install PHP %s or newer (installed version is %s) ' , self ::REQUIRED_PHP_VERSION , $ installedPhpVersion )
395
+ $ this ->addRecommendation (
396
+ $ requiredPhpVersion ,
397
+ 'Vendors should be installed in order to check all requirements. ' ,
398
+ 'Run the <code>composer install</code> command. ' ,
399
+ 'Run the "composer install" command. '
397
400
);
398
401
402
+ if (false !== $ requiredPhpVersion ) {
403
+ $ this ->addRequirement (
404
+ version_compare ($ installedPhpVersion , $ requiredPhpVersion , '>= ' ),
405
+ sprintf ('PHP version must be at least %s (%s installed) ' , $ requiredPhpVersion , $ installedPhpVersion ),
406
+ sprintf ('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
407
+ Before using Symfony, upgrade your PHP installation, preferably to the latest version. ' ,
408
+ $ installedPhpVersion , $ requiredPhpVersion ),
409
+ sprintf ('Install PHP %s or newer (installed version is %s) ' , $ requiredPhpVersion , $ installedPhpVersion )
410
+ );
411
+ }
412
+
399
413
$ this ->addRequirement (
400
414
version_compare ($ installedPhpVersion , '5.3.16 ' , '!= ' ),
401
415
'PHP version must not be 5.3.16 as Symfony won \'t work properly with it ' ,
@@ -433,7 +447,7 @@ public function __construct()
433
447
);
434
448
}
435
449
436
- if (version_compare ($ installedPhpVersion , self :: REQUIRED_PHP_VERSION , '>= ' )) {
450
+ if (false !== $ requiredPhpVersion && version_compare ($ installedPhpVersion , $ requiredPhpVersion , '>= ' )) {
437
451
$ timezones = array ();
438
452
foreach (DateTimeZone::listAbbreviations () as $ abbreviations ) {
439
453
foreach ($ abbreviations as $ abbreviation ) {
@@ -725,9 +739,9 @@ function_exists('posix_isatty'),
725
739
726
740
if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
727
741
$ this ->addRecommendation (
728
- $ this ->getRealpathCacheSize () > 1000 ,
729
- 'realpath_cache_size should be above 1024 in php.ini ' ,
730
- 'Set "<strong>realpath_cache_size</strong>" to e.g. "<strong>1024 </strong>" in php.ini<a href="#phpini">*</a> to improve performance on windows . '
742
+ $ this ->getRealpathCacheSize () >= 5 * 1024 * 1024 ,
743
+ 'realpath_cache_size should be at least 5M in php.ini ' ,
744
+ '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 . '
731
745
);
732
746
}
733
747
@@ -778,4 +792,28 @@ protected function getRealpathCacheSize()
778
792
return (int ) $ size ;
779
793
}
780
794
}
795
+
796
+ /**
797
+ * Defines PHP required version from Symfony version.
798
+ *
799
+ * @return string|false The PHP required version or false if it could not be guessed
800
+ */
801
+ protected function getPhpRequiredVersion ()
802
+ {
803
+ if (!file_exists ($ path = __DIR__ .'/../composer.lock ' )) {
804
+ return false ;
805
+ }
806
+
807
+ $ composerLock = json_decode (file_get_contents ($ path ), true );
808
+ foreach ($ composerLock ['packages ' ] as $ package ) {
809
+ $ name = $ package ['name ' ];
810
+ if ('symfony/symfony ' !== $ name && 'symfony/http-kernel ' !== $ name ) {
811
+ continue ;
812
+ }
813
+
814
+ return (int ) $ package ['version ' ][1 ] > 2 ? self ::REQUIRED_PHP_VERSION : self ::LEGACY_REQUIRED_PHP_VERSION ;
815
+ }
816
+
817
+ return false ;
818
+ }
781
819
}
0 commit comments