From 337c67ca4fccda215f3d927cec05b0cb58e83492 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 19 Jan 2017 14:16:51 +0100 Subject: [PATCH] TemplateFactory: filters |normalize, |toAscii, |reverse, |url, |null and |modifyDate are deprecated --- .../ApplicationLatte/TemplateFactory.php | 18 ++++++++++++++---- .../Bridges.Latte/TemplateFactory.filters.phpt | 18 +++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 8aa6d944c..10c7a7367 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -81,12 +81,22 @@ public function createTemplate(UI\Control $control = NULL) } }); - $latte->addFilter('url', 'rawurlencode'); // back compatiblity - foreach (['normalize', 'toAscii', 'webalize', 'reverse'] as $name) { - $latte->addFilter($name, 'Nette\Utils\Strings::' . $name); + $latte->addFilter('webalize', 'Nette\Utils\Strings::webalize'); + $latte->addFilter('url', function ($s) { + trigger_error('Filter |url is deprecated, use |escapeUrl.', E_USER_DEPRECATED); + return rawurlencode($s); + }); + foreach (['normalize', 'toAscii', 'reverse'] as $name) { + $latte->addFilter($name, function ($s) use ($name) { + trigger_error("Filter |$name is deprecated.", E_USER_DEPRECATED); + return [Nette\Utils\Strings::class, $name]($s); + }); } - $latte->addFilter('null', function () {}); + $latte->addFilter('null', function () { + trigger_error('Filter |null is deprecated.', E_USER_DEPRECATED); + }); $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) { + trigger_error('Filter |modifyDate is deprecated.', E_USER_DEPRECATED); return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit); // intentionally == }); diff --git a/tests/Bridges.Latte/TemplateFactory.filters.phpt b/tests/Bridges.Latte/TemplateFactory.filters.phpt index 0f8d40090..be6208367 100644 --- a/tests/Bridges.Latte/TemplateFactory.filters.phpt +++ b/tests/Bridges.Latte/TemplateFactory.filters.phpt @@ -35,15 +35,15 @@ $latte = $factory->createTemplate()->getLatte(); setlocale(LC_TIME, 'C'); date_default_timezone_set('Europe/Prague'); -Assert::null($latte->invokeFilter('modifyDate', [NULL, NULL])); -Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, '+1 day'])); -Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); -Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); -Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, -1, 'day'])); +Assert::null(@$latte->invokeFilter('modifyDate', [NULL, NULL])); // @ is deprecated +Assert::same('1978-01-24 11:40:00', (string) @$latte->invokeFilter('modifyDate', [254400000, '+1 day'])); +Assert::same('1978-05-06 00:00:00', (string) @$latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); +Assert::same('1978-05-06 00:00:00', (string) @$latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); +Assert::same('1978-01-22 11:40:00', (string) @$latte->invokeFilter('modifyDate', [254400000, -1, 'day'])); -Assert::same('%25', $latte->invokeFilter('url', ['%'])); -Assert::null($latte->invokeFilter('null', ['x'])); -Assert::same('', $latte->invokeFilter('normalize', [' '])); +Assert::same('%25', @$latte->invokeFilter('url', ['%'])); // @ is deprecated +Assert::null(@$latte->invokeFilter('null', ['x'])); // @ is deprecated +Assert::same('', @$latte->invokeFilter('normalize', [' '])); // @ is deprecated Assert::same('a-b', $latte->invokeFilter('webalize', ['a b'])); -Assert::same('cba', $latte->invokeFilter('reverse', ['abc'])); +Assert::same('cba', @$latte->invokeFilter('reverse', ['abc'])); // @ is deprecated