Skip to content

Commit

Permalink
Add Environment value to be checked + xdebug recommendation on produc…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ghisleouf committed Nov 9, 2018
1 parent 22b9b46 commit 8ba54a8
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions src/SymfonyRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*
* @author Tobias Schultze <http://tobion.de>
* @author Fabien Potencier <[email protected]>
* @author Fabien Potencier <[email protected]>
*/
class SymfonyRequirements extends RequirementCollection
{
const REQUIRED_PHP_VERSION = '5.5.9';
const REQUIRED_PHP_VERSION = '7.2.8';

public function __construct($rootDir)
{
Expand All @@ -30,6 +31,8 @@ public function __construct($rootDir)

$rootDir = $this->getComposerRootDir($rootDir);
$options = $this->readComposer($rootDir);
$appEnv = getenv('APP_ENV') ?? 'dev';


$this->addRequirement(
version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='),
Expand All @@ -44,7 +47,7 @@ public function __construct($rootDir)
is_dir($rootDir.'/vendor/composer'),
'Vendor libraries must be installed',
'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
'Then run "<strong>php composer.phar install</strong>" to install them.'
'Then run "<strong>php composer.phar install</strong>" to install them.'
);

if (is_dir($cacheDir = $rootDir.'/'.$options['var-dir'].'/cache')) {
Expand Down Expand Up @@ -143,24 +146,36 @@ function($cfgValue) { return false !== stripos($cfgValue, 'phar'); },
);
}

if (extension_loaded('xdebug')) {
$this->addPhpConfigRequirement(
'xdebug.show_exception_trace', false, true
);
if ($appEnv !== 'prod' ) {
if (extension_loaded('xdebug')) {
$this->addPhpConfigRequirement(
'xdebug.show_exception_trace', false, true
);

$this->addPhpConfigRequirement(
'xdebug.scream', false, true
);
$this->addPhpConfigRequirement(
'xdebug.scream', false, true
);

$this->addPhpConfigRecommendation(
'xdebug.max_nesting_level',
function ($cfgValue) { return $cfgValue > 100; },
true,
'xdebug.max_nesting_level should be above 100 in php.ini',
'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.'
);
}
} else {
$this->addPhpConfigRecommendation(
'xdebug.max_nesting_level',
function ($cfgValue) { return $cfgValue > 100; },
true,
'xdebug.max_nesting_level should be above 100 in php.ini',
'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.'
'xdebug.enabled',
extension_loaded('xdebug'),
false,
'xdebug should be disabled',
'To increase platform performances, <strong>xdebug</strong> should be disabled in production mode.',
'To increase platform performances, xdebug should be disabled in production mode.'
);
}


$pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;

$this->addRequirement(
Expand Down Expand Up @@ -315,13 +330,17 @@ function ($cfgValue) { return (int) $cfgValue === 0; },

$this->addPhpConfigRecommendation('session.auto_start', false);

$this->addPhpConfigRecommendation(
'xdebug.max_nesting_level',
function ($cfgValue) { return $cfgValue > 100; },
true,
'xdebug.max_nesting_level should be above 100 in php.ini',
'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.'
);
if ($appEnv !== 'prod' ) {
$this->addPhpConfigRecommendation(
'xdebug.max_nesting_level',
function ( $cfgValue ) {
return $cfgValue > 100;
},
true,
'xdebug.max_nesting_level should be above 100 in php.ini',
'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.'
);
}

$this->addPhpConfigRecommendation(
'post_max_size',
Expand Down Expand Up @@ -412,7 +431,7 @@ private function getRealpathCacheSize()
*
* @return int
*/
private function getPostMaxSize()
public function getPostMaxSize()
{
return $this->convertShorthandSize(ini_get('post_max_size'));
}
Expand All @@ -422,7 +441,7 @@ private function getPostMaxSize()
*
* @return int
*/
private function getMemoryLimit()
public function getMemoryLimit()
{
return $this->convertShorthandSize(ini_get('memory_limit'));
}
Expand All @@ -432,12 +451,12 @@ private function getMemoryLimit()
*
* @return int
*/
private function getUploadMaxFilesize()
public function getUploadMaxFilesize()
{
return $this->convertShorthandSize(ini_get('upload_max_filesize'));
}

private function getComposerRootDir($rootDir)
public function getComposerRootDir($rootDir)
{
$dir = $rootDir;
while (!file_exists($dir.'/composer.json')) {
Expand Down Expand Up @@ -474,4 +493,4 @@ private function readComposer($rootDir)

return $options;
}
}
}

0 comments on commit 8ba54a8

Please sign in to comment.