Skip to content

Commit b0f8fe6

Browse files
committed
removed support for @annotations (BC break)
1 parent 6642f42 commit b0f8fe6

File tree

4 files changed

+6
-160
lines changed

4 files changed

+6
-160
lines changed

src/Application/LinkGenerator.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function createRequest(
135135
$method = $reflection->getSignalMethod($signal);
136136
if (!$method) {
137137
throw new UI\InvalidLinkException("Unknown signal '$signal', missing handler {$reflection->getName()}::{$component::formatSignalMethod($signal)}()");
138-
} elseif ($this->isDeprecated($refPresenter, $method)) {
138+
} elseif ($refPresenter?->invalidLinkMode && $reflection->getAttributes(Attributes\Deprecated::class)) {
139139
trigger_error("Link to deprecated signal '$signal'" . ($component === $refPresenter ? '' : ' in ' . $component::class) . " from '{$refPresenter->getName()}:{$refPresenter->getAction()}'.", E_USER_DEPRECATED);
140140
}
141141

@@ -166,7 +166,7 @@ public function createRequest(
166166
$current = $refPresenter && ($action === '*' || strcasecmp($action, $refPresenter->getAction()) === 0) && $presenterClass === $refPresenter::class;
167167

168168
$reflection = new UI\ComponentReflection($presenterClass);
169-
if ($this->isDeprecated($refPresenter, $reflection)) {
169+
if ($refPresenter?->invalidLinkMode && $reflection->getAttributes(Attributes\Deprecated::class)) {
170170
trigger_error("Link to deprecated presenter '$presenter' from '{$refPresenter->getName()}:{$refPresenter->getAction()}'.", E_USER_DEPRECATED);
171171
}
172172

@@ -178,7 +178,7 @@ public function createRequest(
178178

179179
// counterpart of run() & tryCall()
180180
if ($method = $reflection->getActionRenderMethod($action)) {
181-
if ($this->isDeprecated($refPresenter, $method)) {
181+
if ($refPresenter?->invalidLinkMode && $reflection->getAttributes(Attributes\Deprecated::class)) {
182182
trigger_error("Link to deprecated action '$presenter:$action' from '{$refPresenter->getName()}:{$refPresenter->getAction()}'.", E_USER_DEPRECATED);
183183
}
184184

@@ -297,13 +297,6 @@ public function withReferenceUrl(string $url): static
297297
}
298298

299299

300-
private function isDeprecated(?UI\Presenter $presenter, \ReflectionClass|\ReflectionMethod $reflection): bool
301-
{
302-
return $presenter?->invalidLinkMode
303-
&& (UI\ComponentReflection::parseAnnotation($reflection, 'deprecated') || $reflection->getAttributes(Attributes\Deprecated::class));
304-
}
305-
306-
307300
/** @internal */
308301
public static function applyBase(string $link, string $base): string
309302
{

src/Application/UI/ComponentReflection.php

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ public function getParameters(): array
4444
foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
4545
if ($prop->isStatic()) {
4646
continue;
47-
} elseif (
48-
self::parseAnnotation($prop, 'persistent')
49-
|| $prop->getAttributes(Attributes\Persistent::class)
50-
) {
47+
} elseif ($prop->getAttributes(Attributes\Persistent::class)) {
5148
$params[$prop->getName()] = [
5249
'def' => $prop->hasDefaultValue() ? $prop->getDefaultValue() : null,
5350
'type' => ParameterConverter::getType($prop),
@@ -88,7 +85,7 @@ public function getPersistentParams(): array
8885

8986
/**
9087
* Returns array of persistent components. They are tagged with class-level attribute
91-
* #[Persistent] or annotation @persistent or returned by Presenter::getPersistentComponents().
88+
* #[Persistent] or returned by Presenter::getPersistentComponents().
9289
* @return array<string, array{since: string}>
9390
*/
9491
public function getPersistentComponents(): array
@@ -100,9 +97,7 @@ public function getPersistentComponents(): array
10097
}
10198

10299
$attrs = $this->getAttributes(Attributes\Persistent::class);
103-
$names = $attrs
104-
? $attrs[0]->getArguments()
105-
: (array) self::parseAnnotation($this, 'persistent');
100+
$names = $attrs ? $attrs[0]->getArguments() : [];
106101
$names = array_merge($names, $class::getPersistentComponents());
107102
$components = array_fill_keys($names, ['since' => $class]);
108103

@@ -150,71 +145,6 @@ public function getSignalMethod(string $signal): ?\ReflectionMethod
150145
}
151146

152147

153-
/**
154-
* Returns an annotation value.
155-
* @deprecated
156-
*/
157-
public static function parseAnnotation(\Reflector $ref, string $name): ?array
158-
{
159-
if (!preg_match_all('#[\s*]@' . preg_quote($name, '#') . '(?:\(\s*([^)]*)\s*\)|\s|$)#', (string) $ref->getDocComment(), $m)) {
160-
return null;
161-
}
162-
163-
$tokens = ['true' => true, 'false' => false, 'null' => null];
164-
$res = [];
165-
foreach ($m[1] as $s) {
166-
foreach (preg_split('#\s*,\s*#', $s, -1, PREG_SPLIT_NO_EMPTY) ?: ['true'] as $item) {
167-
$res[] = array_key_exists($tmp = strtolower($item), $tokens)
168-
? $tokens[$tmp]
169-
: $item;
170-
}
171-
}
172-
173-
$alt = match ($name) {
174-
'persistent' => '#[Nette\Application\Attributes\Persistent]',
175-
'deprecated' => '#[Nette\Application\Attributes\Deprecated]',
176-
'crossOrigin' => '#[Nette\Application\Attributes\Request(sameOrigin: false)]',
177-
default => 'alternative'
178-
};
179-
trigger_error("Annotation @$name is deprecated, use $alt (used in " . Reflection::toString($ref) . ')', E_USER_DEPRECATED);
180-
return $res;
181-
}
182-
183-
184-
#[\Deprecated]
185-
public function hasAnnotation(string $name): bool
186-
{
187-
return (bool) self::parseAnnotation($this, $name);
188-
}
189-
190-
191-
#[\Deprecated]
192-
public function getAnnotation(string $name): mixed
193-
{
194-
$res = self::parseAnnotation($this, $name);
195-
return $res ? end($res) : null;
196-
}
197-
198-
199-
public function getMethod($name): MethodReflection
200-
{
201-
return new MethodReflection($this->getName(), $name);
202-
}
203-
204-
205-
/**
206-
* @return MethodReflection[]
207-
*/
208-
public function getMethods($filter = -1): array
209-
{
210-
foreach ($res = parent::getMethods($filter) as $key => $val) {
211-
$res[$key] = new MethodReflection($this->getName(), $val->getName());
212-
}
213-
214-
return $res;
215-
}
216-
217-
218148
#[\Deprecated]
219149
public static function combineArgs(\ReflectionFunctionAbstract $method, array $args): array
220150
{

src/Application/UI/MethodReflection.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/UI/ComponentReflection.parseAnnotation.phpt

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)