2017 © Pedro Peláez
 

symfony-bundle configuration

Configuration abstract class for Symfony projects

image

johnkrovitch/configuration

Configuration abstract class for Symfony projects

  • Tuesday, April 17, 2018
  • by JohnKrovitch
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,110 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

Configuration

Configuration class for Symfony projects. This package allows you to manipulate immutable configuration object. You can add your custom getters to improve parameters php type, or you the default generic getters., (*1)

Installation

composer install johnkrovitch/configuration

v2.0: For Symfony 5.1+, (*2)

v1.0: For Symfony 3.4, 4.4, (*3)

Usage

Create a configuration class., (*4)

<?php

use JK\Configuration\Configuration;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MyConfiguration extends Configuration 
{
    public function configureOptions(OptionsResolver $resolver): void {
        // Configure your options resolver here 
        $resolver->setDefaults([
            'panda' => 'bamboo',
        ]);
    }
}

Use it in your service for example :, (*5)

<?php

use MyConfiguration;

class MyService {

    public function myMethod(array $options): void
    {
        $configuration = new MyConfiguration();
        $configuration->configure($options);

        $configuration->get('panda'); // "bamboo"
        $configuration->has('panda'); // true
        $configuration->toArray(); // ['panda' => 'bamboo']        
    }

}

You can also provide a options resolver :, (*6)

use MyConfiguration;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MyService {

    public function myMethod(array $options): void
    {
        $configuration = new MyConfiguration();
        $resolver = new OptionsResolver();

        // Do something with the resolver
        // $resolver->setDefaults('...');

        // Pass your custom resolver
        $configuration->configure($options, $resolver);

        $configuration->get('panda'); // Returns "bamboo"
        $configuration->has('panda'); // Returns true
        $configuration->toArray(); // Returns ['panda' => 'bamboo']        
    }

}

OptionsResolver

The Configuration use the Symfony OptionsResolver component, (*7)

The Versions

17/04 2018

dev-master

9999999-dev

Configuration abstract class for Symfony projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JohnKrovitch

17/04 2018

v1.1

1.1.0.0

Configuration abstract class for Symfony projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JohnKrovitch

11/11 2017

v1.0.1

1.0.1.0

Configuration abstract class for Symfony projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JohnKrovitch

11/11 2017

dev-release/v1.0.1

dev-release/v1.0.1

Configuration abstract class for Symfony projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JohnKrovitch

16/02 2017

v1.0

1.0.0.0

Configuration abstract class for Symfony projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar JohnKrovitch