Phalcon di
NOTE
All classes are prefixed with Phalcon
Di\AbstractInjectionAware¶
Abstract Source on GitHub
This abstract class offers common access to the DI in a class
stdClassPhalcon\Di\AbstractInjectionAware- implementsPhalcon\Di\InjectionAwareInterface
Uses stdClass
Method Summary¶
public
DiInterface
getDI()
Returns the internal dependency injector
public
void
setDI( DiInterface $container )
Sets the dependency injector
Properties¶
protected
DiInterface
$container
Dependency Injector
Methods¶
getDI()¶
Returns the internal dependency injector
setDI()¶
Sets the dependency injector
Di\Di¶
Class Source on GitHub
Phalcon\Di\Di is a component that implements Dependency Injection/Service Location of services and it's itself a container for them.
Since Phalcon is highly decoupled, Phalcon\Di\Di is essential to integrate the different components of the framework. The developer can also use this component to inject dependencies and manage global instances of the different classes used in the application.
Basically, this component implements the Inversion of Control pattern.
Applying this, the objects do not receive their dependencies using setters or
constructors, but requesting a service dependency injector. This reduces the
overall complexity, since there is only one way to get the required
dependencies within a component.
Additionally, this pattern increases testability in the code, thus making it less prone to errors.
use Phalcon\Di\Di;
use Phalcon\Http\Request;
$di = new Di();
// Using a string definition
$di->set("request", Request::class, true);
// Using an anonymous function
$di->setShared(
"request",
function () {
return new Request();
}
);
$request = $di->getRequest();
Phalcon\Di\Di- implementsPhalcon\Di\DiInterface
Uses Phalcon\Config\Adapter\Php · Phalcon\Config\Adapter\Yaml · Phalcon\Config\ConfigInterface · Phalcon\Di\DiInterface · Phalcon\Di\Exception · Phalcon\Di\Exception\ServiceResolutionException · Phalcon\Di\Exceptions\AliasAlreadyInUse · Phalcon\Di\Exceptions\AliasNameMustBeString · Phalcon\Di\Exceptions\CircularAliasReference · Phalcon\Di\Exceptions\ServiceCannotBeResolved · Phalcon\Di\InitializationAwareInterface · Phalcon\Di\InjectionAwareInterface · Phalcon\Di\Service · Phalcon\Di\ServiceInterface · Phalcon\Di\ServiceProviderInterface · Phalcon\Events\ManagerInterface
Method Summary¶
public
mixed|null
__call(string $method,array $arguments = [])
Magic method to get or set services using setters/getters
public
__construct()
Phalcon\Di\Di constructor
public
ServiceInterface|bool
attempt(string $name,mixed $definition,bool $shared = false)
Attempts to register a service in the services container
public
mixed
get(string $name,mixed $parameters = null)
Resolves the service based on its configuration
public
string
getAlias( string $name )
Return the alias based on a passed key. Returns an empty string if
public
DiInterface|null
getDefault()
Return the latest DI created
public
ManagerInterface|null
getInternalEventsManager()
Returns the internal event manager
public
mixed
getRaw( string $name )
Returns a service definition without resolving
public
ServiceInterface
getService( string $name )
Returns a Phalcon\Di\Service instance
public
ServiceInterface[]
getServices()
Return the services registered in the DI
public
mixed
getShared(string $name,mixed $parameters = null)
Resolves a service, the resolved service is stored in the DI, subsequent
public
bool
has( string $name )
Check whether the DI contains a service by a name
public
bool
hasShared( string $name )
Check whether the DI has a cached shared instance for a service name.
public
void
loadFromPhp( string $filePath )
Loads services from a php config file.
public
void
loadFromYaml(string $filePath,array $callbacks = null)
Loads services from a yaml file.
public
bool
offsetExists( mixed $name )
Check if a service is registered using the array syntax
public
mixed
offsetGet( mixed $name )
Allows to obtain a shared service using the array syntax
public
void
offsetSet(mixed $offset,mixed $value)
Allows to register a shared service using the array syntax
public
void
offsetUnset( mixed $name )
Removes a service from the services container using the array syntax
public
void
register( ServiceProviderInterface $provider )
Registers a service provider.
public
void
remove( string $name )
Removes a service in the services container
public
void
removeShared( string $name )
Removes the cached shared instance for a service, leaving the service
public
void
reset()
Resets the internal default DI
public
ServiceInterface
set(string $name,mixed $definition,bool $shared = false)
Registers a service in the services container
public
self
setAlias(string $name,mixed $aliases)
Sets one or more aliases to the given name.
public
void
setDefault( DiInterface $container )
Set a default dependency injection container to be obtained into static
public
setInternalEventsManager( ManagerInterface $eventsManager )
Sets the internal event manager
public
ServiceInterface
setService(string $name,ServiceInterface $rawDefinition)
Sets a service using a raw Phalcon\Di\Service definition
public
ServiceInterface
setShared(string $name,mixed $definition)
Registers an "always shared" service in the services container
protected
void
loadFromConfig( ConfigInterface $config )
Loads services from a Config object.
Properties¶
protected
array
$aliases = []
List of service aliases
protected
DiInterface|null
$defaultContainer = null
Latest DI build
protected
ManagerInterface|null
$eventsManager = null
Events Manager
protected
ServiceInterface[]
$services = []
List of registered services
protected
array
$sharedInstances = []
List of shared instances
Methods¶
__call()¶
Magic method to get or set services using setters/getters
__construct()¶
Phalcon\Di\Di constructor
attempt()¶
public function attempt(
string $name,
mixed $definition,
bool $shared = false
): ServiceInterface|bool;
Attempts to register a service in the services container Only is successful if a service hasn't been registered previously with the same name
get()¶
Resolves the service based on its configuration
getAlias()¶
Return the alias based on a passed key. Returns an empty string if the alias does not exist
getDefault()¶
Return the latest DI created
getInternalEventsManager()¶
Returns the internal event manager
getRaw()¶
Returns a service definition without resolving
getService()¶
Returns a Phalcon\Di\Service instance
getServices()¶
Return the services registered in the DI
getShared()¶
Resolves a service, the resolved service is stored in the DI, subsequent requests for this service will return the same instance
has()¶
Check whether the DI contains a service by a name
hasShared()¶
Check whether the DI has a cached shared instance for a service name.
Unlike has(), which reports on the service definition registry,
this method reports only on the resolved-instance cache populated by
getShared().
loadFromPhp()¶
Loads services from a php config file.
And the services can be specified in the file as:
return [
'myComponent' => [
'className' => '\Acme\Components\MyComponent',
'shared' => true,
],
'group' => [
'className' => '\Acme\Group',
'arguments' => [
[
'type' => 'service',
'service' => 'myComponent',
],
],
],
'user' => [
'className' => '\Acme\User',
],
];
@link https://docs.phalcon.io/latest/di/
loadFromYaml()¶
Loads services from a yaml file.
$di->loadFromYaml(
"path/services.yaml",
[
"!approot" => function ($value) {
return dirname(__DIR__) . $value;
}
]
);
And the services can be specified in the file as:
myComponent:
className: \Acme\Components\MyComponent
shared: true
group:
className: \Acme\Group
arguments:
- type: service
name: myComponent
user:
className: \Acme\User
@link https://docs.phalcon.io/latest/di/
offsetExists()¶
Check if a service is registered using the array syntax
offsetGet()¶
Allows to obtain a shared service using the array syntax
offsetSet()¶
Allows to register a shared service using the array syntax
offsetUnset()¶
Removes a service from the services container using the array syntax
register()¶
Registers a service provider.
use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
class SomeServiceProvider implements ServiceProviderInterface
{
public function register(DiInterface $di)
{
$di->setShared(
'service',
function () {
// ...
}
);
}
}
remove()¶
Removes a service in the services container It also removes any shared instance created for the service
removeShared()¶
Removes the cached shared instance for a service, leaving the service
definition intact so the next getShared() call rebuilds it.
reset()¶
Resets the internal default DI
set()¶
Registers a service in the services container
setAlias()¶
Sets one or more aliases to the given name.
setDefault()¶
Set a default dependency injection container to be obtained into static methods
setInternalEventsManager()¶
Sets the internal event manager
setService()¶
Sets a service using a raw Phalcon\Di\Service definition
setShared()¶
Registers an "always shared" service in the services container
loadFromConfig()¶
Loads services from a Config object.
Di\DiInterface¶
Interface Source on GitHub
Interface for Phalcon\Di\Di
ArrayAccessPhalcon\Di\DiInterface
Uses ArrayAccess
Method Summary¶
public
ServiceInterface|bool
attempt(string $name,mixed $definition,bool $shared = false)
Attempts to register a service in the services container
public
mixed
get(string $name,mixed $parameters = null)
Resolves the service based on its configuration
public
DiInterface|null
getDefault()
Return the last DI created
public
mixed
getRaw( string $name )
Returns a service definition without resolving
public
ServiceInterface
getService( string $name )
Returns the corresponding Phalcon\Di\Service instance for a service
public
ServiceInterface[]
getServices()
Return the services registered in the DI
public
mixed
getShared(string $name,mixed $parameters = null)
Returns a shared service based on their configuration
public
bool
has( string $name )
Check whether the DI contains a service by a name
public
bool
hasShared( string $name )
Check whether the DI has a cached shared instance for a service name.
public
void
remove( string $name )
Removes a service in the services container
public
void
removeShared( string $name )
Removes the cached shared instance for a service, leaving the service
public
void
reset()
Resets the internal default DI
public
ServiceInterface
set(string $name,mixed $definition,bool $shared = false)
Registers a service in the services container
public
void
setDefault( DiInterface $container )
Set a default dependency injection container to be obtained into static
public
ServiceInterface
setService(string $name,ServiceInterface $rawDefinition)
Sets a service using a raw Phalcon\Di\Service definition
public
ServiceInterface
setShared(string $name,mixed $definition)
Registers an "always shared" service in the services container
Methods¶
attempt()¶
public function attempt(
string $name,
mixed $definition,
bool $shared = false
): ServiceInterface|bool;
Attempts to register a service in the services container Only is successful if a service hasn't been registered previously with the same name
get()¶
Resolves the service based on its configuration
getDefault()¶
Return the last DI created
getRaw()¶
Returns a service definition without resolving
getService()¶
Returns the corresponding Phalcon\Di\Service instance for a service
getServices()¶
Return the services registered in the DI
getShared()¶
Returns a shared service based on their configuration
has()¶
Check whether the DI contains a service by a name
hasShared()¶
Check whether the DI has a cached shared instance for a service name.
Unlike has(), which reports on the service definition registry,
this method reports only on the resolved-instance cache populated by
getShared(). A service can be registered (has() returns true)
without yet having a shared instance (hasShared() returns false).
remove()¶
Removes a service in the services container
removeShared()¶
Removes the cached shared instance for a service, leaving the service
definition intact so the next getShared() call rebuilds it.
Useful in fork-based multi-process setups where a child inherits the parent's resource handle (e.g. a database connection) and needs to discard the cached instance without re-registering the service.
reset()¶
Resets the internal default DI
set()¶
Registers a service in the services container
setDefault()¶
Set a default dependency injection container to be obtained into static methods
setService()¶
Sets a service using a raw Phalcon\Di\Service definition
setShared()¶
Registers an "always shared" service in the services container
Di\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Di will use this class
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exception\ServiceResolutionExceptionPhalcon\Di\Exceptions\AliasAlreadyInUsePhalcon\Di\Exceptions\AliasNameMustBeStringPhalcon\Di\Exceptions\ArgumentTypeRequiredPhalcon\Di\Exceptions\CallArgumentsMustBeArrayPhalcon\Di\Exceptions\CircularAliasReferencePhalcon\Di\Exceptions\ContainerRequiredPhalcon\Di\Exceptions\DefinitionMustBeArrayForReadPhalcon\Di\Exceptions\DefinitionMustBeArrayForUpdatePhalcon\Di\Exceptions\MethodCallMustBeArrayPhalcon\Di\Exceptions\MethodNameRequiredPhalcon\Di\Exceptions\MissingClassNameParameterPhalcon\Di\Exceptions\MissingParameterKeyPhalcon\Di\Exceptions\PropertyInjectionRequiresInstancePhalcon\Di\Exceptions\PropertyMustBeArrayPhalcon\Di\Exceptions\PropertyNameRequiredPhalcon\Di\Exceptions\PropertyValueRequiredPhalcon\Di\Exceptions\ServiceCannotBeResolvedPhalcon\Di\Exceptions\SetterInjectionRequiresInstancePhalcon\Di\Exceptions\SetterParametersMustBeArrayPhalcon\Di\Exceptions\UnknownServiceType
Method Summary¶
public
Exception
serviceCannotBeResolved( string $name )
public
Exception
serviceNotFound( string $name )
public
Exception
undefinedMethod( string $method )
public
Exception
unknownServiceInParameter( int $position )
Methods¶
serviceCannotBeResolved()¶
serviceNotFound()¶
undefinedMethod()¶
unknownServiceInParameter()¶
Di\Exception\ServiceResolutionException¶
Class Source on GitHub
Phalcon\Di\Exception\ServiceResolutionException
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exception\ServiceResolutionException
Di\Exceptions\AliasAlreadyInUse¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\AliasAlreadyInUse
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\AliasNameMustBeString¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\AliasNameMustBeString
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\ArgumentTypeRequired¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\ArgumentTypeRequired
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\CallArgumentsMustBeArray¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\CallArgumentsMustBeArray
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\CircularAliasReference¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\CircularAliasReference
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\ContainerRequired¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\ContainerRequired
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\DefinitionMustBeArrayForRead¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\DefinitionMustBeArrayForRead
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\DefinitionMustBeArrayForUpdate¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\DefinitionMustBeArrayForUpdate
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\MethodCallMustBeArray¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\MethodCallMustBeArray
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\MethodNameRequired¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\MethodNameRequired
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\MissingClassNameParameter¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\MissingClassNameParameter
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\MissingParameterKey¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\MissingParameterKey
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\PropertyInjectionRequiresInstance¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\PropertyInjectionRequiresInstance
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\PropertyMustBeArray¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\PropertyMustBeArray
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\PropertyNameRequired¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\PropertyNameRequired
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\PropertyValueRequired¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\PropertyValueRequired
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\ServiceCannotBeResolved¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\ServiceCannotBeResolved
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\SetterInjectionRequiresInstance¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\SetterInjectionRequiresInstance
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\SetterParametersMustBeArray¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\SetterParametersMustBeArray
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\Exceptions\UnknownServiceType¶
Class Source on GitHub
\ExceptionPhalcon\Di\ExceptionPhalcon\Di\Exceptions\UnknownServiceType
Uses Phalcon\Di\Exception
Method Summary¶
Methods¶
__construct()¶
Di\FactoryDefault¶
Class Source on GitHub
This is a variant of the standard Phalcon\Di\Di. By default it automatically registers all the services provided by the framework. Thanks to this, the developer does not need to register each service individually providing a full stack framework
Phalcon\Di\DiPhalcon\Di\FactoryDefault
Uses Phalcon\Filter\FilterFactory
Method Summary¶
Methods¶
__construct()¶
Phalcon\Di\FactoryDefault constructor
Di\FactoryDefault\Cli¶
Class Source on GitHub
Phalcon\Di\FactoryDefault\Cli
This is a variant of the standard Phalcon\Di. By default it automatically registers all the services provided by the framework. Thanks to this, the developer does not need to register each service individually. This class is specially suitable for CLI applications
Phalcon\Di\DiPhalcon\Di\FactoryDefaultPhalcon\Di\FactoryDefault\Cli
Uses Phalcon\Di\FactoryDefault · Phalcon\Di\Service · Phalcon\Filter\FilterFactory
Method Summary¶
Methods¶
__construct()¶
Phalcon\Di\FactoryDefault\Cli constructor
Di\InitializationAwareInterface¶
Interface Source on GitHub
Interface for components that have initialize()
Phalcon\Di\InitializationAwareInterface
Method Summary¶
Methods¶
initialize()¶
Di\Injectable¶
Abstract Source on GitHub
This class allows to access services in the services container by just only accessing a public property with the same name of a registered service
@property \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher @property \Phalcon\Mvc\Router|\Phalcon\Mvc\RouterInterface $router @property \Phalcon\Mvc\Url|\Phalcon\Mvc\Url\UrlInterface $url @property \Phalcon\Http\Request|\Phalcon\Http\RequestInterface $request @property \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface $response @property \Phalcon\Http\Response\Cookies|\Phalcon\Http\Response\CookiesInterface $cookies @property \Phalcon\Filter\Filter $filter @property \Phalcon\Flash\Direct $flash @property \Phalcon\Flash\Session $flashSession @property \Phalcon\Session\ManagerInterface $session @property \Phalcon\Events\Manager|\Phalcon\Events\ManagerInterface $eventsManager @property \Phalcon\Db\Adapter\AdapterInterface $db @property \Phalcon\Encryption\Security $security @property \Phalcon\Encryption\Crypt|\Phalcon\Encryption\Crypt\CryptInterface $crypt @property \Phalcon\Html\TagFactory $tag @property \Phalcon\Html\Escaper|\Phalcon\Html\Escaper\EscaperInterface $escaper @property \Phalcon\Annotations\Adapter\Memory|\Phalcon\Annotations\Adapter $annotations @property \Phalcon\Mvc\Model\Manager|\Phalcon\Mvc\Model\ManagerInterface $modelsManager @property \Phalcon\Mvc\Model\MetaData\Memory|\Phalcon\Mvc\Model\MetadataInterface $modelsMetadata @property \Phalcon\Mvc\Model\Transaction\Manager|\Phalcon\Mvc\Model\Transaction\ManagerInterface $transactionManager @property \Phalcon\Support\Settings $settings @property \Phalcon\Assets\Manager $assets @property \Phalcon\Di\Di|\Phalcon\Di\DiInterface $di @property \Phalcon\Session\Bag|\Phalcon\Session\BagInterface $persistent @property \Phalcon\Mvc\View|\Phalcon\Mvc\ViewInterface $view
stdClass
Uses Phalcon\Di\Di · Phalcon\Di\Exceptions\ContainerRequired · Phalcon\Session\BagInterface · stdClass
Method Summary¶
public
mixed|null
__get( string $propertyName )
Magic method __get
public
bool
__isset( string $name )
Magic method __isset
public
DiInterface
getDI()
Returns the internal dependency injector
public
void
setDI( DiInterface $container )
Sets the dependency injector
Properties¶
protected
DiInterface|null
$container = null
Dependency Injector
Methods¶
__get()¶
Magic method __get
__isset()¶
Magic method __isset
getDI()¶
Returns the internal dependency injector
setDI()¶
Sets the dependency injector
Di\InjectionAwareInterface¶
Interface Source on GitHub
This interface must be implemented in those classes that uses internally the Phalcon\Di\Di that creates them
Phalcon\Di\InjectionAwareInterface
Method Summary¶
public
DiInterface
getDI()
Returns the internal dependency injector
public
void
setDI( DiInterface $container )
Sets the dependency injector
Methods¶
getDI()¶
Returns the internal dependency injector
setDI()¶
Sets the dependency injector
Di\Service¶
Class Source on GitHub
Represents individually a service in the services container
$service = new \Phalcon\Di\Service(
"request",
\Phalcon\Http\Request::class
);
$request = service->resolve();
Phalcon\Di\Service- implementsPhalcon\Di\ServiceInterface
Uses Closure · Phalcon\Di\Exception\ServiceResolutionException · Phalcon\Di\Exceptions\DefinitionMustBeArrayForRead · Phalcon\Di\Exceptions\DefinitionMustBeArrayForUpdate · Phalcon\Di\Service\Builder
Method Summary¶
public
__construct(mixed $definition,bool $shared = false)
Phalcon\Di\Service
public
mixed
getDefinition()
Returns the service definition
public
getParameter( int $position )
Returns a parameter in a specific position
public
bool
isResolved()
Returns true if the service was resolved
public
bool
isShared()
Check whether the service is shared or not
public
mixed
resolve(mixed $parameters = null,DiInterface $container = null)
Resolves the service
public
void
setDefinition( mixed $definition )
Set the service definition
public
ServiceInterface
setParameter(int $position,array $parameter)
Changes a parameter in the definition without resolve the service
public
void
setShared( bool $shared )
Sets if the service is shared or not
public
void
setSharedInstance( mixed $sharedInstance )
Sets/Resets the shared instance related to the service
Properties¶
protected
mixed
$definition
protected
bool
$resolved = false
protected
bool
$shared = false
protected
mixed|null
$sharedInstance = null
Methods¶
__construct()¶
Phalcon\Di\Service
getDefinition()¶
Returns the service definition
getParameter()¶
Returns a parameter in a specific position
isResolved()¶
Returns true if the service was resolved
isShared()¶
Check whether the service is shared or not
resolve()¶
Resolves the service
setDefinition()¶
Set the service definition
setParameter()¶
Changes a parameter in the definition without resolve the service
setShared()¶
Sets if the service is shared or not
setSharedInstance()¶
Sets/Resets the shared instance related to the service
Di\ServiceInterface¶
Interface Source on GitHub
Represents a service in the services container
Phalcon\Di\ServiceInterface
Method Summary¶
public
mixed
getDefinition()
Returns the service definition
public
getParameter( int $position )
Returns a parameter in a specific position
public
bool
isResolved()
Returns true if the service was resolved
public
bool
isShared()
Check whether the service is shared or not
public
mixed
resolve(mixed $parameters = null,DiInterface $container = null)
Resolves the service
public
setDefinition( mixed $definition )
Set the service definition
public
ServiceInterface
setParameter(int $position,array $parameter)
Changes a parameter in the definition without resolve the service
public
setShared( bool $shared )
Sets if the service is shared or not
Methods¶
getDefinition()¶
Returns the service definition
getParameter()¶
Returns a parameter in a specific position
isResolved()¶
Returns true if the service was resolved
isShared()¶
Check whether the service is shared or not
resolve()¶
Resolves the service
setDefinition()¶
Set the service definition
setParameter()¶
Changes a parameter in the definition without resolve the service
setShared()¶
Sets if the service is shared or not
Di\ServiceProviderInterface¶
Interface Source on GitHub
Should be implemented by service providers, or such components, which register a service in the service container.
namespace Acme;
use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
class SomeServiceProvider implements ServiceProviderInterface
{
public function register(DiInterface $di)
{
$di->setShared(
'service',
function () {
// ...
}
);
}
}
Phalcon\Di\ServiceProviderInterface
Method Summary¶
Methods¶
register()¶
Registers a service provider.
Di\Service\Builder¶
Class Source on GitHub
Phalcon\Di\Service\Builder
This class builds instances based on complex definitions
Phalcon\Di\Service\Builder
Uses Phalcon\Di\DiInterface · Phalcon\Di\Exception · Phalcon\Di\Exceptions\ArgumentTypeRequired · Phalcon\Di\Exceptions\CallArgumentsMustBeArray · Phalcon\Di\Exceptions\MethodCallMustBeArray · Phalcon\Di\Exceptions\MethodNameRequired · Phalcon\Di\Exceptions\MissingClassNameParameter · Phalcon\Di\Exceptions\MissingParameterKey · Phalcon\Di\Exceptions\PropertyInjectionRequiresInstance · Phalcon\Di\Exceptions\PropertyMustBeArray · Phalcon\Di\Exceptions\PropertyNameRequired · Phalcon\Di\Exceptions\PropertyValueRequired · Phalcon\Di\Exceptions\SetterInjectionRequiresInstance · Phalcon\Di\Exceptions\SetterParametersMustBeArray · Phalcon\Di\Exceptions\UnknownServiceType
Method Summary¶
Methods¶
build()¶
Builds a service using a complex service definition