Skip to content

Phalcon annotations

NOTE

All classes are prefixed with Phalcon

Annotations\Adapter\AbstractAdapter

Abstract Source on GitHub

This is the base class for Phalcon\Annotations adapters

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

Method Summary

Properties

protected array $annotations = []
protected int $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.
protected Reader $reader

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

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

Method Summary

Properties

protected string $prefix = ""
protected int $ttl = 172800

Methods

Public · 3

__construct()

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

Phalcon\Annotations\Adapter\Apcu constructor

read()

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

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

Method Summary

Properties

protected mixed $data

Methods

Public · 3

__construct()

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

read()

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

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\Exception · Phalcon\Annotations\Exceptions\AnnotationsDirectoryNotWritable · Phalcon\Annotations\Exceptions\CannotReadAnnotationData · Phalcon\Annotations\Reflection · RuntimeException

Method Summary

Properties

protected string $annotationsDir = "./"

Methods

Public · 3

__construct()

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

Phalcon\Annotations\Adapter\Stream constructor

read()

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

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\Exceptions\UnknownAnnotationExpression

Method Summary

Properties

protected array $arguments = [] Annotation Arguments
protected array $exprArguments = [] Annotation ExprArguments
protected string|null $name Annotation Name

Methods

Public · 10

__construct()

public function __construct( array $reflectionData );

Phalcon\Annotations\Annotation constructor

getArgument()

public function getArgument( mixed $position ): mixed|null;

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(): null|string;

Returns the annotation's name

getNamedArgument()

public function getNamedArgument( string $name ): mixed|null;

Returns a named argument

getNamedParameter()

public function getNamedParameter( string $name ): mixed;

Returns a named parameter

hasArgument()

public function hasArgument( mixed $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\Factory\AbstractFactory · Phalcon\Support\Helper\Arr\Get

Method Summary

Methods

Public · 3

__construct()

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

AdapterFactory constructor.

load()

public function load( mixed $config ): mixed;

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\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");
  • Phalcon\Annotations\Collection — implements Iterator, Countable

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

Method Summary

Properties

protected array $annotations
protected int $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 ): Annotation[];

Returns all the annotations that match a name

getAnnotations()

public function getAnnotations(): Annotation[];

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\Reader

Class Source on GitHub

Parses docblocks returning an array with the found annotations

Uses ReflectionClass

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;

Parses a raw doc block returning the annotations found

Annotations\ReaderInterface

Interface Source on GitHub

Parses docblocks returning an array with the found annotations

  • Phalcon\Annotations\ReaderInterface

Method Summary

Methods

Public · 2

parse()

public function parse( string $className ): array;

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

parseDocBlock()

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

Parses a raw docblock returning the annotations found

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

Method Summary

Properties

protected Collection|null $classAnnotations = null
protected array $constantAnnotations = []
protected array $methodAnnotations = []
protected array $propertyAnnotations = []
protected array $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(): Collection[];

Returns the annotations found in the constants' docblocks

getMethodsAnnotations()

public function getMethodsAnnotations(): Collection[];

Returns the annotations found in the methods' docblocks

getPropertiesAnnotations()

public function getPropertiesAnnotations(): Collection[];

Returns the annotations found in the properties' docblocks

getReflectionData()

public function getReflectionData(): array;

Returns the raw parsing intermediate definitions used to construct the reflection