@vituum/vite-plugin-latte 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/index.js +2 -2
  2. package/latte/PlaceholderFunction.php +2 -2
  3. package/package.json +10 -11
  4. package/vendor/autoload.php +18 -0
  5. package/vendor/bin/latte-lint +16 -4
  6. package/vendor/composer/ClassLoader.php +72 -65
  7. package/vendor/composer/InstalledVersions.php +21 -12
  8. package/vendor/composer/autoload_classmap.php +14 -8
  9. package/vendor/composer/autoload_namespaces.php +1 -1
  10. package/vendor/composer/autoload_psr4.php +1 -1
  11. package/vendor/composer/autoload_real.php +3 -22
  12. package/vendor/composer/autoload_static.php +13 -7
  13. package/vendor/composer/installed.json +8 -8
  14. package/vendor/composer/installed.php +10 -10
  15. package/vendor/latte/latte/bin/latte-lint +8 -2
  16. package/vendor/latte/latte/composer.json +1 -1
  17. package/vendor/latte/latte/readme.md +6 -6
  18. package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +1 -0
  19. package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +3 -2
  20. package/vendor/latte/latte/src/Latte/Compiler/Block.php +0 -3
  21. package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +113 -89
  22. package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +2 -1
  23. package/vendor/latte/latte/src/Latte/Compiler/Node.php +0 -4
  24. package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +0 -4
  25. package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +0 -4
  26. package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +11 -3
  27. package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +10 -0
  28. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +22 -4
  29. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +35 -12
  30. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +6 -0
  31. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php +12 -0
  32. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +4 -31
  33. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +15 -1
  34. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +11 -0
  35. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AuxiliaryNode.php +42 -0
  36. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +2 -2
  37. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +1 -1
  38. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +8 -0
  39. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +15 -1
  40. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +11 -0
  41. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +11 -0
  42. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/{StaticCallNode.php → StaticMethodCallNode.php} +11 -1
  43. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/{StaticCallableNode.php → StaticMethodCallableNode.php} +11 -1
  44. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TemporaryNode.php +38 -0
  45. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +24 -0
  46. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +1 -1
  47. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListItemNode.php +48 -0
  48. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ListNode.php +56 -0
  49. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +5 -5
  50. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +11 -21
  51. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/InterpolatedStringNode.php +1 -8
  52. package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +30 -0
  53. package/vendor/latte/latte/src/Latte/Compiler/Position.php +4 -8
  54. package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +15 -8
  55. package/vendor/latte/latte/src/Latte/Compiler/Tag.php +13 -14
  56. package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +5 -9
  57. package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +52 -3
  58. package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +353 -326
  59. package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +6 -5
  60. package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +105 -178
  61. package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +40 -33
  62. package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +186 -126
  63. package/vendor/latte/latte/src/Latte/Compiler/Token.php +5 -9
  64. package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +6 -22
  65. package/vendor/latte/latte/src/Latte/Engine.php +136 -95
  66. package/vendor/latte/latte/src/Latte/Essential/AuxiliaryIterator.php +46 -0
  67. package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +42 -27
  68. package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +0 -4
  69. package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +81 -66
  70. package/vendor/latte/latte/src/Latte/Essential/Filters.php +103 -43
  71. package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +1 -2
  72. package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +2 -13
  73. package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +8 -1
  74. package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +1 -2
  75. package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +1 -1
  76. package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +0 -3
  77. package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +1 -1
  78. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +1 -1
  79. package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +40 -13
  80. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +1 -1
  81. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +4 -1
  82. package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +5 -3
  83. package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +5 -2
  84. package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +6 -4
  85. package/vendor/latte/latte/src/Latte/Essential/Nodes/JumpNode.php +26 -23
  86. package/vendor/latte/latte/src/Latte/Essential/Nodes/NElseNode.php +88 -0
  87. package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +20 -28
  88. package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +7 -12
  89. package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +1 -1
  90. package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +1 -1
  91. package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +1 -1
  92. package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +25 -3
  93. package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +1 -1
  94. package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +3 -4
  95. package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +9 -2
  96. package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +1 -1
  97. package/vendor/latte/latte/src/Latte/Essential/Passes.php +16 -58
  98. package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +0 -2
  99. package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +6 -1
  100. package/vendor/latte/latte/src/Latte/Helpers.php +3 -1
  101. package/vendor/latte/latte/src/Latte/Loader.php +1 -0
  102. package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +1 -4
  103. package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +0 -2
  104. package/vendor/latte/latte/src/Latte/PositionAwareException.php +1 -1
  105. package/vendor/latte/latte/src/Latte/Runtime/Block.php +0 -4
  106. package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +43 -51
  107. package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +0 -2
  108. package/vendor/latte/latte/src/Latte/Runtime/Filters.php +64 -33
  109. package/vendor/latte/latte/src/Latte/Runtime/FunctionExecutor.php +68 -0
  110. package/vendor/latte/latte/src/Latte/Runtime/Html.php +0 -4
  111. package/vendor/latte/latte/src/Latte/Runtime/Template.php +3 -5
  112. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +2 -1
  113. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +1 -1
  114. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +3 -3
  115. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/{StaticCallNode.php → StaticMethodCallNode.php} +3 -3
  116. package/vendor/latte/latte/src/Latte/Sandbox/Nodes/{StaticCallableNode.php → StaticMethodCallableNode.php} +2 -2
  117. package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +0 -2
  118. package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +11 -9
  119. package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +0 -2
  120. package/vendor/latte/latte/src/Latte/exceptions.php +2 -11
  121. package/vendor/latte/latte/src/Tools/Linter.php +13 -37
  122. package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +0 -53
  123. package/vendor/latte/latte/src/Latte/Strict.php +0 -101
@@ -44,15 +44,15 @@ class SandboxNode extends StatementNode
44
44
  ob_start(fn() => '');
45
45
  try {
46
46
  $this->createTemplate(%node, %node, 'sandbox')->renderToContentType(%dump) %line;
47
- echo ob_get_clean();
48
47
  } catch (\Throwable $ʟ_e) {
49
48
  if (isset($this->global->coreExceptionHandler)) {
50
- ob_end_clean();
49
+ ob_clean();
51
50
  ($this->global->coreExceptionHandler)($ʟ_e, $this);
52
51
  } else {
53
- echo ob_get_clean();
54
52
  throw $ʟ_e;
55
53
  }
54
+ } finally {
55
+ echo ob_get_clean();
56
56
  }
57
57
 
58
58
 
@@ -13,9 +13,9 @@ use Latte\Compiler\Nodes\Php\Expression;
13
13
  use Latte\Compiler\PrintContext;
14
14
 
15
15
 
16
- class StaticCallNode extends Expression\StaticCallNode
16
+ class StaticMethodCallNode extends Expression\StaticMethodCallNode
17
17
  {
18
- public function __construct(Expression\StaticCallNode $from)
18
+ public function __construct(Expression\StaticMethodCallNode $from)
19
19
  {
20
20
  parent::__construct($from->class, $from->name, $from->args, $from->position);
21
21
  }
@@ -26,6 +26,6 @@ class StaticCallNode extends Expression\StaticCallNode
26
26
  return '$this->global->sandbox->call(['
27
27
  . $context->memberAsString($this->class) . ', '
28
28
  . $context->memberAsString($this->name) . '], '
29
- . Expression\ArrayNode::fromArguments($this->args)->print($context) . ')';
29
+ . $context->argumentsAsArray($this->args) . ')';
30
30
  }
31
31
  }
@@ -13,9 +13,9 @@ use Latte\Compiler\Nodes\Php\Expression;
13
13
  use Latte\Compiler\PrintContext;
14
14
 
15
15
 
16
- class StaticCallableNode extends Expression\StaticCallableNode
16
+ class StaticMethodCallableNode extends Expression\StaticMethodCallableNode
17
17
  {
18
- public function __construct(Expression\StaticCallableNode $from)
18
+ public function __construct(Expression\StaticMethodCallableNode $from)
19
19
  {
20
20
  parent::__construct($from->class, $from->name, $from->position);
21
21
  }
@@ -15,8 +15,6 @@ use Latte;
15
15
  /** @internal */
16
16
  final class RuntimeChecker
17
17
  {
18
- use Latte\Strict;
19
-
20
18
  public function __construct(
21
19
  public Latte\Policy $policy,
22
20
  ) {
@@ -10,12 +10,12 @@ declare(strict_types=1);
10
10
  namespace Latte\Sandbox;
11
11
 
12
12
  use Latte;
13
- use Latte\Compiler\ExpressionBuilder;
14
13
  use Latte\Compiler\Node;
15
14
  use Latte\Compiler\Nodes\Php;
16
15
  use Latte\Compiler\Nodes\Php\Expression;
17
16
  use Latte\Compiler\Nodes\TemplateNode;
18
17
  use Latte\Compiler\NodeTraverser;
18
+ use Latte\Compiler\PrintContext;
19
19
  use Latte\Engine;
20
20
  use Latte\Runtime\Template;
21
21
  use Latte\SecurityViolationException;
@@ -26,8 +26,6 @@ use Latte\SecurityViolationException;
26
26
  */
27
27
  final class SandboxExtension extends Latte\Extension
28
28
  {
29
- use Latte\Strict;
30
-
31
29
  private ?Latte\Policy $policy;
32
30
 
33
31
 
@@ -95,8 +93,10 @@ final class SandboxExtension extends Latte\Extension
95
93
  throw new SecurityViolationException("Function $node->name() is not allowed.", $node->position);
96
94
 
97
95
  } elseif ($node->args) {
98
- $arg = ExpressionBuilder::variable('$this')->property('global')->property('sandbox')->method('args', $node->args)
99
- ->build();
96
+ $arg = new Expression\AuxiliaryNode(
97
+ fn(PrintContext $context, ...$args) => '$this->global->sandbox->args(' . $context->implode($args) . ')',
98
+ $node->args,
99
+ );
100
100
  $node->args = [new Php\ArgumentNode($arg, unpack: true)];
101
101
  }
102
102
 
@@ -108,8 +108,10 @@ final class SandboxExtension extends Latte\Extension
108
108
  throw new SecurityViolationException("Filter |$name is not allowed.", $node->position);
109
109
 
110
110
  } elseif ($node->args) {
111
- $arg = ExpressionBuilder::variable('$this')->property('global')->property('sandbox')->method('args', $node->args)
112
- ->build();
111
+ $arg = new Expression\AuxiliaryNode(
112
+ fn(PrintContext $context, ...$args) => '$this->global->sandbox->args(' . $context->implode($args) . ')',
113
+ $node->args,
114
+ );
113
115
  $node->args = [new Php\ArgumentNode($arg, unpack: true)];
114
116
  }
115
117
 
@@ -121,8 +123,8 @@ final class SandboxExtension extends Latte\Extension
121
123
  || $node instanceof Expression\FunctionCallableNode
122
124
  || $node instanceof Expression\MethodCallNode
123
125
  || $node instanceof Expression\MethodCallableNode
124
- || $node instanceof Expression\StaticCallNode
125
- || $node instanceof Expression\StaticCallableNode
126
+ || $node instanceof Expression\StaticMethodCallNode
127
+ || $node instanceof Expression\StaticMethodCallableNode
126
128
  ) {
127
129
  $class = namespace\Nodes::class . strrchr($node::class, '\\');
128
130
  return new $class($node);
@@ -17,8 +17,6 @@ use Latte;
17
17
  */
18
18
  class SecurityPolicy implements Latte\Policy
19
19
  {
20
- use Latte\Strict;
21
-
22
20
  public const All = ['*'];
23
21
  public const ALL = self::All;
24
22
 
@@ -37,14 +37,10 @@ class CompileException extends \Exception implements Exception
37
37
 
38
38
 
39
39
  /**
40
- * The exception that indicates error of the last Regexp execution.
40
+ * The exception occurred during template rendering.
41
41
  */
42
- class RegexpException extends \Exception implements Exception
42
+ class RuntimeException extends \RuntimeException implements Exception
43
43
  {
44
- public function __construct()
45
- {
46
- parent::__construct(preg_last_error_msg(), preg_last_error());
47
- }
48
44
  }
49
45
 
50
46
 
@@ -62,8 +58,3 @@ class SecurityViolationException extends \Exception implements Exception
62
58
  $this->generateMessage();
63
59
  }
64
60
  }
65
-
66
-
67
- class RuntimeException extends \RuntimeException implements Exception
68
- {
69
- }
@@ -15,11 +15,10 @@ use Nette;
15
15
 
16
16
  final class Linter
17
17
  {
18
- use Latte\Strict;
19
-
20
18
  public function __construct(
21
19
  private ?Latte\Engine $engine = null,
22
20
  private bool $debug = false,
21
+ private bool $strict = false,
23
22
  ) {
24
23
  }
25
24
 
@@ -31,10 +30,6 @@ final class Linter
31
30
  echo "Scanning $path\n";
32
31
 
33
32
  $files = $this->getFiles($path);
34
-
35
- $this->engine ??= $this->createEngine();
36
- $this->engine->setLoader(new Latte\Loaders\StringLoader);
37
-
38
33
  $counter = 0;
39
34
  $errors = 0;
40
35
  foreach ($files as $file) {
@@ -53,6 +48,8 @@ final class Linter
53
48
  private function createEngine(): Latte\Engine
54
49
  {
55
50
  $engine = new Latte\Engine;
51
+ $engine->enablePhpLinter(PHP_BINARY);
52
+ $engine->setStrictParsing($this->strict);
56
53
  $engine->addExtension(new Latte\Essential\TranslatorExtension(null));
57
54
 
58
55
  if (class_exists(Nette\Bridges\ApplicationLatte\UIExtension::class)) {
@@ -71,6 +68,13 @@ final class Linter
71
68
  }
72
69
 
73
70
 
71
+ public function getEngine(): Latte\Engine
72
+ {
73
+ $this->engine ??= $this->createEngine();
74
+ return $this->engine;
75
+ }
76
+
77
+
74
78
  public function lintLatte(string $file): bool
75
79
  {
76
80
  set_error_handler(function (int $severity, string $message) use ($file) {
@@ -91,7 +95,9 @@ final class Linter
91
95
  }
92
96
 
93
97
  try {
94
- $code = $this->engine->compile($s);
98
+ $this->getEngine()
99
+ ->setLoader(new Latte\Loaders\StringLoader)
100
+ ->compile($s);
95
101
 
96
102
  } catch (Latte\CompileException $e) {
97
103
  if ($this->debug) {
@@ -106,40 +112,10 @@ final class Linter
106
112
  restore_error_handler();
107
113
  }
108
114
 
109
- if ($error = $this->lintPHP($code)) {
110
- fwrite(STDERR, "[ERROR] $file $error\n");
111
- return false;
112
- }
113
-
114
115
  return true;
115
116
  }
116
117
 
117
118
 
118
- private function lintPHP(string $code): ?string
119
- {
120
- $php = defined('PHP_BINARY') ? PHP_BINARY : 'php';
121
- $stdin = tmpfile();
122
- fwrite($stdin, $code);
123
- fseek($stdin, 0);
124
- $process = proc_open(
125
- $php . ' -l -d display_errors=1',
126
- [$stdin, ['pipe', 'w'], ['pipe', 'w']],
127
- $pipes,
128
- null,
129
- null,
130
- ['bypass_shell' => true],
131
- );
132
- if (!is_resource($process)) {
133
- return 'Unable to lint PHP code';
134
- }
135
- $error = stream_get_contents($pipes[1]);
136
- if (proc_close($process)) {
137
- return strip_tags(explode("\n", $error)[1]);
138
- }
139
- return null;
140
- }
141
-
142
-
143
119
  private function initialize(): void
144
120
  {
145
121
  if (function_exists('pcntl_signal')) {
@@ -1,53 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * This file is part of the Latte (https://latte.nette.org)
5
- * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
- */
7
-
8
- declare(strict_types=1);
9
-
10
- namespace Latte\Compiler\Nodes\Html;
11
-
12
- use Latte\Compiler\Nodes\AreaNode;
13
- use Latte\Compiler\Nodes\FragmentNode;
14
- use Latte\Compiler\Position;
15
- use Latte\Compiler\PrintContext;
16
-
17
-
18
- class QuotedValue extends AreaNode
19
- {
20
- public function __construct(
21
- public AreaNode $value,
22
- public string $quote,
23
- public ?Position $position = null,
24
- ) {
25
- }
26
-
27
-
28
- public function print(PrintContext $context): string
29
- {
30
- $res = 'echo ' . var_export($this->quote, true) . ';';
31
- $escaper = $context->beginEscape();
32
- $escaper->enterHtmlAttributeQuote($this->quote);
33
-
34
- if ($this->value instanceof FragmentNode && $escaper->export() === 'html/attr/url') {
35
- foreach ($this->value->children as $child) {
36
- $res .= $child->print($context);
37
- $escaper->enterHtmlAttribute(null, $this->quote);
38
- }
39
- } else {
40
- $res .= $this->value->print($context);
41
- }
42
-
43
- $res .= 'echo ' . var_export($this->quote, true) . ';';
44
- $context->restoreEscape();
45
- return $res;
46
- }
47
-
48
-
49
- public function &getIterator(): \Generator
50
- {
51
- yield $this->value;
52
- }
53
- }
@@ -1,101 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * This file is part of the Latte (https://latte.nette.org)
5
- * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
- */
7
-
8
- declare(strict_types=1);
9
-
10
- namespace Latte;
11
-
12
- use LogicException;
13
-
14
-
15
- /**
16
- * Better OOP experience.
17
- */
18
- trait Strict
19
- {
20
- /**
21
- * Call to undefined method.
22
- * @param mixed[] $args
23
- * @throws LogicException
24
- */
25
- public function __call(string $name, array $args): mixed
26
- {
27
- $class = method_exists($this, $name) ? 'parent' : static::class;
28
- $items = (new \ReflectionClass($this))->getMethods(\ReflectionMethod::IS_PUBLIC);
29
- $items = array_map(fn($item) => $item->getName(), $items);
30
- $hint = ($t = Helpers::getSuggestion($items, $name))
31
- ? ", did you mean $t()?"
32
- : '.';
33
- throw new LogicException("Call to undefined method $class::$name()$hint");
34
- }
35
-
36
-
37
- /**
38
- * Call to undefined static method.
39
- * @param mixed[] $args
40
- * @throws LogicException
41
- */
42
- public static function __callStatic(string $name, array $args): mixed
43
- {
44
- $rc = new \ReflectionClass(static::class);
45
- $items = array_filter($rc->getMethods(\ReflectionMethod::IS_STATIC), fn($m) => $m->isPublic());
46
- $items = array_map(fn($item) => $item->getName(), $items);
47
- $hint = ($t = Helpers::getSuggestion($items, $name))
48
- ? ", did you mean $t()?"
49
- : '.';
50
- throw new LogicException("Call to undefined static method $rc->name::$name()$hint");
51
- }
52
-
53
-
54
- /**
55
- * Access to undeclared property.
56
- * @throws LogicException
57
- */
58
- public function &__get(string $name): mixed
59
- {
60
- $rc = new \ReflectionClass($this);
61
- $items = array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
62
- $items = array_map(fn($item) => $item->getName(), $items);
63
- $hint = ($t = Helpers::getSuggestion($items, $name))
64
- ? ", did you mean $$t?"
65
- : '.';
66
- throw new LogicException("Attempt to read undeclared property $rc->name::$$name$hint");
67
- }
68
-
69
-
70
- /**
71
- * Access to undeclared property.
72
- * @throws LogicException
73
- */
74
- public function __set(string $name, mixed $value): void
75
- {
76
- $rc = new \ReflectionClass($this);
77
- $items = array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
78
- $items = array_map(fn($item) => $item->getName(), $items);
79
- $hint = ($t = Helpers::getSuggestion($items, $name))
80
- ? ", did you mean $$t?"
81
- : '.';
82
- throw new LogicException("Attempt to write to undeclared property $rc->name::$$name$hint");
83
- }
84
-
85
-
86
- public function __isset(string $name): bool
87
- {
88
- return false;
89
- }
90
-
91
-
92
- /**
93
- * Access to undeclared property.
94
- * @throws LogicException
95
- */
96
- public function __unset(string $name): void
97
- {
98
- $class = static::class;
99
- throw new LogicException("Attempt to unset undeclared property $class::$$name.");
100
- }
101
- }