Skip to content

Commit

Permalink
Added Deprecated tab to DebugBar to catch future incompatibilities …
Browse files Browse the repository at this point in the history
…with later Grav versions
  • Loading branch information
mahagr committed Aug 24, 2018
1 parent 89f64e4 commit 756ddaa
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Grav.Core
*
Expand All @@ -7,6 +8,7 @@
*/

namespace Grav;

define('GRAV_PHP_MIN', '5.6.4');

// Ensure vendor libraries exist
Expand All @@ -29,7 +31,7 @@
}

// Register the auto-loader.
$loader = require_once $autoload;
$loader = require $autoload;

// Set timezone to default, falls back to system if php.ini not set
date_default_timezone_set(@date_default_timezone_get());
Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Common/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function init()
*/
public function getLanguages()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use Grav::instance()[\'languages\'] instead', E_USER_DEPRECATED);

return Grav::instance()['languages'];
}
}
64 changes: 64 additions & 0 deletions system/src/Grav/Common/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Grav\Common;

use DebugBar\DataCollector\ConfigCollector;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\JavascriptRenderer;
use DebugBar\StandardDebugBar;
use Grav\Common\Config\Config;
Expand All @@ -31,6 +32,11 @@ class Debugger

protected $timers = [];

/** @var string[] $deprecations */
protected $deprecations = [];

protected $errorHandler;

/**
* Debugger constructor.
*/
Expand All @@ -41,6 +47,9 @@ public function __construct()

$this->debugbar = new StandardDebugBar();
$this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true));

// Set deprecation collector.
$this->setErrorHandler();
}

/**
Expand Down Expand Up @@ -177,6 +186,8 @@ public function render()
return $this;
}

$this->addDeprecations();

echo $this->renderer->render();
}

Expand All @@ -191,6 +202,7 @@ public function render()
public function sendDataInHeaders()
{
if ($this->enabled()) {
$this->addDeprecations();
$this->debugbar->sendDataInHeaders();
}

Expand All @@ -208,6 +220,7 @@ public function getData()
return null;
}

$this->addDeprecations();
$this->timers = [];

return $this->debugbar->getData();
Expand Down Expand Up @@ -279,4 +292,55 @@ public function addException(\Exception $e)

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);
}
}
}
3 changes: 3 additions & 0 deletions system/src/Grav/Common/Errors/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ public function resetHandlers()
}

$whoops->register();

// Re-register deprecation handler.
$grav['debugger']->setErrorHandler();
}
}
5 changes: 2 additions & 3 deletions system/src/Grav/Common/GravTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Grav\Common;

/**
* @deprecated 2.0
* @deprecated 1.4 Use Grav::instance() instead
*/
trait GravTrait
{
Expand All @@ -24,8 +24,7 @@ public static function getGrav()
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;
}
Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ protected function processMarkdown()

// 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');
}

Expand Down
12 changes: 9 additions & 3 deletions system/src/Grav/Common/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -51,21 +53,25 @@ public function setAutoStart($auto)
* 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();
}

/**
* 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();
}

Expand Down
10 changes: 9 additions & 1 deletion system/src/Grav/Common/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public function init()
$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')) {
Expand Down Expand Up @@ -411,8 +415,12 @@ public function template($template)
* 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;
}
}
2 changes: 2 additions & 0 deletions system/src/Grav/Common/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ public function authorize($action)
*/
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);
}

Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ public static function date2timestamp($date, $format = null)
*/
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);
}

Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Framework/File/Formatter/IniFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function __construct(array $config = [])
*/
public function getFileExtension()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED);

return $this->getDefaultFileExtension();
}

Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Framework/File/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(array $config = [])
*/
public function getFileExtension()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED);

return $this->getDefaultFileExtension();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function __construct(array $config = [], FormatterInterface $headerFormat
*/
public function getFileExtension()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED);

return $this->getDefaultFileExtension();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function __construct(array $config = [])
*/
public function getFileExtension()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED);

return $this->getDefaultFileExtension();
}

Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Framework/File/Formatter/YamlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function __construct(array $config = [])
*/
public function getFileExtension()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getDefaultFileExtension() method instead', E_USER_DEPRECATED);

return $this->getDefaultFileExtension();
}

Expand Down

0 comments on commit 756ddaa

Please sign in to comment.