Skip to content

Commit a30e866

Browse files
noone-silentniden
authored andcommitted
feature(attributes): added attributes support for models and controllers.
1 parent 3795a37 commit a30e866

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+489
-1212
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
.env
2-
.php_cs.cache
3-
.php-cs-fixer.cache
41
.idea/
52
.local/
63
tests/_output/
74
tests/_support/_generated/
85
vendor/
96
*.sqlite*
7+
.env
8+
.php_cs.cache
9+
.php-cs-fixer.cache
10+
docker-compose.override.yml

src/Annotations/Adapter/Apcu.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Apcu as StorageApcu;
1718

1819
/**
1920
* Stores the parsed annotations in apcu.
2021
*/
2122
class Apcu extends StorageApcu implements AdapterInterface
2223
{
24+
/**
25+
* @param string $key
26+
* @param mixed|null $defaultValue
27+
*
28+
* @return Reflection|mixed
29+
*/
30+
public function get(string $key, mixed $defaultValue = null): mixed
31+
{
32+
return parent::get($key, $defaultValue);
33+
}
2334
}

src/Annotations/Adapter/Libmemcached.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Libmemcached as StorageLibmemcached;
1718

1819
/**
@@ -21,4 +22,14 @@
2122
*/
2223
class Libmemcached extends StorageLibmemcached implements AdapterInterface
2324
{
25+
/**
26+
* @param string $key
27+
* @param mixed|null $defaultValue
28+
*
29+
* @return Reflection|mixed
30+
*/
31+
public function get(string $key, mixed $defaultValue = null): mixed
32+
{
33+
return parent::get($key, $defaultValue);
34+
}
2435
}

src/Annotations/Adapter/Memory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Memory as StorageMemory;
1718

1819
/**
@@ -21,4 +22,14 @@
2122
*/
2223
class Memory extends StorageMemory implements AdapterInterface
2324
{
25+
/**
26+
* @param string $key
27+
* @param mixed|null $defaultValue
28+
*
29+
* @return Reflection|mixed
30+
*/
31+
public function get(string $key, mixed $defaultValue = null): mixed
32+
{
33+
return parent::get($key, $defaultValue);
34+
}
2435
}

src/Annotations/Adapter/Redis.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Redis as StorageRedis;
1718

1819
/**
1920
* Stores the parsed annotations in redis.
2021
*/
2122
class Redis extends StorageRedis implements AdapterInterface
2223
{
24+
/**
25+
* @param string $key
26+
* @param mixed|null $defaultValue
27+
*
28+
* @return Reflection|mixed
29+
*/
30+
public function get(string $key, mixed $defaultValue = null): mixed
31+
{
32+
return parent::get($key, $defaultValue);
33+
}
2334
}

src/Annotations/Adapter/Stream.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Stream as StorageStream;
1718

1819
/**
@@ -21,4 +22,14 @@
2122
*/
2223
class Stream extends StorageStream implements AdapterInterface
2324
{
25+
/**
26+
* @param string $key
27+
* @param mixed|null $defaultValue
28+
*
29+
* @return Reflection|mixed
30+
*/
31+
public function get(string $key, mixed $defaultValue = null): mixed
32+
{
33+
return parent::get($key, $defaultValue);
34+
}
2435
}

src/Annotations/Adapter/Weak.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Phalcon\Annotations\Adapter;
1515

16+
use Phalcon\Annotations\Parser\Reflection;
1617
use Phalcon\Storage\Adapter\Weak as StorageWeak;
1718

1819
/**
@@ -21,4 +22,14 @@
2122
*/
2223
class Weak extends StorageWeak implements AdapterInterface
2324
{
25+
/**
26+
* @param string $key
27+
* @param mixed|null $defaultValue
28+
*
29+
* @return Reflection|mixed
30+
*/
31+
public function get(string $key, mixed $defaultValue = null): mixed
32+
{
33+
return parent::get($key, $defaultValue);
34+
}
2435
}

src/Annotations/Parser/Collection.php

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Phalcon\Annotations\Parser;
1515

16-
use Countable;
17-
use Iterator;
16+
use ArrayIterator;
17+
use Exception;
18+
use IteratorAggregate;
19+
use Traversable;
1820

1921
/**
2022
* Represents a collection of annotations. This class allows to traverse a group
@@ -31,18 +33,15 @@
3133
*
3234
* // Get an specific annotation in the collection
3335
* $annotation = $classAnnotations->get("Cacheable");
36+
*
37+
* @template TKey of int
38+
* @template TValue of Annotation
3439
*```
3540
*/
36-
class Collection implements Iterator, Countable
41+
class Collection implements IteratorAggregate
3742
{
38-
/**
39-
* @var array
40-
*/
4143
protected array $annotations;
4244

43-
/**
44-
* @var int
45-
*/
4645
protected int $position = 0;
4746

4847
/**
@@ -52,32 +51,20 @@ class Collection implements Iterator, Countable
5251
*/
5352
public function __construct(array $reflectionData = [])
5453
{
55-
$annotations = [];
54+
$this->annotations = [];
5655
foreach ($reflectionData as $annotationData) {
57-
$annotations[] = new Annotation($annotationData);
56+
$this->annotations[] = new Annotation($annotationData);
5857
}
59-
60-
$this->annotations = $annotations;
6158
}
6259

63-
/**
64-
* Returns the number of annotations in the collection
65-
*
66-
* @return int
67-
*/
68-
public function count(): int
60+
public function getIterator(): Traversable
6961
{
70-
return count($this->annotations);
62+
return new ArrayIterator($this->annotations);
7163
}
7264

73-
/**
74-
* Returns the current annotation in the iterator
75-
*
76-
* @return mixed
77-
*/
78-
public function current(): mixed
65+
public function getAnnotations(): Traversable
7966
{
80-
return $this->annotations[$this->position] ?? false;
67+
return new ArrayIterator($this->annotations);
8168
}
8269

8370
/**
@@ -106,7 +93,7 @@ public function get(string $name): Annotation
10693
*
10794
* @param string $name
10895
*
109-
* @return Annotation[]
96+
* @return TValue[]
11097
*/
11198
public function getAll(string $name): array
11299
{
@@ -120,16 +107,6 @@ public function getAll(string $name): array
120107
return $found;
121108
}
122109

123-
/**
124-
* Returns the internal annotations as an array
125-
*
126-
* @return Annotation[]
127-
*/
128-
public function getAnnotations(): array
129-
{
130-
return $this->annotations;
131-
}
132-
133110
/**
134111
* Check if an annotation exists in a collection
135112
*
@@ -147,44 +124,4 @@ public function has(string $name): bool
147124

148125
return false;
149126
}
150-
151-
/**
152-
* Returns the current position/key in the iterator
153-
*
154-
* @return int
155-
*/
156-
public function key(): int
157-
{
158-
return $this->position;
159-
}
160-
161-
/**
162-
* Moves the internal iteration pointer to the next position
163-
*
164-
* @return void
165-
*/
166-
public function next(): void
167-
{
168-
$this->position++;
169-
}
170-
171-
/**
172-
* Rewinds the internal iterator
173-
*
174-
* @return void
175-
*/
176-
public function rewind(): void
177-
{
178-
$this->position = 0;
179-
}
180-
181-
/**
182-
* Check if the current annotation in the iterator is valid
183-
*
184-
* @return bool
185-
*/
186-
public function valid(): bool
187-
{
188-
return isset($this->annotations[$this->position]);
189-
}
190127
}

src/Annotations/Router/Connect.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon Framework.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Annotations\Router;
15+
16+
use Attribute;
17+
use Phalcon\Http\Message\Interfaces\RequestMethodInterface;
18+
19+
#[Attribute(Attribute::TARGET_METHOD)]
20+
class Connect extends Route
21+
{
22+
public function __construct(...$params)
23+
{
24+
$params['methods'] = RequestMethodInterface::METHOD_CONNECT;
25+
parent::__construct(...$params);
26+
}
27+
}

src/Annotations/Router/Delete.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
namespace Phalcon\Annotations\Router;
1515

1616
use Attribute;
17+
use Phalcon\Http\Message\Interfaces\RequestMethodInterface;
1718

1819
#[Attribute(Attribute::TARGET_METHOD)]
1920
class Delete extends Route
2021
{
2122
public function __construct(...$params)
2223
{
23-
$params['methods'] = 'DELETE';
24+
$params['methods'] = RequestMethodInterface::METHOD_DELETE;
2425
parent::__construct(...$params);
2526
}
2627
}

0 commit comments

Comments
 (0)