Skip to content

Commit 9230e5e

Browse files
committed
removed support for @annotations (BC break)
1 parent 3cf284a commit 9230e5e

5 files changed

Lines changed: 4 additions & 156 deletions

File tree

src/Application/LinkGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ private function validateLinkTarget(
326326
: " from '{$presenter->getName()}:{$presenter->getAction()}'";
327327
if ($mode !== 'forward' && !(new UI\AccessPolicy($element))->isLinkable()) {
328328
throw new UI\InvalidLinkException("Link to forbidden $message.");
329-
} elseif ($presenter?->invalidLinkMode
330-
&& (UI\ComponentReflection::parseAnnotation($element, 'deprecated') || $element->getAttributes(Attributes\Deprecated::class))
331-
) {
329+
} elseif ($presenter?->invalidLinkMode && $element->getAttributes(Attributes\Deprecated::class)) {
332330
trigger_error("Link to deprecated $message.", E_USER_DEPRECATED);
333331
}
334332
}

src/Application/UI/AccessPolicy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ private function applyInternalRules(array $attrs, Component $component): array
7070
if (
7171
$this->element instanceof \ReflectionMethod
7272
&& str_starts_with($this->element->getName(), $component::formatSignalMethod(''))
73-
&& !ComponentReflection::parseAnnotation($this->element, 'crossOrigin')
7473
&& !Nette\Utils\Arrays::some($attrs, fn($attr) => $attr->sameOrigin === false)
7574
) {
7675
$attrs[] = new Attributes\Requires(sameOrigin: true);

src/Application/UI/ComponentReflection.php

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ public function getParameters(): array
4848
foreach ($this->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
4949
if ($prop->isStatic()) {
5050
continue;
51-
} elseif (
52-
self::parseAnnotation($prop, 'persistent')
53-
|| $prop->getAttributes(Attributes\Persistent::class)
54-
) {
51+
} elseif ($prop->getAttributes(Attributes\Persistent::class)) {
5552
$params[$prop->getName()] = [
5653
'def' => $prop->hasDefaultValue() ? $prop->getDefaultValue() : null,
5754
'type' => ParameterConverter::getType($prop),
@@ -92,7 +89,7 @@ public function getPersistentParams(): array
9289

9390
/**
9491
* Returns array of persistent components. They are tagged with class-level attribute
95-
* #[Persistent] or annotation @persistent or returned by Presenter::getPersistentComponents().
92+
* #[Persistent] or returned by Presenter::getPersistentComponents().
9693
* @return array<string, array{since: class-string}>
9794
*/
9895
public function getPersistentComponents(): array
@@ -104,9 +101,7 @@ public function getPersistentComponents(): array
104101
}
105102

106103
$attrs = $this->getAttributes(Attributes\Persistent::class);
107-
$names = $attrs
108-
? $attrs[0]->getArguments()
109-
: (array) self::parseAnnotation($this, 'persistent');
104+
$names = $attrs ? $attrs[0]->getArguments() : [];
110105
$names = array_merge($names, $class::getPersistentComponents());
111106
$components = array_fill_keys($names, ['since' => $class]);
112107

@@ -174,77 +169,6 @@ public function getSignalMethod(string $signal): ?\ReflectionMethod
174169
}
175170

176171

177-
/**
178-
* Returns an annotation value.
179-
* @deprecated
180-
* @return ?list<mixed>
181-
*/
182-
public static function parseAnnotation(\Reflector $ref, string $name): ?array
183-
{
184-
if (!preg_match_all('#[\s*]@' . preg_quote($name, '#') . '(?:\(\s*([^)]*)\s*\)|\s|$)#', (string) $ref->getDocComment(), $m)) {
185-
return null;
186-
}
187-
188-
$tokens = ['true' => true, 'false' => false, 'null' => null];
189-
$res = [];
190-
foreach ($m[1] as $s) {
191-
foreach (preg_split('#\s*,\s*#', $s, -1, PREG_SPLIT_NO_EMPTY) ?: ['true'] as $item) {
192-
$res[] = array_key_exists($tmp = strtolower($item), $tokens)
193-
? $tokens[$tmp]
194-
: $item;
195-
}
196-
}
197-
198-
$alt = match ($name) {
199-
'persistent' => '#[Nette\Application\Attributes\Persistent]',
200-
'deprecated' => '#[Nette\Application\Attributes\Deprecated]',
201-
'crossOrigin' => '#[Nette\Application\Attributes\Request(sameOrigin: false)]',
202-
default => 'alternative'
203-
};
204-
trigger_error("Annotation @$name is deprecated, use $alt (used in " . Reflection::toString($ref) . ')', E_USER_DEPRECATED);
205-
return $res;
206-
}
207-
208-
209-
#[\Deprecated]
210-
public function hasAnnotation(string $name): bool
211-
{
212-
return (bool) self::parseAnnotation($this, $name);
213-
}
214-
215-
216-
#[\Deprecated]
217-
public function getAnnotation(string $name): mixed
218-
{
219-
$res = self::parseAnnotation($this, $name);
220-
return $res ? end($res) : null;
221-
}
222-
223-
224-
public function getMethod($name): MethodReflection
225-
{
226-
return new MethodReflection($this->getName(), $name);
227-
}
228-
229-
230-
/**
231-
* @return list<MethodReflection>
232-
*/
233-
public function getMethods($filter = -1): array
234-
{
235-
foreach ($res = parent::getMethods($filter) as $key => $val) {
236-
$res[$key] = new MethodReflection($this->getName(), $val->getName());
237-
}
238-
239-
return $res;
240-
}
241-
242-
243-
/**
244-
* @deprecated
245-
* @param array<string, mixed> $args
246-
* @return list<mixed>
247-
*/
248172
#[\Deprecated]
249173
public static function combineArgs(\ReflectionFunctionAbstract $method, array $args): array
250174
{

src/Application/UI/MethodReflection.php

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

tests/UI/ComponentReflection.parseAnnotation.phpt

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

0 commit comments

Comments
 (0)