GithubHelp home page GithubHelp logo

sandrokeil / easyconfig Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 1.0 490 KB

Zend Framework 2 (ZF2) module to retrieve specific module options and provides some abstract factories to create easily instances depending on configuration

License: Other

PHP 100.00%

easyconfig's Introduction

EasyConfig module for Zend Framework 2

You want to configure your factories via your module config?

You want to configure option classes via module config for your plugin manager?

You want to add other services via module config to a factory?

This module comes to the rescue!

Build Status Scrutinizer Quality Score Coverage Status HHVM Status SensioLabsInsight Latest Stable Version Dependency Status Total Downloads License

EasyConfig provides some abstract factories and some interfaces to easily create instances depending on configuration or retrieve specified module options.

  • Well tested. Besides unit test and continuous integration/inspection this solution is also ready for production use.
  • Great foundations. Based on Zend Framework 2
  • Every change is tracked. Want to know whats new? Take a look at CHANGELOG.md
  • Listen to your ideas. Have a great idea? Bring your tested pull request or open a new issue.

You should have coding conventions and you should have config conventions. If not, you should think about that.

The module config keys should have the following structure module.scope.name. A common configuration looks like that:

return array(
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(...)
            )
        )
    )
);

So doctrine is the module, connection is the scope and orm_default is the name. After that the specified instance options follow. With AbstractConfigurableFactory we can easily access to these options also with an option class and mandatory options check. See docs for a detailed explanation.

use Sake\EasyConfig\Service\AbstractConfigurableFactory;
use Sake\EasyConfig\Service\OptionsClassInterface;
use Sake\EasyConfig\Service\MandatoryOptionsInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class MyDBALConnectionFactory extends AbstractConfigurableFactory implements FactoryInterface, OptionsClassInterface, MandatoryOptionsInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        // get option class for doctrine.connection.orm_default
        // dont implement OptionsClassInterface to get an array of options
        $options = $this->getOptions($serviceLocator);

        // so you can do
        $pdo          = $options->getPdo();
        $driverClass  = $options->getDriverClass();
        $wrapperClass = $options->getWrapperClass();

        // create your instance

        return $instance;
    }

    /**
     * Returns a list of mandatory options which must be available
     *
     * @return array
     */
    public function getMandatoryOptions()
    {
        return array(
            'driverClass',
            'params',
        );
    }

    /**
     * Return the option class name (fcqn) where options are injected via constructor
     *
     * @return string
     */
    public function getOptionsClass()
    {
        return '\DoctrineORMModule\Options\DBALConnection';
    }

    /**
     * Module name
     *
     * @return string
     */
    public function getModule()
    {
        return 'doctrine';
    }

    /**
     * Config scope
     *
     * @return string
     */
    public function getScope()
    {
        return 'connection';
    }

    /**
     * Config name
     *
     * @return string
     */
    public function getName()
    {
        return 'orm_default';
    }
}

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.

Put the following into your composer.json

{
    "require": {
        "sandrokeil/easy-config": "~1.0"
    }
}

It is not necessary to add this module to your config/application.config.php.

Documentation

You can find documentation about the usages of factories at the following links:

easyconfig's People

Contributors

sandrokeil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

manojnegi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.