From 7a4b234c6df119bf8b27df8a23ab647c27bd69ba Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 14 Sep 2018 15:36:25 +0300 Subject: [PATCH] Update Config classes for PHP 7.1 --- system/src/Grav/Common/Config/CompiledBase.php | 10 +++++----- system/src/Grav/Common/Config/CompiledConfig.php | 2 +- system/src/Grav/Common/Config/Config.php | 4 +++- system/src/Grav/Common/Config/Setup.php | 16 ++++++++-------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Config/CompiledBase.php b/system/src/Grav/Common/Config/CompiledBase.php index 1e6379599..6aca8f949 100644 --- a/system/src/Grav/Common/Config/CompiledBase.php +++ b/system/src/Grav/Common/Config/CompiledBase.php @@ -128,7 +128,7 @@ abstract class CompiledBase */ public function checksum() { - if (!isset($this->checksum)) { + if (null === $this->checksum) { $this->checksum = md5(json_encode($this->files) . $this->version); } @@ -197,11 +197,11 @@ abstract class CompiledBase $cache = include $filename; if ( - !is_array($cache) + !\is_array($cache) || !isset($cache['checksum']) || !isset($cache['data']) || !isset($cache['@class']) - || $cache['@class'] != get_class($this) + || $cache['@class'] !== \get_class($this) ) { return false; } @@ -212,7 +212,7 @@ abstract class CompiledBase } $this->createObject($cache['data']); - $this->timestamp = isset($cache['timestamp']) ? $cache['timestamp'] : 0; + $this->timestamp = $cache['timestamp'] ?? 0; $this->finalizeObject(); @@ -243,7 +243,7 @@ abstract class CompiledBase } $cache = [ - '@class' => get_class($this), + '@class' => \get_class($this), 'timestamp' => time(), 'checksum' => $this->checksum(), 'files' => $this->files, diff --git a/system/src/Grav/Common/Config/CompiledConfig.php b/system/src/Grav/Common/Config/CompiledConfig.php index 6f21123aa..955e0d8e6 100644 --- a/system/src/Grav/Common/Config/CompiledConfig.php +++ b/system/src/Grav/Common/Config/CompiledConfig.php @@ -63,7 +63,7 @@ class CompiledConfig extends CompiledBase */ protected function createObject(array $data = []) { - if ($this->withDefaults && empty($data) && is_callable($this->callable)) { + if ($this->withDefaults && empty($data) && \is_callable($this->callable)) { $blueprints = $this->callable; $data = $blueprints()->getDefaults(); } diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index a8e2bdf83..f285d9682 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -16,6 +16,8 @@ use Grav\Common\Utils; class Config extends Data { + public $environment; + /** @var string */ protected $checksum; protected $modified = false; @@ -90,7 +92,7 @@ class Config extends Data { $setup = Grav::instance()['setup']->toArray(); foreach ($setup as $key => $value) { - if ($key === 'streams' || !is_array($value)) { + if ($key === 'streams' || !\is_array($value)) { // Optimized as streams and simple values are fully defined in setup. $this->items[$key] = $value; } else { diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php index 57504f0ee..a889b7af6 100644 --- a/system/src/Grav/Common/Config/Setup.php +++ b/system/src/Grav/Common/Config/Setup.php @@ -133,12 +133,12 @@ class Setup extends Data */ public function __construct($container) { - $environment = null !== static::$environment ? static::$environment : ($container['uri']->environment() ?: 'localhost'); + $environment = static::$environment ?? $container['uri']->environment() ?: 'localhost'; // Pre-load setup.php which contains our initial configuration. // Configuration may contain dynamic parts, which is why we need to always load it. // If "GRAVE_SETUP_PATH" has been defined, use it, otherwise use defaults. - $file = defined('GRAV_SETUP_PATH') ? GRAV_SETUP_PATH : GRAV_ROOT . '/setup.php'; + $file = \defined('GRAV_SETUP_PATH') ? GRAV_SETUP_PATH : GRAV_ROOT . '/setup.php'; $setup = is_file($file) ? (array) include $file : []; // Add default streams defined in beginning of the class. @@ -152,7 +152,7 @@ class Setup extends Data // Set up environment. $this->def('environment', $environment ?: 'cli'); - $this->def('streams.schemes.environment.prefixes', ['' => $environment ? ["user://{$this->environment}"] : []]); + $this->def('streams.schemes.environment.prefixes', ['' => $environment ? ["user://{$environment}"] : []]); } /** @@ -212,8 +212,8 @@ class Setup extends Data $locator->addPath($scheme, '', $config['paths']); } - $override = isset($config['override']) ? $config['override'] : false; - $force = isset($config['force']) ? $config['force'] : false; + $override = $config['override'] ?? false; + $force = $config['force'] ?? false; if (isset($config['prefixes'])) { foreach ((array)$config['prefixes'] as $prefix => $paths) { @@ -232,7 +232,7 @@ class Setup extends Data { $schemes = []; foreach ((array) $this->get('streams.schemes') as $scheme => $config) { - $type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream'; + $type = $config['type'] ?? 'ReadOnlyStream'; if ($type[0] !== '\\') { $type = '\\RocketTheme\\Toolbox\\StreamWrapper\\' . $type; } @@ -251,8 +251,8 @@ class Setup extends Data */ protected function check(UniformResourceLocator $locator) { - $streams = isset($this->items['streams']['schemes']) ? $this->items['streams']['schemes'] : null; - if (!is_array($streams)) { + $streams = $this->items['streams']['schemes'] ?? null; + if (!\is_array($streams)) { throw new \InvalidArgumentException('Configuration is missing streams.schemes!'); } $diff = array_keys(array_diff_key($this->streams, $streams));