Skip to content

Commit 91e78d6

Browse files
committed
removed support for @annotations (BC break)
1 parent 0d7b1eb commit 91e78d6

File tree

5 files changed

+4
-154
lines changed

5 files changed

+4
-154
lines changed

src/Application/LinkGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ private function validateLinkTarget(
302302
{
303303
if ($mode !== 'forward' && !(new UI\AccessPolicy($element))->isLinkable()) {
304304
throw new UI\InvalidLinkException("Link to forbidden $message from '{$presenter->getName()}:{$presenter->getAction()}'.");
305-
} elseif ($presenter?->invalidLinkMode
306-
&& (UI\ComponentReflection::parseAnnotation($element, 'deprecated') || $element->getAttributes(Attributes\Deprecated::class))
307-
) {
305+
} elseif ($presenter?->invalidLinkMode && $element->getAttributes(Attributes\Deprecated::class)) {
308306
trigger_error("Link to deprecated $message from '{$presenter->getName()}:{$presenter->getAction()}'.", E_USER_DEPRECATED);
309307
}
310308
}

src/Application/UI/AccessPolicy.php

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

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: class-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

@@ -170,71 +165,6 @@ public function getSignalMethod(string $signal): ?\ReflectionMethod
170165
}
171166

172167

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

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)