-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate variable types to generated code to allow statical analysis
- Loading branch information
1 parent
2c7ddd9
commit 9fe662e
Showing
13 changed files
with
264 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* Test: {templateType} | ||
* @phpVersion 8 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
|
||
class ExampleTemplateType { | ||
public $a; | ||
public int $b; | ||
public ExampleTemplateType|int|null $c; | ||
private $private; | ||
} | ||
|
||
Assert::matchFile( | ||
__DIR__ . '/expected/CoreMacros.templateType.80.phtml', | ||
$latte->compile('{templateType ExampleTemplateType}{define test}{$a}{/define}') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
default values | ||
|
||
|
||
a) Variables 1, 123, 10 | ||
|
||
|
||
b) Variables 1, 123, 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
%A% | ||
final class Template%a% extends Latte\Runtime\Template | ||
{ | ||
protected const BLOCKS = [ | ||
['test' => 'blockTest'], | ||
]; | ||
|
||
|
||
public function main(): array | ||
{ | ||
extract($this->params); | ||
echo 'default values | ||
'; | ||
if ($this->getParentName()) { | ||
return get_defined_vars(); | ||
} | ||
echo ' | ||
a) '; | ||
$this->renderBlock('test', [1] + [], 'html') /* line %d% */; | ||
echo ' | ||
b) '; | ||
$this->renderBlock('test', ['var1' => 1] + [], 'html') /* line %d% */; | ||
return get_defined_vars(); | ||
} | ||
|
||
|
||
/** {define test $var1 = 0, array $var2 = [1, 2, 3], int $var3 = 10} on line %d% */ | ||
public function blockTest(array $ʟ_args): void | ||
{ | ||
extract($this->params); | ||
$var1 = $ʟ_args[0] ?? $ʟ_args['var1'] ?? 0; | ||
/** @var array $var2 */ | ||
$var2 = $ʟ_args[1] ?? $ʟ_args['var2'] ?? [1, 2, 3]; | ||
/** @var int $var3 */ | ||
$var3 = $ʟ_args[2] ?? $ʟ_args['var3'] ?? 10; | ||
unset($ʟ_args); | ||
echo ' Variables '; | ||
echo LR\Filters::escapeHtmlText($var1) /* line %d% */; | ||
echo ', '; | ||
echo LR\Filters::escapeHtmlText(($this->filters->implode)($var2)) /* line %d% */; | ||
echo ', '; | ||
echo LR\Filters::escapeHtmlText($var3) /* line %d% */; | ||
echo "\n"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
%A% | ||
public function main(): array | ||
{ | ||
extract($this->params); | ||
/** @var mixed $a (ExampleTemplateType) */ | ||
/** @var int $b (ExampleTemplateType) */ | ||
/** @var ExampleTemplateType|int|null $c (ExampleTemplateType) */ | ||
%A% | ||
public function blockTest(array $ʟ_args): void | ||
{ | ||
extract($this->params); | ||
/** @var mixed $a (ExampleTemplateType) */ | ||
/** @var int $b (ExampleTemplateType) */ | ||
/** @var ExampleTemplateType|int|null $c (ExampleTemplateType) */ | ||
%A% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
%A% | ||
public function main(): array | ||
{ | ||
extract($this->params); | ||
/** @var mixed $a (ExampleTemplateType) */ | ||
/** @var int $b (ExampleTemplateType) */ | ||
/** @var ?ExampleTemplateType $c (ExampleTemplateType) */ | ||
%A% | ||
public function blockTest(array $ʟ_args): void | ||
{ | ||
extract($this->params); | ||
/** @var mixed $a (ExampleTemplateType) */ | ||
/** @var int $b (ExampleTemplateType) */ | ||
/** @var ?ExampleTemplateType $c (ExampleTemplateType) */ | ||
%A% |
Oops, something went wrong.