PHP code example of xervice / yaml-config

1. Go to this page and download the library: Download xervice/yaml-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xervice / yaml-config example snippets


$configFile = new YamlConfigFileDataProvider();
$configFile->setPath(__DIR__ . '/data/my_config.yml');

$fileList = new YamlConfigFileListDataProvider();
$fileList->addFile($configFile);

$config = $yamlConfigFacade->getYamlConfig($fileList); // YamlConfigDataProvider



namespace App\MyModule\Business\Hydrator;

use DataProvider\DockerConfigDataProvider;
use Xervice\YamlConfig\Business\Hydrator\HydratorInterface;
use Xervice\Core\Locator\AbstractWithLocator;

/**
 * @method \App\MyModule\MyModuleFactory getFactory()
 */
class MyHydrator extends AbstractWithLocator implememts HydratorInterface
{
    /**
     * @param array $data
     * @param \DataProvider\YamlConfigDataProvider $dataProvider
     *
     * @return \DataProvider\YamlConfigDataProvider
     * @throws \Xervice\YamlConfig\Business\Exception\ConfigException
     */
    public function hydrateConfig(array $data, DockerConfigDataProvider $dataProvider): DockerConfigDataProvider
        {
            if (isset($data[MyModuleConfig::CONFIG_NAME])) {
                $dataProvider = $this->getFactory()->createMyModuleHydrator(
                    $data[MyModuleConfig::CONFIG_NAME],
                    $dataProvider
                )->hydrate();
            }

            return $dataProvider;
        }
}