2017 © Pedro Peláez
 

drupal-module drimple

Module which adds a Dependency Injection Container using Pimple to Drupal 7.x.

image

korstiaan/drimple

Module which adds a Dependency Injection Container using Pimple to Drupal 7.x.

  • Tuesday, October 22, 2013
  • by korstiaan
  • Repository
  • 0 Watchers
  • 8 Stars
  • 26 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Drimple for Drupal 7.x

Module which adds a Dependency Injection Container using Pimple to Drupal., (*1)

Build Status, (*2)

Requirements

  • Drupal 7.x
  • PHP 5.3.3+
  • Pimple

Installation

The recommended way to install Drimple is with Composer. Just add the following to your composer.json:, (*3)

   {
       "minimum-stability": "dev",
       "require": {
           ...
           "korstiaan/drimple": "dev-master"
       }
   }

Now update composer and install the newly added requirement and its dependencies (including Pimple):, (*4)

``` bash $ php composer.phar update korstiaan/drimple, (*5)


If all went well and `composer/installers` did its job, `Drimple` was installed to `modules/drimple`. If you don't want it there, or it's not part of your Drupal rootdir, symlink it to your folder of choice. Next go to `site/all/modules` and enable it on `http://yourdomain.com/admin/modules/list`. (If you're using [voiture](http://voiture.hoppinger.com) just add `drimple` to `cnf/shared/modules.php`) ### Using Composer Using `Composer` means including its autoloader. Add the following to your Drupals settings.php: ```php // /path/to/sites/default/settings.php require '/path/to/vendor/autoload.php';

Usage

Drimples container and its services can then be retrieved as singleton via drimple() or \Drimple\Drimple::getInstance()., (*6)

Adding services

Recommended way of adding services is by implementing hook_drimple_provide(\Drimple\Drimple $drimple):, (*7)

<?php
// sites/all/modules/foo/foo.module

function foo_drimple_provide(\Drimple\Drimple $drimple) 
{
    $drimple['database']            = $drimple->share(function($c) {
        $options = $c['database.options'] + array(
            'user'      => null,
            'password'  => null,
        );
        if (!isset($options['dsn'])) {
            throw new \Exception('Please provide dsn');
        }

        return new \PDO($options['dsn'],$options['user'],$options['password']);
    });
    $drimple['database.options']    = array(
        'dsn'       => 'mysql:dbname=drupal;host=localhost',
        'user'      => 'root',
        'password'  => 'root',
    ); 
}

Service providers

Just like Silex you can also add services to Drimple by registering Service Providers., (*8)

Example:, (*9)

<?php
// sites/all/modules/foo/foo.module

function foo_drimple_provide(\Drimple\Drimple $drimple) 
{
    $drimple->register(new \Foo\Provider\DBProvider(), array(
        'database.options'  => array(
            'dsn'       => 'mysql:dbname=drupal;host=localhost',
            'user'      => 'root',
            'password'  => 'root',
        ),
    ));
}

// sites/all/modules/foo/Foo/Provider/DBProvider.php
namespace Foo\Provider;

use Drimple\Drimple,
    Drimple\Provider\ServiceProviderInterface; 

class DBProvider implements ServiceProviderInterface
{
    public function register(Drimple $drimple)
    {
        $drimple['database'] = $drimple->share(function($c) {
            $options = $c['database.options'] + array(
                'user'      => null,
                'password'  => null,
            );
            if (!isset($options['dsn'])) {
                throw new \Exception('Please provide dsn');
            }
            return new \PDO($options['dsn'],$options['user'],$options['password']);
        });

    }
}

Providers

See the wiki, (*10)

License

Drimple is licensed under the MIT license., (*11)

The Versions

22/10 2013

dev-master

9999999-dev http://korstiaan.com/drimple

Module which adds a Dependency Injection Container using Pimple to Drupal 7.x.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection container drupal pimple

24/07 2012

dev-tests

dev-tests http://korstiaan.com/drimple

Module which adds a Dependency Injection Container using Pimple to Drupal 7.x.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection container drupal pimple