Skip to content

Phalcon Annotations

Updated View as Markdown

Annotations\Adapter\AbstractAdapter

Abstract Source on GitHub

This is the base class for Phalcon\Annotations adapters

The adapters supply read() and write(). This class does not declare them, the same as in cphalcon.

@method mixed read(string $key) @method mixed write(string $key, Reflection $data)

Uses Phalcon\Annotations\Collection · Phalcon\Annotations\Exception · Phalcon\Annotations\Reader · Phalcon\Annotations\ReaderInterface · Phalcon\Annotations\Reflection · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

protectedarray$annotations = []
protectedint$annotationsLimit = 0

Maximum number of class annotation entries retained in the in-memory cache. 0 (default) keeps the original unbounded behavior; a positive value clears the cache when adding a new class would exceed it.

protectedReaderInterface|null$reader = null

Methods

Public · 11

get()

public function get( mixed $className ): Reflection;

Parses or retrieves all the annotations found in a class

getAnnotationsLimit()

public function getAnnotationsLimit(): int;

Returns the configured annotations-cache cap (0 = unlimited). See setAnnotationsLimit().

getConstant()

public function getConstant(
    string $className,
    string $constantName
): Collection;

Returns the annotations found in a specific constant

getConstants()

public function getConstants( string $className ): array;

Returns the annotations found in all the class’ constants

getMethod()

public function getMethod(
    string $className,
    string $methodName
): Collection;

Returns the annotations found in a specific method

getMethods()

public function getMethods( string $className ): array;

Returns the annotations found in all the class’ methods

getProperties()

public function getProperties( string $className ): array;

Returns the annotations found in all the class’ properties

getProperty()

public function getProperty(
    string $className,
    string $propertyName
): Collection;

Returns the annotations found in a specific property

getReader()

public function getReader(): ReaderInterface;

Returns the annotation reader

setAnnotationsLimit()

public function setAnnotationsLimit( int $annotationsLimit );

Caps the number of class entries retained in the annotations cache. 0 disables the cap (the default; preserves the original unbounded behavior). When the cap is exceeded, the cache is cleared and repopulated on subsequent reads.

setReader()

public function setReader( ReaderInterface $reader );

Sets the annotations parser

Annotations\Adapter\AdapterInterface

Interface Source on GitHub

This interface must be implemented by adapters in Phalcon\Annotations

  • Phalcon\Annotations\Adapter\AdapterInterface

Uses Phalcon\Annotations\Collection · Phalcon\Annotations\ReaderInterface · Phalcon\Annotations\Reflection · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Methods

Public · 9

get()

public function get( string $className ): Reflection;

Parses or retrieves all the annotations found in a class

getConstant()

public function getConstant(
    string $className,
    string $constantName
): Collection;

Returns the annotations found in a specific constant

getConstants()

public function getConstants( string $className ): array;

Returns the annotations found in all the class’ constants

getMethod()

public function getMethod(
    string $className,
    string $methodName
): Collection;

Returns the annotations found in a specific method

getMethods()

public function getMethods( string $className ): array;

Returns the annotations found in all the class’ methods

getProperties()

public function getProperties( string $className ): array;

Returns the annotations found in all the class’ methods

getProperty()

public function getProperty(
    string $className,
    string $propertyName
): Collection;

Returns the annotations found in a specific property

getReader()

public function getReader(): ReaderInterface;

Returns the annotation reader

setReader()

public function setReader( ReaderInterface $reader );

Sets the annotations parser

Annotations\Adapter\Apcu

Class Source on GitHub

Stores the parsed annotations in APCu. This adapter is suitable for production

use Phalcon\Annotations\Adapter\Apcu;

$annotations = new Apcu();

Uses Phalcon\Annotations\Reflection · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

protectedstring$prefix = ""
protectedint$ttl = 172800

Methods

Public · 3

__construct()

public function __construct( array $options = [] );

Phalcon\Annotations\Adapter\Apcu constructor

read()

public function read( string $key ): bool|Reflection;

Reads parsed annotations from APCu

write()

public function write(
    string $key,
    Reflection $data
): bool;

Writes parsed annotations to APCu

Annotations\Adapter\Memory

Class Source on GitHub

Stores the parsed annotations in memory. This adapter is the suitable development/testing

Uses Phalcon\Annotations\Reflection · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

protectedmixed$data = null

The property has no initializer, so it is null until the first write.

Methods

Public · 3

__construct()

public function __construct( array $options = [] );

read()

public function read( string $key ): bool|Reflection;

Reads parsed annotations from memory

write()

public function write(
    string $key,
    Reflection $data
): void;

Writes parsed annotations to memory

Annotations\Adapter\Stream

Class Source on GitHub

Stores the parsed annotations in files. This adapter is suitable for production

use Phalcon\Annotations\Adapter\Stream;

$annotations = new Stream(
    [
        "annotationsDir" => "app/cache/annotations/",
    ]
);

Uses Phalcon\Annotations\Annotation · Phalcon\Annotations\Collection · Phalcon\Annotations\Exceptions\AnnotationsDirectoryNotWritable · Phalcon\Annotations\Exceptions\CannotReadAnnotationData · Phalcon\Annotations\Reflection · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Support\Traits\FilePathTrait · Phalcon\Traits\Php\FileTrait

Method Summary

Properties

protectedstring$annotationsDir = "./"

Methods

Public · 3

__construct()

public function __construct( array $options = [] );

Phalcon\Annotations\Adapter\Stream constructor

read()

public function read( string $key ): bool|int|Reflection;

Reads parsed annotations from files

write()

public function write(
    string $key,
    Reflection $data
): void;

Writes parsed annotations to files

Annotations\Annotation

Class Source on GitHub

Represents a single annotation in an annotations collection

  • Phalcon\Annotations\Annotation

Uses Phalcon\Annotations\Docblock\Scanner\Opcode · Phalcon\Annotations\Exceptions\UnknownAnnotationExpression · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Constants

intT_RESOLVED = 1000

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().

Properties

protectedarray$arguments = []

Annotation Arguments

protectedarray$exprArguments = []

Annotation ExprArguments

protectedstring|null$name = null

Annotation Name

Methods

Public · 10

__construct()

public function __construct( array $reflectionData );

Phalcon\Annotations\Annotation constructor

getArgument()

public function getArgument( int|string $position ): mixed;

Returns an argument in a specific position

getArguments()

public function getArguments(): array;

Returns the expression arguments

getExprArguments()

public function getExprArguments(): array;

Returns the expression arguments without resolving

getExpression()

public function getExpression( array $expr ): mixed;

Resolves an annotation expression

getName()

public function getName(): string|null;

Returns the annotation’s name

getNamedArgument()

public function getNamedArgument( string $name ): mixed;

Returns a named argument

getNamedParameter()

public function getNamedParameter( string $name ): mixed;

Returns a named parameter

hasArgument()

public function hasArgument( int|string $position ): bool;

Returns an argument in a specific position

numberArguments()

public function numberArguments(): int;

Returns the number of arguments that the annotation has

Annotations\AnnotationsFactory

Class Source on GitHub

Factory to create annotations components

Uses Phalcon\Annotations\Adapter\AdapterInterface · Phalcon\Annotations\Adapter\Apcu · Phalcon\Annotations\Adapter\Memory · Phalcon\Annotations\Adapter\Stream · Phalcon\Config\ConfigInterface · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Factory\AbstractFactory

Method Summary

Methods

Public · 3

__construct()

public function __construct( array $services = [] );

AdapterFactory constructor.

load()

public function load( mixed $config ): AdapterInterface;

Factory to create an instance from a Config object

newInstance()

public function newInstance(
    string $name,
    array $options = []
): AdapterInterface;

Create a new instance of the adapter

Protected · 2

getExceptionClass()

protected function getExceptionClass(): string;

getServices()

protected function getServices(): array;

Returns the available adapters

Annotations\AttributesReader

Class Source on GitHub

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.

Uses Phalcon\Annotations\Docblock\Scanner\Opcode · Phalcon\Contracts\Annotations\AnnotationsTypes · ReflectionAttribute · ReflectionClass · ReflectionException

Method Summary

Constants

stringPHALCON_NAMESPACE = "Phalcon\\Annotations\\"

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.

Methods

Public · 1

parse()

public function parse( string $className ): array;

Reads attributes from the class, its constants, properties and methods

Protected · 3

buildArguments()

protected function buildArguments( array $attributeArguments ): 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.

buildNodes()

protected function buildNodes(
    array $attributes,
    string $file,
    int $line
): array;

Makes the node list of one target from its attributes

resolveName()

protected function resolveName( string $name ): string;

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.

Annotations\Collection

Class Source on GitHub

Represents a collection of annotations. This class allows to traverse a group of annotations easily

// Traverse annotations
foreach ($classAnnotations as $annotation) {
    echo "Name=", $annotation->getName(), PHP_EOL;
}

// Check if the annotations has a specific
var_dump($classAnnotations->has("Cacheable"));

// Get an specific annotation in the collection
$annotation = $classAnnotations->get("Cacheable");

The class cannot carry an @implements Iterator<int, Annotation> tag. current() returns false past the end of the collection, while Psalm’s Iterator stub requires TValue|null there. Narrowing the iteration would mean changing that return to null, which is a v7 signature change.

  • Phalcon\Annotations\Collection - implements \Iterator, \Countable

Uses Countable · Iterator · Phalcon\Annotations\Exceptions\AnnotationNotFound · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

protectedarray$annotations
protectedint$position = 0

Methods

Public · 11

__construct()

public function __construct( array $reflectionData = [] );

Phalcon\Annotations\Collection constructor

count()

public function count(): int;

Returns the number of annotations in the collection

current()

public function current(): mixed;

Returns the current annotation in the iterator

get()

public function get( string $name ): Annotation;

Returns the first annotation that match a name

getAll()

public function getAll( string $name ): array;

Returns all the annotations that match a name

getAnnotations()

public function getAnnotations(): array;

Returns the internal annotations as an array

has()

public function has( string $name ): bool;

Check if an annotation exists in a collection

key()

public function key(): int;

Returns the current position/key in the iterator

next()

public function next(): void;

Moves the internal iteration pointer to the next position

rewind()

public function rewind(): void;

Rewinds the internal iterator

valid()

public function valid(): bool;

Check if the current annotation in the iterator is valid

Annotations\Exception

Class Source on GitHub

Class for exceptions thrown by Phalcon\Annotations

Annotations\Exceptions\AnnotationNotFound

Class Source on GitHub

Uses Phalcon\Annotations\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Annotations\Exceptions\AnnotationsDirectoryNotWritable

Class Source on GitHub

Uses Phalcon\Annotations\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Annotations\Exceptions\CannotReadAnnotationData

Class Source on GitHub
  • \RuntimeException
    • Phalcon\Annotations\Exceptions\CannotReadAnnotationData

Uses RuntimeException

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Annotations\Exceptions\UnknownAnnotationExpression

Class Source on GitHub

Uses Phalcon\Annotations\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $type );

Annotations\Models\MetaData\Column

Class Source on GitHub

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.

  • Phalcon\Annotations\Models\MetaData\Column

Uses Attribute

Method Summary

Properties

publicbool$allowEmptyString = false
publicstring|null$column = null
publicmixed$defaultValue = null
publicint|null$length = null
publicbool$nullable = false
publicbool$skipOnInsert = false
publicbool$skipOnUpdate = false
publicstring$type = "string"

Methods

Public · 1

__construct()

public function __construct(
    string|null $column = null,
    string $type = "string",
    int|null $length = null,
    bool $nullable = false,
    bool $skipOnInsert = false,
    bool $skipOnUpdate = false,
    bool $allowEmptyString = false,
    mixed $defaultValue = null
);

Annotations\Models\MetaData\Identity

Class Source on GitHub

Marks a property as the identity column. It is the attribute form of @Identity.

  • Phalcon\Annotations\Models\MetaData\Identity

Uses Attribute

Annotations\Models\MetaData\Primary

Class Source on GitHub

Marks a property as part of the primary key. It is the attribute form of @Primary.

  • Phalcon\Annotations\Models\MetaData\Primary

Uses Attribute

Annotations\Models\MetaData\Source

Class Source on GitHub

Names the table of a model. No framework code reads it today.

  • Phalcon\Annotations\Models\MetaData\Source

Uses Attribute

Method Summary

Properties

publicstring$table

Methods

Public · 1

__construct()

public function __construct( string $table );

Annotations\Reader

Class Source on GitHub

Parses docblocks returning an array with the found annotations

Uses Phalcon\Annotations\Docblock\Exception · Phalcon\Annotations\Docblock\Parser\Parser · Phalcon\Contracts\Annotations\AnnotationsTypes · ReflectionClass · ReflectionClassConstant

Method Summary

Methods

Public · 2

parse()

public function parse( string $className ): array;

Reads annotations from the class docblocks, its methods and/or properties

parseDocBlock()

public static function parseDocBlock(
    string $docBlock,
    mixed $file = null,
    mixed $line = null
): array|false;

Parses a raw doc block returning the annotations found

Annotations\ReaderInterface

Interface Source on GitHub

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.

  • Phalcon\Annotations\ReaderInterface

Uses Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Methods

Public · 1

parse()

public function parse( string $className ): array;

Reads annotations from the class, its constants, properties and methods

Annotations\Reflection

Class Source on GitHub

Allows to manipulate the annotations reflection in an OO manner

use Phalcon\Annotations\Reader;
use Phalcon\Annotations\Reflection;

// Parse the annotations in a class
$reader = new Reader();
$parsing = $reader->parse("MyComponent");

// Create the reflection
$reflection = new Reflection($parsing);

// Get the annotations in the class docblock
$classAnnotations = $reflection->getClassAnnotations();
  • Phalcon\Annotations\Reflection

Uses Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

protectedCollection|null$classAnnotations = null
protectedarray$constantAnnotations = []
protectedarray$methodAnnotations = []
protectedarray$propertyAnnotations = []
protectedarray$reflectionData = []

Methods

Public · 6

__construct()

public function __construct( array $reflectionData = [] );

getClassAnnotations()

public function getClassAnnotations(): Collection|null;

Returns the annotations found in the class docblock

getConstantsAnnotations()

public function getConstantsAnnotations(): array;

Returns the annotations found in the constants’ docblocks

getMethodsAnnotations()

public function getMethodsAnnotations(): array;

Returns the annotations found in the methods’ docblocks

getPropertiesAnnotations()

public function getPropertiesAnnotations(): array;

Returns the annotations found in the properties’ docblocks

getReflectionData()

public function getReflectionData(): array;

Returns the raw parsing intermediate definitions used to construct the reflection

Annotations\Router\Connect

Class Source on GitHub

Marks a method as a CONNECT route. It is the attribute form of @Connect.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Delete

Class Source on GitHub

Marks a method as a DELETE route. It is the attribute form of @Delete.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Get

Class Source on GitHub

Marks a method as a GET route. It is the attribute form of @Get.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Head

Class Source on GitHub

Marks a method as a HEAD route. It is the attribute form of @Head.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Options

Class Source on GitHub

Marks a method as a OPTIONS route. It is the attribute form of @Options.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Patch

Class Source on GitHub

Marks a method as a PATCH route. It is the attribute form of @Patch.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Post

Class Source on GitHub

Marks a method as a POST route. It is the attribute form of @Post.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Purge

Class Source on GitHub

Marks a method as a PURGE route. It is the attribute form of @Purge.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Put

Class Source on GitHub

Marks a method as a PUT route. It is the attribute form of @Put.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\Route

Class Source on GitHub

Marks a method as a route. It is the attribute form of @Route.

The annotations service never makes an instance of this class. It reads the arguments with ReflectionAttribute::getArguments(). The class gives the name, the targets and the signature that an IDE and a static analyzer read.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes

Method Summary

Properties

publicarray|string|null$beforeMatch = null
publicarray$converters = []
publicarray|string|null$methods = null
publicstring|null$name = null
publicarray$paths = []
publicstring$route

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    array|string|null $methods = null,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);

Annotations\Router\RoutePrefix

Class Source on GitHub

Sets the prefix of every route of a controller. It is the attribute form of @RoutePrefix.

  • Phalcon\Annotations\Router\RoutePrefix

Uses Attribute

Method Summary

Properties

publicstring$prefix

Methods

Public · 1

__construct()

public function __construct( string $prefix );

Annotations\Router\Trace

Class Source on GitHub

Marks a method as a TRACE route. It is the attribute form of @Trace.

Uses Attribute · Phalcon\Contracts\Annotations\AnnotationsTypes · Phalcon\Http\Message\RequestMethodInterface

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $route,
    string|null $name = null,
    array $paths = [],
    array $converters = [],
    array|string|null $beforeMatch = null
);
Navigation

Type to search…

↑↓ navigate↵ selectEsc close