Skip to content

Abstract Class Phalcon\Annotations\Adapter\AbstractAdapter

Source on GitHub

| Namespace | Phalcon\Annotations\Adapter | | Uses | Phalcon\Annotations\Reader, Phalcon\Annotations\Exception, Phalcon\Annotations\Collection, Phalcon\Annotations\Reflection, Phalcon\Annotations\ReaderInterface | | Implements | AdapterInterface |

This is the base class for Phalcon\Annotations adapters

Properties

/**
 * @var array
 */
protected annotations;

/**
 * @var Reader
 */
protected reader;

Methods

public function get( mixed $className ): Reflection;
Parses or retrieves all the annotations found in a class

public function getMethod( string $className, string $methodName ): Collection;
Returns the annotations found in a specific method

public function getMethods( string $className ): array;
Returns the annotations found in all the class' methods

public function getProperties( string $className ): array;
Returns the annotations found in all the class' methods

public function getProperty( string $className, string $propertyName ): Collection;
Returns the annotations found in a specific property

public function getReader(): ReaderInterface;
Returns the annotation reader

public function setReader( ReaderInterface $reader );
Sets the annotations parser

Interface Phalcon\Annotations\Adapter\AdapterInterface

Source on GitHub

| Namespace | Phalcon\Annotations\Adapter | | Uses | Phalcon\Annotations\Reflection, Phalcon\Annotations\Collection, Phalcon\Annotations\ReaderInterface |

This interface must be implemented by adapters in Phalcon\Annotations

Methods

public function get( string $className ): Reflection;
Parses or retrieves all the annotations found in a class

public function getMethod( string $className, string $methodName ): Collection;
Returns the annotations found in a specific method

public function getMethods( string $className ): array;
Returns the annotations found in all the class' methods

public function getProperties( string $className ): array;
Returns the annotations found in all the class' methods

public function getProperty( string $className, string $propertyName ): Collection;
Returns the annotations found in a specific property

public function getReader(): ReaderInterface;
Returns the annotation reader

public function setReader( ReaderInterface $reader );
Sets the annotations parser

Class Phalcon\Annotations\Adapter\Apcu

Source on GitHub

| Namespace | Phalcon\Annotations\Adapter | | Uses | Phalcon\Annotations\Reflection | | Extends | AbstractAdapter |

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

use Phalcon\Annotations\Adapter\Apcu;

$annotations = new Apcu();

Properties

/**
 * @var string
 */
protected prefix = ;

/**
 * @var int
 */
protected ttl = 172800;

Methods

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

public function read( string $key ): Reflection | bool;
Reads parsed annotations from APCu

public function write( string $key, Reflection $data ): bool;
Writes parsed annotations to APCu

Class Phalcon\Annotations\Adapter\Memory

Source on GitHub

| Namespace | Phalcon\Annotations\Adapter | | Uses | Phalcon\Annotations\Reflection | | Extends | AbstractAdapter |

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

Properties

/**
 * @var mixed
 */
protected data;

Methods

public function read( string $key ): Reflection | bool;
Reads parsed annotations from memory

public function write( string $key, Reflection $data ): void;
Writes parsed annotations to memory

Class Phalcon\Annotations\Adapter\Stream

Source on GitHub

| Namespace | Phalcon\Annotations\Adapter | | Uses | Phalcon\Annotations\Reflection, Phalcon\Annotations\Exception, RuntimeException | | Extends | AbstractAdapter |

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

use Phalcon\Annotations\Adapter\Stream;

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

Properties

/**
 * @var string
 */
protected annotationsDir = ./;

Methods

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

public function read( string $key ): Reflection | bool | int;
Reads parsed annotations from files

public function write( string $key, Reflection $data ): void;
Writes parsed annotations to files

Class Phalcon\Annotations\Annotation

Source on GitHub

| Namespace | Phalcon\Annotations |

Represents a single annotation in an annotations collection

Properties

/**
 * Annotation Arguments
 *
 * @var array
 */
protected arguments;

/**
 * Annotation ExprArguments
 *
 * @var array
 */
protected exprArguments;

/**
 * Annotation Name
 *
 * @var string|null
 */
protected name;

Methods

public function __construct( array $reflectionData );
Phalcon\Annotations\Annotation constructor

public function getArgument( mixed $position ): mixed | null;
Returns an argument in a specific position

public function getArguments(): array;
Returns the expression arguments

public function getExprArguments(): array;
Returns the expression arguments without resolving

public function getExpression( array $expr ): mixed;
Resolves an annotation expression

public function getName(): null | string;
Returns the annotation's name

public function getNamedArgument( string $name ): mixed | null;
Returns a named argument

public function getNamedParameter( string $name ): mixed;
Returns a named parameter

public function hasArgument( mixed $position ): bool;
Returns an argument in a specific position

public function numberArguments(): int;
Returns the number of arguments that the annotation has

Class Phalcon\Annotations\AnnotationsFactory

Source on GitHub

| Namespace | Phalcon\Annotations | | Uses | Phalcon\Annotations\Adapter\AdapterInterface, Phalcon\Factory\AbstractFactory, Phalcon\Helper\Arr | | Extends | AbstractFactory |

Factory to create annotations components

Methods

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

public function load( mixed $config ): mixed;

public function newInstance( string $name, array $options = [] ): AdapterInterface;
Create a new instance of the adapter

protected function getAdapters(): array;
The available adapters

Class Phalcon\Annotations\Collection

Source on GitHub

| Namespace | Phalcon\Annotations | | Uses | Countable, Iterator | | Implements | Iterator, Countable |

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");

Properties

/**
 * @var array
 */
protected annotations;

/**
 * @var int
 */
protected position = 0;

Methods

public function __construct( array $reflectionData = [] );
Phalcon\Annotations\Collection constructor

public function count(): int;
Returns the number of annotations in the collection

public function current(): Annotation | bool;
Returns the current annotation in the iterator

public function get( string $name ): Annotation;
Returns the first annotation that match a name

public function getAll( string $name ): Annotation[];
Returns all the annotations that match a name

public function getAnnotations(): Annotation[];
Returns the internal annotations as an array

public function has( string $name ): bool;
Check if an annotation exists in a collection

public function key(): int;
Returns the current position/key in the iterator

public function next(): void;
Moves the internal iteration pointer to the next position

public function rewind(): void;
Rewinds the internal iterator

public function valid(): bool;
Check if the current annotation in the iterator is valid

Class Phalcon\Annotations\Exception

Source on GitHub

| Namespace | Phalcon\Annotations | | Extends | \Phalcon\Exception |

Class for exceptions thrown by Phalcon\Annotations

Class Phalcon\Annotations\Reader

Source on GitHub

| Namespace | Phalcon\Annotations | | Uses | ReflectionClass | | Implements | ReaderInterface |

Parses docblocks returning an array with the found annotations

Methods

public function parse( string $className ): array;
Reads annotations from the class docblocks, its methods and/or properties

public static function parseDocBlock( string $docBlock, mixed $file = null, mixed $line = null ): array;
Parses a raw doc block returning the annotations found

Interface Phalcon\Annotations\ReaderInterface

Source on GitHub

| Namespace | Phalcon\Annotations |

Parses docblocks returning an array with the found annotations

Methods

public function parse( string $className ): array;
Reads annotations from the class docblocks, its methods and/or properties

public static function parseDocBlock( string $docBlock, mixed $file = null, mixed $line = null ): array;
Parses a raw docblock returning the annotations found

Class Phalcon\Annotations\Reflection

Source on GitHub

| Namespace | Phalcon\Annotations |

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

Properties

//
protected classAnnotations;

//
protected methodAnnotations;

//
protected propertyAnnotations;

/**
 * @var array
 */
protected reflectionData;

Methods

public function __construct( array $reflectionData = [] );
Phalcon\Annotations\Reflection constructor

public function getClassAnnotations(): Collection | bool;
Returns the annotations found in the class docblock

public function getMethodsAnnotations(): Collection[] | bool;
Returns the annotations found in the methods' docblocks

public function getPropertiesAnnotations(): Collection[] | bool;
Returns the annotations found in the properties' docblocks

public function getReflectionData(): array;
Returns the raw parsing intermediate definitions used to construct the reflection