DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Store configuration array service

The goal of this service is to allow configuration objects to store the initial array which was actually used to create the object. You will then be able to fetch the array when your configuration object is created.

Usage

You can activate this service for a given configuration object by attaching it to the ServiceFactory in the static function getConfigurationObjectServices(). Use the constant ServiceInterface::SERVICE_STORE_CONFIGURATION_ARRAY as an identifier for this service (see example below).

You then have to import the trait StoreConfigurationArrayTrait in every class which needs to store its configuration. This can be sub-objects of your configuration object root. Every class which uses this trait has access to the function getConfigurationArray() which returns the full array used to create the object.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use Romm\ConfigurationObject\Service\ServiceInterface;
use Romm\ConfigurationObject\Service\ServiceFactory;
use Romm\Conf[...]\Service\Items\StoreConfigurationArray\StoreConfigurationArrayTrait;
use Romm\ConfigurationObject\ConfigurationObjectFactory;
use Romm\ConfigurationObject\ConfigurationObjectInterface;
use Romm\ConfigurationObject\Traits\ConfigurationObject\DefaultConfigurationObjectTrait;

class MyObject implements ConfigurationObjectInterface
{
    use DefaultConfigurationObjectTrait;

    /**
     * @var SubObject[]
     */
    protected $subObjects;

    /**
     * @return ServiceFactory
     */
    public static function getConfigurationObjectServices()
    {
        return ServiceFactory::getInstance()
            ->attach(ServiceInterface::SERVICE_STORE_CONFIGURATION_ARRAY);
    }
}

class SubObject
{
    use StoreConfigurationArrayTrait;

    /**
     * @var string
     */
    protected $name;
}

$myConfigurationObject = ConfigurationObjectFactory::convert(
    MyObject::class,
    $someConfigurationArray
);

foreach($myConfigurationObject->getSubObjects() as $subObject) {
    // Getting the array used to create the sub-object.
    $configurationArray = $subObject->getConfigurationArray();
}