Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Annotations/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
*/
class Annotation
{
/**
* Type of an expression node that holds a value that PHP resolved
* already. The attributes reader makes these nodes, because
* ReflectionAttribute::getArguments() gives the values and not a parse
* tree. The value goes to the caller without a change.
*
* The parser types stop at 309 (PHANNOT_T_ARBITRARY_TEXT). The value is
* 1000 and not 310, so that a token added to the grammar later cannot
* make two case labels with one value in getExpression().
*
* @var int
*/
const int T_RESOLVED = 1000;

/**
* Annotation Arguments
*
Expand Down
104 changes: 104 additions & 0 deletions src/Annotations/AttributesReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations;

use Phalcon\Contracts\Annotations\AnnotationsTypes;
use ReflectionClass;

/**
* Parses PHP attributes returning an array with the found annotations
*
* The array has the same shape as the one of Phalcon\Annotations\Reader, so
* the adapters, Reflection, Collection and Annotation do not know which
* reader made it.
*
* PHP resolves the value of an attribute argument, so there is no parse tree
* to walk. Each value goes in a node of the type Annotation::T_RESOLVED,
* which Annotation::getExpression() gives back without a change.
*
* @phpstan-import-type annotations_arguments from AnnotationsTypes
* @phpstan-import-type annotations_node_list from AnnotationsTypes
* @phpstan-import-type annotations_reflection_data from AnnotationsTypes
*/
class AttributesReader implements \Phalcon\Annotations\ReaderInterface
{
/**
* An attribute of this namespace gets the short name, so that `#[Column]`
* and `@Column` give the same name. Every other attribute keeps the full
* class name, so that an attribute of another library cannot take the
* place of a Phalcon one.
*
* @var string
*/
const string PHALCON_NAMESPACE = 'Phalcon\\\\Annotations\\\\';


/**
* Reads attributes from the class, its constants, properties and methods
*
* @phpstan-param class-string $className
*
* @phpstan-return annotations_reflection_data
* @param string $className
* @return array
*/
public function parse(string $className): array
{
}

/**
* Makes the argument list of one attribute. PHP resolved the values
* already, so each one goes in a node that Annotation::getExpression()
* gives back without a change. An integer key is a positional argument
* and a string key is a named one.
*
* @phpstan-param array<array-key, mixed> $attributeArguments
*
* @phpstan-return annotations_arguments
* @param array $attributeArguments
* @return array
*/
protected function buildArguments(array $attributeArguments): array
{
}

/**
* Makes the node list of one target from its attributes
*
* @phpstan-param array<array-key, \ReflectionAttribute<object>> $attributes
*
* @phpstan-return annotations_node_list
* @param array $attributes
* @param string $file
* @param int $line
* @return array
*/
protected function buildNodes(array $attributes, string $file, int $line): array
{
}

/**
* Gives the name that the collection matches on.
*
* An attribute of the Phalcon\Annotations namespace gets the short name,
* so that `#[Column]` and `@Column` give the same name. Every other
* attribute keeps the full class name, so that an attribute of another
* library cannot take the place of a Phalcon one.
*
* Extend this reader and override this method to give the same short
* name to the attributes of your own namespace.
*
* @param string $name
* @return string
*/
protected function resolveName(string $name): string
{
}
}
76 changes: 76 additions & 0 deletions src/Annotations/Models/MetaData/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Models\MetaData;

/**
* Describes a model column. It is the attribute form of `@Column`.
*
* The parameter names are camelCase, because PSR-12 does not allow
* snake_case. The metadata strategy reads the two spellings. The default
* value is `defaultValue` and not `default`, because `default` is a Zephir
* keyword.
*/
#[\Attribute(8)]
class Column
{
/**
* @var bool
*/
public $allowEmptyString;

/**
* @var string|null
*/
public $column;

/**
* @var mixed
*/
public $defaultValue;

/**
* @var int|null
*/
public $length;

/**
* @var bool
*/
public $nullable;

/**
* @var bool
*/
public $skipOnInsert;

/**
* @var bool
*/
public $skipOnUpdate;

/**
* @var string
*/
public $type;

/**
* @param string|null $column
* @param string $type
* @param int|null $length
* @param bool $nullable
* @param bool $skipOnInsert
* @param bool $skipOnUpdate
* @param bool $allowEmptyString
* @param mixed $defaultValue
*/
public function __construct(?string $column = null, string $type = 'string', ?int $length = null, bool $nullable = false, bool $skipOnInsert = false, bool $skipOnUpdate = false, bool $allowEmptyString = false, $defaultValue = null)
{
}
}
18 changes: 18 additions & 0 deletions src/Annotations/Models/MetaData/Identity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Models\MetaData;

/**
* Marks a property as the identity column. It is the attribute form of `@Identity`.
*/
#[\Attribute(8)]
class Identity
{
}
18 changes: 18 additions & 0 deletions src/Annotations/Models/MetaData/Primary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Models\MetaData;

/**
* Marks a property as part of the primary key. It is the attribute form of `@Primary`.
*/
#[\Attribute(8)]
class Primary
{
}
29 changes: 29 additions & 0 deletions src/Annotations/Models/MetaData/Source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Models\MetaData;

/**
* Names the table of a model. No framework code reads it today.
*/
#[\Attribute(1)]
class Source
{
/**
* @var string
*/
public $table;

/**
* @param string $table
*/
public function __construct(string $table)
{
}
}
23 changes: 6 additions & 17 deletions src/Annotations/ReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
use Phalcon\Contracts\Annotations\AnnotationsTypes;

/**
* Parses docblocks returning an array with the found annotations
* Reads the annotations of a class and returns them as an array
*
* Phalcon\Annotations\Reader reads the docblocks and Phalcon\Annotations\AttributesReader
* reads the PHP attributes. The two give the same array shape, so the adapter
* and the classes after it do not know which reader made it.
*
* @phpstan-import-type annotations_node_list from AnnotationsTypes
* @phpstan-import-type annotations_reflection_data from AnnotationsTypes
*/
interface ReaderInterface
{
/**
* Reads annotations from the class docblocks, its constants, properties and methods
* Reads annotations from the class, its constants, properties and methods
*
* @phpstan-param class-string $className
*
Expand All @@ -29,18 +32,4 @@ interface ReaderInterface
* @return array
*/
public function parse(string $className): array;

/**
* Parses a raw docblock returning the annotations found
*
* @phpstan-param string|null $file
* @phpstan-param int|null $line
*
* @phpstan-return annotations_node_list
* @param string $docBlock
* @param mixed $file
* @param mixed $line
* @return array
*/
public static function parseDocBlock(string $docBlock, $file = null, $line = null): array;
}
38 changes: 38 additions & 0 deletions src/Annotations/Router/Connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Router;

use Phalcon\Contracts\Annotations\AnnotationsTypes;
use Phalcon\Http\Message\RequestMethodInterface;

/**
* Marks a method as a CONNECT route. It is the attribute form of `@Connect`.
*
* @phpstan-import-type annotations_route_before_match from AnnotationsTypes
* @phpstan-import-type annotations_route_converters from AnnotationsTypes
* @phpstan-import-type annotations_route_paths from AnnotationsTypes
*/
#[\Attribute(132)]
class Connect extends \Phalcon\Annotations\Router\Route
{
/**
* @phpstan-param annotations_route_paths $paths
* @phpstan-param annotations_route_converters $converters
* @phpstan-param annotations_route_before_match $beforeMatch
* @param string $route
* @param string|null $name
* @param array $paths
* @param array $converters
* @param mixed $beforeMatch
*/
public function __construct(string $route, ?string $name = null, array $paths = [], array $converters = [], $beforeMatch = null)
{
}
}
38 changes: 38 additions & 0 deletions src/Annotations/Router/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Annotations\Router;

use Phalcon\Contracts\Annotations\AnnotationsTypes;
use Phalcon\Http\Message\RequestMethodInterface;

/**
* Marks a method as a DELETE route. It is the attribute form of `@Delete`.
*
* @phpstan-import-type annotations_route_before_match from AnnotationsTypes
* @phpstan-import-type annotations_route_converters from AnnotationsTypes
* @phpstan-import-type annotations_route_paths from AnnotationsTypes
*/
#[\Attribute(132)]
class Delete extends \Phalcon\Annotations\Router\Route
{
/**
* @phpstan-param annotations_route_paths $paths
* @phpstan-param annotations_route_converters $converters
* @phpstan-param annotations_route_before_match $beforeMatch
* @param string $route
* @param string|null $name
* @param array $paths
* @param array $converters
* @param mixed $beforeMatch
*/
public function __construct(string $route, ?string $name = null, array $paths = [], array $converters = [], $beforeMatch = null)
{
}
}
Loading
Loading