How tto retrieve custom configuration?

Hello flow users!

Actually I try to “read” my custom configuration from yaml.
This yaml is located at /MY/project/Configuration/foo.yaml

If I do a

./flow configuration:show

at commandline I get:

Available configuration types:
  Caches
  Objects
  Routes
  Policy
  Settings
  Views
  MY.project.foo

If I do a

./flow configuration:show --type MY.project.foo

I get the content from my yaml.
But, if I try to access these “settings” within the framework i.e. from a CommandController

I always getting NULL.

I followed all examples in documentation:

http://flowframework.readthedocs.org/en/stable/TheDefinitiveGuide/PartIII/Configuration.html

I.e.:

/**
 * @Flow\InjectConfiguration(package="MY.project.foo")
 * @var array
 */
protected $someOtherPackageSettings = array();	

than:

$this->someOtherPackageSettings is equal NULL

I’ve tried several other methods to access the settings, but it results every time in NULL…

Does some have an idea was going wronge here?

Hello Frank,

I’d run in the same issue some days ago. This is how it works for me:
First of all add your configuration file to the Configuration directory of your package. Then create some dummy content in it, just for testing.

If you hadn’t done yet, add Package.php file to “Classes/Vendor/Package/”. This is how mine looks like:

<?php
namespace EntwicklerButze\Ansetzungen;

use \TYPO3\Flow\Package\Package as BasePackage;
use \TYPO3\Flow\Configuration\ConfigurationManager;
use \TYPO3\Flow\Core\Bootstrap;

/**
 * The Basepackage
 */
class Package extends BasePackage {

    /**
     * Invokes custom PHP code directly after the package manager has been initialized.
     *
     * @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap
     * @return void
     */
    public function boot(Bootstrap $bootstrap) {

        // Multi-Client configuration file
        ///////////////////////////////////////////////////////////////////////////////////////////
        $dispatcher = $bootstrap->getSignalSlotDispatcher();
        $dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady',
            function (ConfigurationManager $configurationManager) {
                $configurationManager->registerConfigurationType(
                    'Client',  // <= name of your configuration file without .yaml
                    ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT,
                    TRUE   // <= allow suffixes like "Client.Bigcustomer.yaml"
                );
            }
        );

    }
}

Within your controller just add a variable with the following annotation:

    /**
     * @Flow\InjectConfiguration(type="Client")
     * @var array
     */
    protected $allClientSettings = array();

Now you are able to access all merged configurations like an ordinary assoc array.

Hope it will help you!
Steffen

Hello Steffen,

thank you for your definitivly usefull answer!

I’ve found yesterday a solution too, but your’s is better (and near to the documentation).
The important hint was in the flow injection statement:

    /**
     * @Flow\InjectConfiguration(type="Client")
     * @var array
     */

As I can see, there is no hint or example in the docs.

If somebody is interested: my approach was llike this:
in package.php

$dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady',
                 function ($configurationManager) {
                    $configurationManager->registerConfigurationType('MY.project.foo');
                 } );

To access the data:

first injected the ConfigurationManager:

/**
 * @var \TYPO3\Flow\Configuration\ConfigurationManager
 * @Flow\Inject
 */
protected $configurationManager;    

later on:

  $data = $this->configurationManager->getConfiguration('MY.project.foo');

Thank’s again Steffen!