From 756ddaa97db9daaa0c9bb697c2268cede6c3cc0d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 24 Aug 2018 11:31:51 +0300 Subject: [PATCH] Added `Deprecated` tab to DebugBar to catch future incompatibilities with later Grav versions --- CHANGELOG.md | 7 ++ index.php | 4 +- system/src/Grav/Common/Config/Config.php | 2 + system/src/Grav/Common/Debugger.php | 64 +++++++++++++++++++ system/src/Grav/Common/Errors/Errors.php | 3 + system/src/Grav/Common/GravTrait.php | 5 +- system/src/Grav/Common/Page/Page.php | 2 + system/src/Grav/Common/Session.php | 12 +++- system/src/Grav/Common/Twig/Twig.php | 10 ++- system/src/Grav/Common/User/User.php | 2 + system/src/Grav/Common/Utils.php | 2 + .../Framework/File/Formatter/IniFormatter.php | 2 + .../File/Formatter/JsonFormatter.php | 2 + .../File/Formatter/MarkdownFormatter.php | 2 + .../File/Formatter/SerializeFormatter.php | 2 + .../File/Formatter/YamlFormatter.php | 2 + 16 files changed, 115 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ea6acb0..bae9d6915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.5.2 +## mm/dd/2018 + +1. [](#new) + * Added `Deprecated` tab to DebugBar to catch future incompatibilities with later Grav versions + * Added deprecation notices for features which will be removed in Grav 2.0 + # v1.5.1 ## 08/23/2018 diff --git a/index.php b/index.php index db077f5eb..75d0cfe0f 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ debugbar = new StandardDebugBar(); $this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true)); + + // Set deprecation collector. + $this->setErrorHandler(); } /** @@ -177,6 +186,8 @@ class Debugger return $this; } + $this->addDeprecations(); + echo $this->renderer->render(); } @@ -191,6 +202,7 @@ class Debugger public function sendDataInHeaders() { if ($this->enabled()) { + $this->addDeprecations(); $this->debugbar->sendDataInHeaders(); } @@ -208,6 +220,7 @@ class Debugger return null; } + $this->addDeprecations(); $this->timers = []; return $this->debugbar->getData(); @@ -279,4 +292,55 @@ class Debugger return $this; } + + public function setErrorHandler() + { + $this->errorHandler = set_error_handler( + [$this, 'deprecatedErrorHandler'], + E_USER_DEPRECATED + ); + } + + /** + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @return bool + */ + public function deprecatedErrorHandler($errno, $errstr, $errfile, $errline) + { + $this->deprecations[] = [ + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline + ]; + + return true; + } + + protected function addDeprecations() + { + if (!$this->deprecations) { + return; + } + + $collector = new MessagesCollector('deprecated'); + $this->addCollector($collector); + $collector->addMessage('Your site is using following deprecated features:'); + + /** @var array $deprecated */ + foreach ($this->deprecations as $deprecated) { + if (strpos($deprecated['message'], 'Grav') !== false) { + $scope = 'grav'; + } elseif (strpos($deprecated['file'], 'Twig') !== false) { + $scope = 'twig'; + } elseif (strpos($deprecated['file'], 'yaml') !== false) { + $scope = 'yaml'; + } else { + $scope = 'unknown'; + } + $collector->addMessage($deprecated, $scope); + } + } } diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php index c342837d4..9e8535cc0 100644 --- a/system/src/Grav/Common/Errors/Errors.php +++ b/system/src/Grav/Common/Errors/Errors.php @@ -74,5 +74,8 @@ class Errors } $whoops->register(); + + // Re-register deprecation handler. + $grav['debugger']->setErrorHandler(); } } diff --git a/system/src/Grav/Common/GravTrait.php b/system/src/Grav/Common/GravTrait.php index 7ff04e65e..a17a170e5 100644 --- a/system/src/Grav/Common/GravTrait.php +++ b/system/src/Grav/Common/GravTrait.php @@ -9,7 +9,7 @@ namespace Grav\Common; /** - * @deprecated 2.0 + * @deprecated 1.4 Use Grav::instance() instead */ trait GravTrait { @@ -24,8 +24,7 @@ trait GravTrait self::$grav = Grav::instance(); } - $caller = self::$grav['debugger']->getCaller(); - self::$grav['debugger']->addMessage("Deprecated GravTrait used in {$caller['file']}", 'deprecated'); + user_error(__TRAIT__ . ' is deprecated since Grav 1.4, use Grav::instance() instead', E_USER_DEPRECATED); return self::$grav; } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index d79dc8746..5a7b6c411 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -764,6 +764,8 @@ class Page implements PageInterface // pages.markdown_extra is deprecated, but still check it... if (!isset($defaults['extra']) && (isset($this->markdown_extra) || $config->get('system.pages.markdown_extra') !== null)) { + user_error('Configuration option \'system.pages.markdown_extra\' is deprecated since Grav 1.5, use \'system.pages.markdown.extra\' instead', E_USER_DEPRECATED); + $defaults['extra'] = $this->markdown_extra ?: $config->get('system.pages.markdown_extra'); } diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index f7221194f..d617f4684 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -15,10 +15,12 @@ class Session extends \Grav\Framework\Session\Session /** * @return \Grav\Framework\Session\Session - * @deprecated 1.5 + * @deprecated 1.5 Use getInstance() method instead */ public static function instance() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getInstance() method instead', E_USER_DEPRECATED); + return static::getInstance(); } @@ -51,10 +53,12 @@ class Session extends \Grav\Framework\Session\Session * Returns attributes. * * @return array Attributes - * @deprecated 1.5 + * @deprecated 1.5 Use getAll() method instead */ public function all() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getAll() method instead', E_USER_DEPRECATED); + return $this->getAll(); } @@ -62,10 +66,12 @@ class Session extends \Grav\Framework\Session\Session * Checks if the session was started. * * @return Boolean - * @deprecated 1.5 + * @deprecated 1.5 Use isStarted() method instead */ public function started() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use isStarted() method instead', E_USER_DEPRECATED); + return $this->isStarted(); } diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php index c276aafcf..671dd16fd 100644 --- a/system/src/Grav/Common/Twig/Twig.php +++ b/system/src/Grav/Common/Twig/Twig.php @@ -120,6 +120,10 @@ class Twig $params['autoescape'] = $this->autoescape; } + if (empty($params['autoescape'])) { + user_error('Having Twig auto-escaping turned off is deprecated since Grav 1.5, please disable \'system.strict_mode.twig_compat\' setting in your configuration', E_USER_DEPRECATED); + } + $this->twig = new TwigEnvironment($loader_chain, $params); if ($config->get('system.twig.undefined_functions')) { @@ -411,8 +415,12 @@ class Twig * Overrides the autoescape setting * * @param boolean $state + * @deprecated 1.5 */ - public function setAutoescape($state) { + public function setAutoescape($state) + { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5', E_USER_DEPRECATED); + $this->autoescape = (bool) $state; } } diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 512b29203..438ca97a7 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -266,6 +266,8 @@ class User extends Data */ public function authorise($action) { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use authorize() method instead', E_USER_DEPRECATED); + return $this->authorize($action); } diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 0f27277b3..5de4fe7b1 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -696,6 +696,8 @@ abstract class Utils */ public static function resolve(array $array, $path, $default = null) { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDotNotation() method instead', E_USER_DEPRECATED); + return static::getDotNotation($array, $path, $default); } diff --git a/system/src/Grav/Framework/File/Formatter/IniFormatter.php b/system/src/Grav/Framework/File/Formatter/IniFormatter.php index f79e007c2..45be61012 100644 --- a/system/src/Grav/Framework/File/Formatter/IniFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/IniFormatter.php @@ -29,6 +29,8 @@ class IniFormatter implements FormatterInterface */ public function getFileExtension() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED); + return $this->getDefaultFileExtension(); } diff --git a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php index f5705e381..4a2d2fac4 100644 --- a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php @@ -27,6 +27,8 @@ class JsonFormatter implements FormatterInterface */ public function getFileExtension() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED); + return $this->getDefaultFileExtension(); } diff --git a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php index 9cccba990..415f7ceb0 100644 --- a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php @@ -33,6 +33,8 @@ class MarkdownFormatter implements FormatterInterface */ public function getFileExtension() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED); + return $this->getDefaultFileExtension(); } diff --git a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php index 5fd20eb89..88302180b 100644 --- a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php @@ -29,6 +29,8 @@ class SerializeFormatter implements FormatterInterface */ public function getFileExtension() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED); + return $this->getDefaultFileExtension(); } diff --git a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php index 21454ae49..d59f9e7d4 100644 --- a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php @@ -34,6 +34,8 @@ class YamlFormatter implements FormatterInterface */ public function getFileExtension() { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED); + return $this->getDefaultFileExtension(); }