eZPublishCommunityProject  2013.6
eZ\Publish\Core\Base\ServiceContainer Class Reference

Service container class. More...

+ Inheritance diagram for eZ\Publish\Core\Base\ServiceContainer:
+ Collaboration diagram for eZ\Publish\Core\Base\ServiceContainer:

Public Member Functions

 __construct (array $settings, array $dependencies=array())
 Construct object with optional configuration overrides. More...
 
 get ($serviceName)
 Get service by name. More...
 
 getRepository ()
 Service function to get Repository object. More...
 
 getVariable ($variable)
 Get a variable dependency. More...
 

Protected Member Functions

 getListOfExtendedServices ($parent, $function= '')
 
 getServiceArgument ($argument)
 getListOfExtendedServices() recursivelyLookupArguments() More...
 
 lookupArguments (array $arguments, $recursively=false)
 Lookup arguments for variable, service or arrays for recursive lookup. More...
 
 recursivelyLookupArguments (array $arguments)
 Lookup arguments for variable, service or arrays for recursive lookup. More...
 

Private Attributes

 $dependencies
 
 $settings
 

Detailed Description

Service container class.

A dependency injection container that uses configuration for defining dependencies.

Usage:

$sc = new eZ\Publish\Core\Base\ServiceContainer( $configManager->getConfiguration( 'service' )->getAll() );
$sc->getRepository->getContentService()...;

Or overriding $dependencies (in unit tests): ( $dependencies keys should have same value as service.ini "arguments" values explained bellow )

$sc = new eZ\Publish\Core\Base\ServiceContainer(
    $configManager->getConfiguration( 'service' )->getAll(),
    array(
        '@persistence_handler' => new \eZ\Publish\Core\Persistence\InMemory\Handler()
    )
);
$sc->getRepository->getContentService()...;

Settings are defined in service.ini like the following example:

[repository]
class=eZ\Publish\Core\Base\Repository
arguments[persistence_handler]=@persistence_handler_inmemory

[persistence_handler_inmemory]
class=eZ\Publish\Core\Persistence\InMemory\Handler

# @see \eZ\Publish\Core\settings\service.ini For more options and examples.

"arguments" values in service.ini can start with either @ in case of other services being dependency, $ if a predefined global variable is to be used ( currently: $_SERVER, $_REQUEST, $_COOKIE, $_FILES ) or plain scalar if that is to be given directly as argument value. If the argument value starts with %, then it is a lazy loaded service provided as a callback (closure).

Constructor & Destructor Documentation

eZ\Publish\Core\Base\ServiceContainer::__construct ( array  $settings,
array  $dependencies = array() 
)

Construct object with optional configuration overrides.

Parameters
array$settingsServices settings
mixed[]|object[]$dependencies Optional initial dependencies

Member Function Documentation

eZ\Publish\Core\Base\ServiceContainer::get (   $serviceName)

Get service by name.

lookupArguments()

Exceptions
\eZ\Publish\Core\Base\Exceptions\BadConfiguration
\eZ\Publish\Core\Base\Exceptions\MissingClass
Parameters
string$serviceName
Returns
object
eZ\Publish\Core\Base\ServiceContainer::getListOfExtendedServices (   $parent,
  $function = '' 
)
protected
Parameters
string$parentEg: %:controller
string$functionOptional function string
Returns
array

Referenced by eZ\Publish\Core\Base\ServiceContainer\getServiceArgument().

eZ\Publish\Core\Base\ServiceContainer::getRepository ( )

Service function to get Repository object.

Alias with type hints for $repo->get( 'repository' );

get()

Returns

Implements eZ\Publish\API\Container.

eZ\Publish\Core\Base\ServiceContainer::getServiceArgument (   $argument)
protected

getListOfExtendedServices() recursivelyLookupArguments()

Parameters
string$argument
Exceptions
\eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
Returns
array|closure|mixed|object|null Null on non existing optional dependencies

Referenced by eZ\Publish\Core\Base\ServiceContainer\lookupArguments(), and eZ\Publish\Core\Base\ServiceContainer\recursivelyLookupArguments().

eZ\Publish\Core\Base\ServiceContainer::getVariable (   $variable)

Get a variable dependency.

Parameters
string$variable
Exceptions
\eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Returns
mixed
eZ\Publish\Core\Base\ServiceContainer::lookupArguments ( array  $arguments,
  $recursively = false 
)
protected

Lookup arguments for variable, service or arrays for recursive lookup.

  1. Does not keep keys of first level arguments
  2. Exists loop when it encounters optional non existing service dependencies

getServiceArgument() recursivelyLookupArguments()

Exceptions
\eZ\Publish\API\Repository\Exceptions\InvalidArgumentExceptionIf undefined variable is used.
Parameters
array$arguments
boolean$recursively
Returns
array

Referenced by eZ\Publish\Core\Base\ServiceContainer\get().

eZ\Publish\Core\Base\ServiceContainer::recursivelyLookupArguments ( array  $arguments)
protected

Lookup arguments for variable, service or arrays for recursive lookup.

  1. Keep keys of arguments
  2. Does not exit loop on optional non existing service dependencies

getServiceArgument() recursivelyLookupArguments()

Exceptions
\eZ\Publish\API\Repository\Exceptions\InvalidArgumentExceptionIf undefined variable is used.
Parameters
array$arguments
Returns
array

Referenced by eZ\Publish\Core\Base\ServiceContainer\get(), eZ\Publish\Core\Base\ServiceContainer\getServiceArgument(), and eZ\Publish\Core\Base\ServiceContainer\lookupArguments().

Member Data Documentation

eZ\Publish\Core\Base\ServiceContainer::$dependencies
private
eZ\Publish\Core\Base\ServiceContainer::$settings
private

The documentation for this class was generated from the following file: