Skip to content

Commit ec24d29

Browse files
committed
add uses in classes generation
1 parent 8e71dcd commit ec24d29

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Ubiquity/attributes/AttributesEngine.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class AttributesEngine implements AnnotationsEngineInterface {
3232

3333
protected static array $registry;
3434

35+
protected array $uses;
36+
3537
protected function attributesNewInstances(array $attributes): array {
3638
$result = [];
3739
foreach ($attributes as $attribute) {
@@ -85,6 +87,7 @@ public function start(string $cacheDirectory): void {
8587
'autowired' => Autowired::class,
8688
'injected' => Injected::class
8789
];
90+
$this->uses = [];
8891
}
8992

9093
public function getAnnotationByKey(?string $key = null): ?string {
@@ -95,9 +98,10 @@ public function registerAnnotations(array $nameClasses): void {
9598
\array_merge(self::$registry, $nameClasses);
9699
}
97100

98-
public static function getAnnotation(string $key, array $parameters = []): ?object {
101+
public function getAnnotation(string $key, array $parameters = []): ?object {
99102
if (isset(self::$registry[$key])) {
100103
$classname = self::$registry[$key];
104+
$this->uses[$classname] = true;
101105
$reflect = new \ReflectionClass($classname);
102106
return $reflect->newInstanceArgs($parameters);
103107
}
@@ -137,5 +141,9 @@ public function is(string $key, object $annotation): bool {
137141
}
138142
return false;
139143
}
144+
145+
public function getUses(): array {
146+
return \array_keys($this->uses);
147+
}
140148
}
141149

src/Ubiquity/attributes/items/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Validator extends BaseAttribute {
2828
public ?string $message;
2929
public ?string $severity;
3030
public ?string $group;
31-
public ?array $constraints = [];
31+
public ?array $constraints;
3232

3333
/**
3434
* Validator constructor.
@@ -39,15 +39,15 @@ class Validator extends BaseAttribute {
3939
* @param string|null $group
4040
* @throws \Exception
4141
*/
42-
public function __construct(string $type, null|string|array $constraints = null, ?string $message = null, ?string $severity = null, ?string $group = null) {
42+
public function __construct(string $type, null|string|array $constraints = ['ref' => false], ?string $message = null, ?string $severity = null, ?string $group = null) {
4343
if (!isset (ValidatorsManager::$validatorTypes [$type])) {
4444
throw new \Exception ('This type does not exists : ' . $type);
4545
}
4646
$this->type = $type;
4747
$this->message = $message;
4848
$this->severity = $severity;
4949
$this->group = $group;
50-
if (!\is_array($constraints)) {
50+
if ($constraints && !\is_array($constraints)) {
5151
$this->constraints['ref'] = $constraints;
5252
} else {
5353
$this->constraints = $constraints;

0 commit comments

Comments
 (0)