Skip to content

Phalcon container

NOTE

All classes are prefixed with Phalcon

Container\Container

Class Source on GitHub

Uses Closure · Phalcon\Container\Definition\Processor\ClosureProcessor · Phalcon\Container\Definition\Processor\ObjectProcessor · Phalcon\Container\Definition\Processor\Processor · Phalcon\Container\Definition\Processor\StringProcessor · Phalcon\Container\Definition\ServiceDefinition · Phalcon\Container\Definition\ServiceLifetime · Phalcon\Container\Exceptions\CannotExtendResolved · Phalcon\Container\Exceptions\CircularAliasFound · Phalcon\Container\Exceptions\InstanceNotFound · Phalcon\Container\Exceptions\NoProcessorFound · Phalcon\Container\Exceptions\ParameterNotFound · Phalcon\Container\Exceptions\ServiceNotFound · Phalcon\Container\Exceptions\ServiceNotRegistered · Phalcon\Container\Resolver\Lazy\Lazy · Phalcon\Container\Resolver\Resolver · Phalcon\Contracts\Container\Service\Collection · Phalcon\Di\InjectionAwareInterface · ReflectionException

Method Summary

public __construct() public ServiceDefinition bind(string $interfaceName,string $concrete) Bind an interface to a concrete class public Closure callableGet( string $name ) Resolve to a closure on a get() public Closure callableNew( string $name ) Resolve to a closure on a new() public void extend(string $name,callable $callableObject) Extends the definition public mixed get( string $name ) Resolve and return an element registerd in the container public string getAlias( string $name ) Return an alias public array getByTag( string $tag ) Return services by tag public ServiceDefinition getDefinition( string $name ) Return the service definition public object getInstance( string $name ) Return a stored instance public mixed getParameter( string $name ) Return a parameter public Resolver getResolver() Return the resolver public object getService( string $serviceName ) Resolve an return a service public bool has( string $name ) Does the container have a particular service public bool hasAlias( string $name ) Does the service have an alias public bool hasDefinition( string $name ) Does the service have a definition public bool hasInstance( string $name ) Does the service have an instance public bool hasParameter( string $name ) Does the service have a parameter public bool hasService( string $serviceName ) Does the container have a particular service public bool isAutowireEnabled() Is AutoWiring enabled public mixed new( string $name ) Resolve and return a new service public ServiceDefinition newDefinition( string $name ) Return a new service definition public ServiceDefinition set(string $name,mixed $definition) Set a service public static setAlias(string $name,string $alias) Set an alias public static setAutowire( bool $enabled ) Set AutoWire public static setDefinition(string $name,ServiceDefinition $definition) Set a definition public static setInstance(string $name,object $instance,string $lifetime) Set an instance public static setParameter(string $name,mixed $value) Set a parameter public void setTag(string $tag,string $serviceName) Register a tag with a service public void unsetAlias( string $name ) Remove an alias public void unsetDefinition( string $name ) Remove a definition public void unsetInstance( string $name ) Remove an instance public void unsetInstances( string $lifetime ) Remove instances based on lifetime public void unsetParameter( string $name ) Remove a parameter

Properties

protected array<string, string> $aliases = []
protected bool $autowire = true
protected array<string, string> $instanceLifetimes = []
protected array<string, object> $instances = []
protected array<string, mixed> $parameters = []
protected array<string, Processor> $processors = []
protected Resolver $resolver
protected array<string, ServiceDefinition> $services = []
protected array<string, list<string>> $tags = []

Methods

Public · 34

__construct()

public function __construct();

bind()

public function bind(
    string $interfaceName,
    string $concrete
): ServiceDefinition;

Bind an interface to a concrete class

callableGet()

public function callableGet( string $name ): Closure;

Resolve to a closure on a get()

callableNew()

public function callableNew( string $name ): Closure;

Resolve to a closure on a new()

extend()

public function extend(
    string $name,
    callable $callableObject
): void;

Extends the definition

get()

public function get( string $name ): mixed;

Resolve and return an element registerd in the container

getAlias()

public function getAlias( string $name ): string;

Return an alias

getByTag()

public function getByTag( string $tag ): array;

Return services by tag

getDefinition()

public function getDefinition( string $name ): ServiceDefinition;

Return the service definition

getInstance()

public function getInstance( string $name ): object;

Return a stored instance

getParameter()

public function getParameter( string $name ): mixed;

Return a parameter

getResolver()

public function getResolver(): Resolver;

Return the resolver

getService()

public function getService( string $serviceName ): object;

Resolve an return a service

has()

public function has( string $name ): bool;

Does the container have a particular service

hasAlias()

public function hasAlias( string $name ): bool;

Does the service have an alias

hasDefinition()

public function hasDefinition( string $name ): bool;

Does the service have a definition

hasInstance()

public function hasInstance( string $name ): bool;

Does the service have an instance

hasParameter()

public function hasParameter( string $name ): bool;

Does the service have a parameter

hasService()

public function hasService( string $serviceName ): bool;

Does the container have a particular service

isAutowireEnabled()

public function isAutowireEnabled(): bool;

Is AutoWiring enabled

new()

public function new( string $name ): mixed;

Resolve and return a new service

newDefinition()

public function newDefinition( string $name ): ServiceDefinition;

Return a new service definition

set()

public function set(
    string $name,
    mixed $definition
): ServiceDefinition;

Set a service

setAlias()

public function setAlias(
    string $name,
    string $alias
): static;

Set an alias

setAutowire()

public function setAutowire( bool $enabled ): static;

Set AutoWire

setDefinition()

public function setDefinition(
    string $name,
    ServiceDefinition $definition
): static;

Set a definition

setInstance()

public function setInstance(
    string $name,
    object $instance,
    string $lifetime
): static;

Set an instance

setParameter()

public function setParameter(
    string $name,
    mixed $value
): static;

Set a parameter

setTag()

public function setTag(
    string $tag,
    string $serviceName
): void;

Register a tag with a service

unsetAlias()

public function unsetAlias( string $name ): void;

Remove an alias

unsetDefinition()

public function unsetDefinition( string $name ): void;

Remove a definition

unsetInstance()

public function unsetInstance( string $name ): void;

Remove an instance

unsetInstances()

public function unsetInstances( string $lifetime ): void;

Remove instances based on lifetime

unsetParameter()

public function unsetParameter( string $name ): void;

Remove a parameter

Container\ContainerFactory

Class Source on GitHub

Uses Phalcon\Contracts\Container\Ioc\IocContainerFactory · Phalcon\Contracts\Container\Service\Provider

Method Summary

Properties

protected array<array-key, Provider> $providers = []

Methods

Public · 2

addProvider()

public function addProvider( Provider $provider ): static;

Adds a provider

newContainer()

public function newContainer(): Container;

Returns a new container

Container\Definition\DefinitionType

Class Source on GitHub

  • Phalcon\Container\Definition\DefinitionType

Constants

string CLOSURE_TYPE = "closure"
string OBJECT_TYPE = "object"
string PARAMETER_TYPE = "parameter"
string STRING_TYPE = "string"

Container\Definition\Processor\ClosureProcessor

Class Source on GitHub

Uses Closure · Phalcon\Container\Definition\DefinitionType · Phalcon\Container\Definition\ServiceDefinition

Method Summary

Methods

Public · 2

canProcess()

public function canProcess( mixed $definition ): bool;

Wheteher the definition is a Closure

process()

public function process(
    string $name,
    mixed $definition,
    object $container
): ServiceDefinition;

Process the Closure

Container\Definition\Processor\ObjectProcessor

Class Source on GitHub

Uses Closure · Phalcon\Container\Definition\DefinitionType · Phalcon\Container\Definition\ServiceDefinition

Method Summary

Methods

Public · 2

canProcess()

public function canProcess( mixed $definition ): bool;

Whether the definition is an Object (not Closure)

process()

public function process(
    string $name,
    mixed $definition,
    object $container
): ServiceDefinition;

Process the Object

Container\Definition\Processor\ParameterProcessor

Class Source on GitHub

Uses Closure · Phalcon\Container\Definition\DefinitionType · Phalcon\Container\Definition\ServiceDefinition

Method Summary

Methods

Public · 2

canProcess()

public function canProcess( mixed $definition ): bool;

Whetehr the definition is a parameter

process()

public function process(
    string $name,
    mixed $definition,
    object $container
): ServiceDefinition;

Process the parameter

Container\Definition\Processor\Processor

Interface Source on GitHub

  • Phalcon\Container\Definition\Processor\Processor

Uses Phalcon\Container\Definition\ServiceDefinition

Method Summary

Methods

Public · 2

canProcess()

public function canProcess( mixed $definition ): bool;

Can this definition be processed?

process()

public function process(
    string $name,
    mixed $definition,
    object $container
): ServiceDefinition;

Process the definition

Container\Definition\Processor\StringProcessor

Class Source on GitHub

Uses Phalcon\Container\Definition\DefinitionType · Phalcon\Container\Definition\ServiceDefinition

Method Summary

Methods

Public · 2

canProcess()

public function canProcess( mixed $definition ): bool;

Whether the definition is a class string

process()

public function process(
    string $name,
    mixed $definition,
    object $container
): ServiceDefinition;

Process the class string

Container\Definition\ServiceDefinition

Class Source on GitHub

  • Phalcon\Container\Definition\ServiceDefinition

Uses Phalcon\Container\Exceptions\FrozenDefinition · Phalcon\Container\Exceptions\InvalidExtender · Phalcon\Container\Exceptions\NoClassSet · Phalcon\Container\Exceptions\NoFactorySet · ReflectionClass · ReflectionException

Method Summary

public __construct(string $serviceName,string $type,mixed $raw = null) public static addExtender( callable $extender ) Adds an extender public static addTag( string $tag ) Adds a tag public object buildService( object $container ) Builds a service and returns the instance back public void freeze( object $container ) Freezes the container public array getArguments() Returns the arguments public string getClass() Returns the class public array getConstructorArgs() Returns the constructor arguments public array getExtenders() Returns the extenders public callable getFactory() Returns the factory public string getLifetime() Returns the lifetime public string getServiceName() Returns the name of the service public array getTags() Returns the tags public string getType() Returns the type public bool hasClass() Does it have a class public bool hasExtenders() Do we have extenders public bool hasFactory() Does it have a factory public bool isCacheable() Is it cacheable public bool isFrozen() Is it frozen public static setArgument(mixed $param,mixed $value) Set an argument public static setClass( string $className ) Set a class public static setContainer( object $container ) Set the container public static setExtenders( array $extenders ) Set extenders public static setFactory( callable $factory ) Set a factory public static setIsCacheable( bool $isCacheable ) Set cachable public static setLifetime( string $lifetime ) Set lifetime public static unsetClass() Unset class public static unsetExtenders() Unset extenders public static unsetFactory() Unset the factory protected void checkFrozen() Check if frozen

Properties

protected array $arguments = []
protected string | null $className = null
protected array $constructorArgs = []
protected object | null $container = null
protected array<array-key, callable> $extenders = []
protected callable | null $factory = null
protected bool $frozen = false
protected bool $isCacheable = false
protected string $lifetime = ServiceLifetime::SCOPED
protected mixed $raw = null
protected mixed $serviceName
protected array $tags = []
protected mixed $type

Methods

Public · 29

__construct()

public function __construct(
    string $serviceName,
    string $type,
    mixed $raw = null
);

addExtender()

public function addExtender( callable $extender ): static;

Adds an extender

addTag()

public function addTag( string $tag ): static;

Adds a tag

buildService()

public function buildService( object $container ): object;

Builds a service and returns the instance back

freeze()

public function freeze( object $container ): void;

Freezes the container

getArguments()

public function getArguments(): array;

Returns the arguments

getClass()

public function getClass(): string;

Returns the class

getConstructorArgs()

public function getConstructorArgs(): array;

Returns the constructor arguments

getExtenders()

public function getExtenders(): array;

Returns the extenders

getFactory()

public function getFactory(): callable;

Returns the factory

getLifetime()

public function getLifetime(): string;

Returns the lifetime

getServiceName()

public function getServiceName(): string;

Returns the name of the service

getTags()

public function getTags(): array;

Returns the tags

getType()

public function getType(): string;

Returns the type

hasClass()

public function hasClass(): bool;

Does it have a class

hasExtenders()

public function hasExtenders(): bool;

Do we have extenders

hasFactory()

public function hasFactory(): bool;

Does it have a factory

isCacheable()

public function isCacheable(): bool;

Is it cacheable

isFrozen()

public function isFrozen(): bool;

Is it frozen

setArgument()

public function setArgument(
    mixed $param,
    mixed $value
): static;

Set an argument

setClass()

public function setClass( string $className ): static;

Set a class

setContainer()

public function setContainer( object $container ): static;

Set the container

setExtenders()

public function setExtenders( array $extenders ): static;

Set extenders

setFactory()

public function setFactory( callable $factory ): static;

Set a factory

setIsCacheable()

public function setIsCacheable( bool $isCacheable ): static;

Set cachable

setLifetime()

public function setLifetime( string $lifetime ): static;

Set lifetime

unsetClass()

public function unsetClass(): static;

Unset class

unsetExtenders()

public function unsetExtenders(): static;

Unset extenders

unsetFactory()

public function unsetFactory(): static;

Unset the factory

Protected · 1

checkFrozen()

protected function checkFrozen(): void;

Check if frozen

Container\Definition\ServiceLifetime

Class Source on GitHub

  • Phalcon\Container\Definition\ServiceLifetime

Constants

string SCOPED = "SCOPED"
string SINGLETON = "SINGLETON"
string TRANSIENT = "TRANSIENT"

Container\Exceptions\CannotExtendResolved

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Cannot extend a resolved service

Container\Exceptions\CannotResolveParameter

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $param,
    string $className
);

Cannot resolve a parameter

Container\Exceptions\CircularAliasFound

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Circular Alias found

Container\Exceptions\ContainerThrowable

Interface Source on GitHub

Uses Phalcon\Contracts\Container\Ioc\IocThrowable · Phalcon\Contracts\Container\Resolver\ResolverThrowable · Phalcon\Contracts\Container\Service\Throwable

Container\Exceptions\EnvNotDefined

Final Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $varname );

Container\Exceptions\Exception

Class Source on GitHub

Uses Exception

Container\Exceptions\FrozenDefinition

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Definition is frozen

Container\Exceptions\InstanceNotFound

Final Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Container\Exceptions\InvalidExtender

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct(
    string $service,
    string $key
);

Invalid extender (not callable)

Container\Exceptions\NoClassSet

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

No set for service

Container\Exceptions\NoFactorySet

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

No factory for service

Container\Exceptions\NoProcessorFound

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct();

No processor found

Container\Exceptions\ParameterNotFound

Final Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Container\Exceptions\ServiceNotFound

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Service not found

Container\Exceptions\ServiceNotRegistered

Class Source on GitHub

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Service not registered

Container\Provider\Cli

Class Source on GitHub

Uses Phalcon\Auth\Access\AccessLocator · Phalcon\Contracts\Container\Service\Collection · Phalcon\Contracts\Container\Service\Provider · Phalcon\Filter\Filter · Phalcon\Filter\FilterFactory

Method Summary

Methods

Public · 1

provide()

public function provide( Collection $services ): void;

Provider for commonly used CLI applications

Container\Provider\Web

Class Source on GitHub

Uses Phalcon\Auth\Access\AccessLocator · Phalcon\Contracts\Container\Service\Collection · Phalcon\Contracts\Container\Service\Provider · Phalcon\Filter\Filter · Phalcon\Filter\FilterFactory

Method Summary

Methods

Public · 1

provide()

public function provide( Collection $services ): void;

Provider for commonly used Web applications

Container\Resolver\Lazy\ArrayValues

Class Source on GitHub

Uses ArrayAccess · ArrayIterator · Countable · IteratorAggregate

Method Summary

Properties

protected array<array-key, mixed> $values = []

Methods

Public · 9

__construct()

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

count()

public function count(): int;

getIterator()

public function getIterator(): ArrayIterator;

merge()

public function merge( mixed $values ): void;

offsetExists()

public function offsetExists( mixed $offset ): bool;

offsetGet()

public function offsetGet( mixed $offset ): mixed;

offsetSet()

public function offsetSet(
    mixed $offset,
    mixed $value
): void;

offsetUnset()

public function offsetUnset( mixed $offset ): void;

resolve()

public function resolve( object $ioc ): array;

Resolve to an array, where each element has itself been lazy-resolved.

Protected · 2

resolveValue()

protected function resolveValue(
    object $ioc,
    mixed $value
): mixed;

resolveValues()

protected function resolveValues(
    object $ioc,
    array $values
): array;

Container\Resolver\Lazy\Call

Class Source on GitHub

Method Summary

Properties

protected mixed $callableObject

Methods

Public · 2

__construct()

public function __construct( callable $callableObject );

resolve()

public function resolve( object $ioc ): mixed;

Resolve the callable

Container\Resolver\Lazy\CallableGet

Class Source on GitHub

Method Summary

Properties

protected string|Lazy $id

Methods

Public · 2

__construct()

public function __construct( mixed $id );

resolve()

public function resolve( object $ioc ): mixed;

Resolve to a closure on a get()

Container\Resolver\Lazy\CallableNew

Class Source on GitHub

Method Summary

Properties

protected string|Lazy $id

Methods

Public · 2

__construct()

public function __construct( mixed $id );

resolve()

public function resolve( object $ioc ): mixed;

Resolve to a closure on a new()

Container\Resolver\Lazy\CsEnv

Class Source on GitHub

Uses Phalcon\Container\Exceptions\EnvNotDefined

Method Summary

Methods

Public · 1

resolve()

public function resolve( object $ioc ): array;

Resolve the getEnv() from keys as a comma separated list

Container\Resolver\Lazy\Env

Class Source on GitHub

Uses Phalcon\Container\Exceptions\EnvNotDefined

Method Summary

Properties

protected string $varname
protected string|null $vartype = null

Methods

Public · 2

__construct()

public function __construct(
    string $varname,
    string $vartype = null
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve an environment variable

Protected · 2

cast()

protected function cast( mixed $value ): mixed;

Cast a value to the defined type (if any)

getEnv()

protected function getEnv(): string;

Return the env value

Container\Resolver\Lazy\EnvDefault

Class Source on GitHub

Uses Phalcon\Container\Exceptions\EnvNotDefined

Method Summary

Methods

Public · 2

__construct()

public function __construct(
    string $varname,
    mixed $defaultValue,
    string $vartype = null
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve an environment variable, returning the default if not defined

Container\Resolver\Lazy\FunctionCall

Class Source on GitHub

Method Summary

Properties

protected array<array-key, mixed> $arguments
protected string $functionName

Methods

Public · 2

__construct()

public function __construct(
    string $functionName,
    array $arguments
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve a function

Container\Resolver\Lazy\Get

Class Source on GitHub

Method Summary

Properties

protected string|Lazy $id

Methods

Public · 2

__construct()

public function __construct( mixed $id );

resolve()

public function resolve( object $ioc ): mixed;

Resolve a shared instance

Container\Resolver\Lazy\GetCall

Class Source on GitHub

Method Summary

Properties

protected array<array-key, mixed> $arguments
protected string|Lazy $id
protected string $method

Methods

Public · 2

__construct()

public function __construct(
    mixed $id,
    string $method,
    array $arguments
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve a shared instance method call

Container\Resolver\Lazy\Lazy

Abstract Source on GitHub

Uses Phalcon\Contracts\Container\Resolver\Resolvable

Method Summary

Methods

Public · 2

__invoke()

public function __invoke( object $ioc ): mixed;

resolve()

abstract public function resolve( object $ioc ): mixed;
Protected · 2

resolveArgument()

protected function resolveArgument(
    object $ioc,
    mixed $argument
): mixed;

resolveArguments()

protected function resolveArguments(
    object $ioc,
    array $arguments
): array;

Container\Resolver\Lazy\LazyFactory

Class Source on GitHub

  • Phalcon\Container\Resolver\Lazy\LazyFactory

Method Summary

Methods

Public · 13

arrayValues()

public static function arrayValues( array $values ): ArrayValues;

call()

public static function call( callable $callableObject ): Call;

callableGet()

public static function callableGet( string $id ): CallableGet;

callableNew()

public static function callableNew( string $id ): CallableNew;

csEnv()

public static function csEnv(
    string $name,
    string $type = null
): CsEnv;

env()

public static function env(
    string $name,
    string $type = null
): Env;

envDefault()

public static function envDefault(
    string $name,
    mixed $defaultValue,
    string $type = null
): EnvDefault;

functionCall()

public static function functionCall(
    string $functionName,
    array $args
): FunctionCall;

get()

public static function get( string $id ): Get;

getCall()

public static function getCall(
    string $id,
    string $method,
    array $args
): GetCall;

newCall()

public static function newCall(
    string $id,
    string $method,
    array $args
): NewCall;

newInstance()

public static function newInstance( string $id ): NewInstance;

staticCall()

public static function staticCall(
    string $className,
    string $method,
    array $args
): StaticCall;

Container\Resolver\Lazy\NewCall

Class Source on GitHub

Method Summary

Properties

protected array<array-key, mixed> $arguments
protected string|Lazy $id
protected string $method

Methods

Public · 2

__construct()

public function __construct(
    mixed $id,
    string $method,
    array $arguments
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve a new instance method call

Container\Resolver\Lazy\NewInstance

Class Source on GitHub

Method Summary

Properties

protected string|Lazy $id

Methods

Public · 2

__construct()

public function __construct( mixed $id );

resolve()

public function resolve( object $ioc ): mixed;

Resolve a new instance

Container\Resolver\Lazy\StaticCall

Class Source on GitHub

Method Summary

Properties

protected array<array-key, mixed> $arguments
protected string|Lazy $className
protected string $method

Methods

Public · 2

__construct()

public function __construct(
    mixed $className,
    string $method,
    array $arguments
);

resolve()

public function resolve( object $ioc ): mixed;

Resolve a static method call

Container\Resolver\Resolver

Class Source on GitHub

Uses Closure · Phalcon\Container\Exceptions\CannotResolveParameter · Phalcon\Container\Resolver\Lazy\Lazy · Phalcon\Contracts\Container\Resolver\ResolverService · ReflectionClass · ReflectionException · ReflectionFunction · ReflectionMethod · ReflectionNamedType · ReflectionParameter · ReflectionType

Method Summary

Methods

Public · 7

isResolvableClass()

public function isResolvableClass( string $className ): bool;

Is this a resolvable class?

resolveCall()

public function resolveCall(
    object $ioc,
    callable $callableObject,
    array $arguments
): mixed;

Resolve a call

resolveClass()

public function resolveClass(
    object $ioc,
    string $className,
    array $arguments
): object;

Resolve a class

resolveMethod()

public function resolveMethod(
    object $ioc,
    ReflectionMethod $method,
    object $instance
): void;

Resolve a method

resolveParameter()

public function resolveParameter(
    object $ioc,
    ReflectionParameter $parameter
): mixed;

Resolve parameters

resolveParameters()

public function resolveParameters(
    object $ioc,
    array $parameters,
    array $arguments
): array;

resolveType()

public function resolveType(
    object $ioc,
    mixed $type
): mixed;

type is ReflectionType