function fileLocator($file = null, $maxDepth = 10, $currentDir = ".") { if (empty($file)) { return false; } elseif (file_exists($currentDir . "/{$file}")) { return $currentDir; } elseif (--$maxDepth) { return fileLocator($file, $maxDepth, $currentDir . "/.."); } else { return false; } }
/** * Constructor that initializes the requirements. */ public function __construct() { /* mandatory requirements follow */ $installedPhpVersion = phpversion(); $projectBaseDir = fileLocator('composer.json'); $this->addRequirement(version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='), sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion), sprintf('You are running PHP version "<strong>%s</strong>", but CIX needs at least PHP "<strong>%s</strong>" to run. Before using CIX Distribution, upgrade your PHP installation, preferably to the latest version.', $installedPhpVersion, self::REQUIRED_PHP_VERSION), sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)); if (!$projectBaseDir) { $this->addRequirement(!empty($projectBaseDir), 'Composer Configuration file not found!', 'Invalid project directory! composer.json file may be deleted or not found. Please download the CIX distribution again!'); return; } $json_exists = function_exists('json_encode'); $this->addRequirement($json_exists, 'json_encode() must be available', '<strong>JSON</strong> extension must be available, even to run this checking script, Install and enable the <strong>JSON</strong> extension.'); if (!$json_exists) { return; } $json = json_decode(file_get_contents($projectBaseDir . "/composer.json")); $composerInstalled = is_dir($projectBaseDir . '/vendor/composer'); $this->addRequirement($composerInstalled, 'Vendor libraries must be installed', 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. ' . '<br>Then run "<strong>php composer.phar install</strong>" to install them.'); $applicationDir = $projectBaseDir . "/" . $json->extra->{"ci-app-dir"}; if ($composerInstalled) { $this->addRequirement(is_dir($applicationDir), 'Application must be installed', 'Application is missing.' . '<br> Run "<strong>php composer.phar install</strong>" to install application.'); } $baseDir = $json->extra->{"ci-app-dir"}; if (is_dir($applicationDir)) { $this->addDirectoryRequirement($baseDir, $applicationDir, '/cache'); $this->addDirectoryRequirement($baseDir, $applicationDir, '/logs'); } $webRoot = $json->extra->{"ci-web-dir"}; $webPath = $projectBaseDir . "/" . $webRoot; $this->addDirectoryRequirement($webRoot, $webPath, '/uploads'); $this->addDirectoryRequirement($webRoot, $webPath, '/assets/css/cache'); $this->addDirectoryRequirement($webRoot, $webPath, '/assets/js/cache'); $this->addPhpIniRequirement('date.timezone', true, false, 'date.timezone setting must be set', 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Ashia/Dhaka).'); if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { $timezones = array(); foreach (DateTimeZone::listAbbreviations() as $abbreviations) { foreach ($abbreviations as $abbreviation) { $timezones[$abbreviation['timezone_id']] = true; } } $this->addRequirement(isset($timezones[date_default_timezone_get()]), sprintf('Configured default timezone "%s" must be supported by your installation of PHP', date_default_timezone_get()), '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>.'); } $this->addRequirement(function_exists('session_start'), 'session_start() must be available', 'Install and enable the <strong>session</strong> extension.'); if (function_exists('apc_store') && ini_get('apc.enabled')) { if (version_compare($installedPhpVersion, '5.4.0', '>=')) { $this->addRequirement(version_compare(phpversion('apc'), '3.1.13', '>='), 'APC version must be at least 3.1.13 when using PHP 5.4', 'Upgrade your <strong>APC</strong> extension (3.1.13+).'); } else { $this->addRequirement(version_compare(phpversion('apc'), '3.0.17', '>='), 'APC version must be at least 3.0.17', 'Upgrade your <strong>APC</strong> extension (3.0.17+).'); } } $this->addPhpIniRequirement('detect_unicode', false); if (extension_loaded('suhosin')) { $this->addPhpIniRequirement('suhosin.executor.include.whitelist', create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), false, 'suhosin.executor.include.whitelist must be configured correctly in php.ini', 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'); } /* optional recommendations follow */ $this->addRecommendation(version_compare($installedPhpVersion, '5.3.4', '>='), 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions', '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.'); $this->addRecommendation(function_exists('mb_strlen'), 'mb_strlen() should be available', 'Install and enable the <strong>mbstring</strong> extension.'); $this->addRecommendation(function_exists('iconv'), 'iconv() should be available', 'Install and enable the <strong>iconv</strong> extension.'); $this->addRecommendation(function_exists('utf8_decode'), 'utf8_decode() should be available', 'Install and enable the <strong>XML</strong> extension.'); if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $this->addRecommendation(function_exists('posix_isatty'), 'posix_isatty() should be available', 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).'); } $this->addPhpIniRecommendation('short_open_tag', false); $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); $this->addPhpIniRecommendation('register_globals', false, true); $this->addPhpIniRecommendation('session.auto_start', false); }