Interface

eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface

interface ContextualizerInterface

Constants

UNIQUE

With this option, mapConfigArray() will call array_unique() at the end of the merge process.

This will only work with normal arrays (i.e. not hashes) containing scalar values.

MERGE_FROM_SECOND_LEVEL

With this option, mapConfigArray() will merge the hashes from the second level.

For instance: array( 'full' => array( 1, 2, 3 ) ) and array( 'full' => array( 4, 5 ) ) will result in array( 'full' => array( 1, 2, 3, 4, 5 ) ).

Methods

setContextualParameter(string $parameterName, string $scope, mixed $value)

Defines a contextual parameter in the container for given scope in current namespace.

mixed mapSetting(string $id, array $config)

Maps a semantic setting to internal format for all declared scopes.

mapConfigArray(string $id, array $config, int $options)

Maps semantic array settings to internal format, and merges them between scopes.

ContainerInterface getContainer()

setContainer(ContainerInterface $container)

setNamespace(string $namespace)

Injects namespace for internal settings.

string getNamespace()

setSiteAccessNodeName(string $scopeNodeName)

Injects the name of the node under which scope based (semantic) configuration takes place.

string getSiteAccessNodeName()

setAvailableSiteAccesses(array $availableSiteAccesses)

Injects registered SiteAccesses (i.e.

array getAvailableSiteAccesses()

setGroupsBySiteAccess(array $groupsBySiteAccess)

Injects names of registered SiteAccess groups, indexed by SiteAccess.

array getGroupsBySiteAccess()

Details

at line 70
public setContextualParameter(string $parameterName, string $scope, mixed $value)

Defines a contextual parameter in the container for given scope in current namespace.

Resulting parameter will have format .. .

```php <?php namespace Acme\DemoBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware;

class AcmeDemoExtension extends Extension { public function load( array $configs, ContainerBuilder $container ) { $loader = new Loader\YamlFileLoader( $container, new FileLocator( DIR . '/../Resources/config' ) );

    $configuration = $this->getConfiguration( $configs, $container );
    $config = $this->processConfiguration( $configuration, $configs );

    // ...
    $processor = new SiteAccessAware\ConfigurationProcessor( $container, 'acme_demo' );
    $processor->mapConfig(
        $config,
        function ( array $scopeSettings, $currentScope, SiteAccessAware\ContextualizerInterface $contextualizer )
        {
            // Value of 'some_semantic_parameter' will be stored as a container parameter under
            // key acme_demo.<$currentScope>.my_internal_parameter
            $contextualizer->setContextualParameter( 'my_internal_parameter', $currentScope, $scopeSettings['some_semantic_parameter'] );
        }
    );
}

} ```

Parameters

string $parameterName
string $scope
mixed $value

at line 83
public mixed mapSetting(string $id, array $config)

Maps a semantic setting to internal format for all declared scopes.

Resulting parameter will have format .. .

Parameters

string $id Id of the setting to map. Note that it will be used to identify the semantic setting in $config and to define the internal setting in the container (..<$id>)
array $config Full semantic configuration array for current bundle.

Return Value

mixed

at line 176
public mapConfigArray(string $id, array $config, int $options)

Maps semantic array settings to internal format, and merges them between scopes.

This is useful when you have e.g. a hash of settings defined in a siteaccess group and you want an entry of this hash, defined at the siteaccess or global level, to replace the one in the group.

Defined arrays are merged in the following scopes:

To calculate the precedence of siteaccess groups, they are alphabetically sorted.

Example:

```yaml acmedemo: system: mysiteaccessgroup: foosetting: foo: "bar" some: "thing" an_integer: 123 enabled: false

    # Assuming my_siteaccess is part of my_siteaccess_group
    my_siteaccess:
        foo_setting:
            an_integer: 456
            enabled: true

```

In your DIC extension

```php namespace Acme\DemoBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware;

class AcmeDemoExtension extends Extension { public function load( array $configs, ContainerBuilder $container ) { $loader = new Loader\YamlFileLoader( $container, new FileLocator( DIR . '/../Resources/config' ) );

    $configuration = $this->getConfiguration( $configs, $container );
    $config = $this->processConfiguration( $configuration, $configs );

    // ...
    $processor = new SiteAccessAware\ConfigurationProcessor( $container, 'acme_demo' );
    $contextualizer = $processor->getContextualizer();
    $contextualizer->mapConfigArray( 'foo_setting', $configs );

    $processor->mapConfig(
        $config,
        function ( array $scopeSettings, $currentScope, SiteAccessAware\ContextualizerInterface $contextualizer )
        {
            // ...
        }
    );
}

} ```

This will result with having following parameters in the container:

```yaml acmedemo.mysiteaccess.foosetting: foo: "bar" some: "thing" aninteger: 456 enabled: true

acmedemo.mysiteaccessgorup.foosetting foo: "bar" some: "thing" an_integer: 123 enabled: false ```

Parameters

string $id Id of the setting array to map. Note that it will be used to identify the semantic setting in $config and to define the internal setting in the container (..<$id>)
array $config Full semantic configuration array for current bundle.
int $options Bit mask of options (see constants of the interface)

at line 181
public ContainerInterface getContainer()

Return Value

ContainerInterface

at line 186
public setContainer(ContainerInterface $container)

Parameters

ContainerInterface $container

at line 195
public setNamespace(string $namespace)

Injects namespace for internal settings.

Registered internal settings always have the format .. e.g. ezsettings.default.session.

Parameters

string $namespace

at line 200
public string getNamespace()

Return Value

string

at line 207
public setSiteAccessNodeName(string $scopeNodeName)

Injects the name of the node under which scope based (semantic) configuration takes place.

Parameters

string $scopeNodeName

at line 212
public string getSiteAccessNodeName()

Return Value

string

at line 219
public setAvailableSiteAccesses(array $availableSiteAccesses)

Injects registered SiteAccesses (i.e.

configuration scopes).

Parameters

array $availableSiteAccesses

at line 224
public array getAvailableSiteAccesses()

Return Value

array

at line 232
public setGroupsBySiteAccess(array $groupsBySiteAccess)

Injects names of registered SiteAccess groups, indexed by SiteAccess.

i.e. Which groups a SiteAccess is part of.

Parameters

array $groupsBySiteAccess

at line 237
public array getGroupsBySiteAccess()

Return Value

array