From 61a0e6c08fc6f49afb92ee79f3e3d9c01d775a27 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 16 Jul 2019 16:47:16 +0200 Subject: [PATCH 1/4] opened 3.0-dev --- composer.json | 2 +- src/Latte/Engine.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7d8ae3bdf..a2597375a 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "3.0-dev" } } } diff --git a/src/Latte/Engine.php b/src/Latte/Engine.php index eaef49454..37e652ae3 100644 --- a/src/Latte/Engine.php +++ b/src/Latte/Engine.php @@ -17,7 +17,7 @@ class Engine { use Strict; - public const VERSION = '2.5.2'; + public const VERSION = '3.0-dev'; /** Content types */ public const From aced71d87ec2c7f99de17f26978adaf551a98a8e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 20 Feb 2019 11:12:13 +0100 Subject: [PATCH 2/4] ISnippetBridge: added typehints --- composer.json | 2 +- src/Latte/Runtime/ISnippetBridge.php | 14 +++++++------- tests/Latte/mocks/SnippetBridge.php | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index a2597375a..d9e1125ed 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "nette/utils": "to use filter |webalize" }, "conflict": { - "nette/application": "<2.4.1" + "nette/application": "<3.0" }, "autoload": { "classmap": ["src/"] diff --git a/src/Latte/Runtime/ISnippetBridge.php b/src/Latte/Runtime/ISnippetBridge.php index 5829e758f..9c9f3358b 100644 --- a/src/Latte/Runtime/ISnippetBridge.php +++ b/src/Latte/Runtime/ISnippetBridge.php @@ -16,17 +16,17 @@ */ interface ISnippetBridge { - function isSnippetMode(); + function isSnippetMode(): bool; - function setSnippetMode($snippetMode); + function setSnippetMode(bool $snippetMode); - function needsRedraw($name); + function needsRedraw(string $name): bool; - function markRedrawn($name); + function markRedrawn(string $name): void; - function getHtmlId($name); + function getHtmlId(string $name): string; - function addSnippet($name, $content); + function addSnippet(string $name, string $content): void; - function renderChildren(); + function renderChildren(): void; } diff --git a/tests/Latte/mocks/SnippetBridge.php b/tests/Latte/mocks/SnippetBridge.php index 1fced3731..7bf3fcb63 100644 --- a/tests/Latte/mocks/SnippetBridge.php +++ b/tests/Latte/mocks/SnippetBridge.php @@ -18,19 +18,19 @@ public function isSnippetMode(): bool } - public function setSnippetMode($snippetMode) + public function setSnippetMode(bool $snippetMode) { $this->snippetMode = $snippetMode; } - public function needsRedraw($name): bool + public function needsRedraw(string $name): bool { return $this->invalid === true || isset($this->invalid[$name]); } - public function markRedrawn($name): void + public function markRedrawn(string $name): void { if ($this->invalid !== true) { unset($this->invalid[$name]); @@ -38,13 +38,13 @@ public function markRedrawn($name): void } - public function getHtmlId($name): string + public function getHtmlId(string $name): string { return $name; } - public function addSnippet($name, $content): void + public function addSnippet(string $name, string $content): void { $this->payload[$name] = $content; } From bca314ef23e524c9b06e9ba73c52258596c927bc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 5 Aug 2019 16:37:28 +0200 Subject: [PATCH 3/4] BlockMacros: block name must not start with underscore [Closes #193] --- src/Latte/Macros/BlockMacros.php | 3 +++ tests/Latte/BlockMacros.block5.phpt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index 25e9d12db..e7c30641f 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -268,6 +268,9 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) return "\$this->checkBlockContentType($blockType, $fname);" . "\$this->blockQueue[$fname][] = [\$this, '{$node->data->func}'];"; } + + } elseif ($name[0] === '_') { + throw new CompileException("Block name '$name' must not start with an underscore."); } // static snippet/snippetArea diff --git a/tests/Latte/BlockMacros.block5.phpt b/tests/Latte/BlockMacros.block5.phpt index 9c7311199..9bbc185d6 100644 --- a/tests/Latte/BlockMacros.block5.phpt +++ b/tests/Latte/BlockMacros.block5.phpt @@ -26,3 +26,7 @@ Assert::match( '
', $latte->renderToString('{block test}
{/block}', ['var' => 123]) ); + +Assert::exception(function () use ($latte) { + $latte->renderToString('{define _foobar}Hello{/define}'); +}, Latte\CompileException::class, "Block name '_foobar' must not start with an underscore."); From 088ba2e9922bdac6f88b729a8a52f000847096c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 31 Aug 2019 17:52:37 +0200 Subject: [PATCH 4/4] Filters::spacelessHtml() Support for script link. --- src/Latte/Runtime/Filters.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index cdf184ef3..81e06afe1 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -316,7 +316,7 @@ public static function strip(FilterInfo $info, string $s): string * @param bool $strip stripping mode * @return string HTML */ - public static function spacelessHtml(string $s, int $phase = null, bool &$strip = true): string + public static function spacelessHtml(string $s, ?int $phase = null, bool &$strip = true): string { if ($phase & PHP_OUTPUT_HANDLER_START) { $s = ltrim($s); @@ -324,18 +324,25 @@ public static function spacelessHtml(string $s, int $phase = null, bool &$strip if ($phase & PHP_OUTPUT_HANDLER_FINAL) { $s = rtrim($s); } - return preg_replace_callback( + $return = (string) preg_replace_callback( // Other cases '#[ \t\r\n]+|<(/)?(textarea|pre|script)(?=\W)#si', - function ($m) use (&$strip) { + static function (array $m) use (&$strip): string { if (empty($m[2])) { - return $strip ? ' ' : $m[0]; - } else { - $strip = !empty($m[1]); - return $m[0]; + return (string) $strip ? ' ' : $m[0]; } + $strip = !empty($m[1]); + return (string) $m[0]; }, $s ); + $return = (string) preg_replace_callback( // ' : (string) $m[0]; + }, + $return + ); + return $return; }