2017 © Pedro Peláez
 

drupal-module dic

Integrates Symfony´s dependency injection container with drupal.

image

janschumann/dic

Integrates Symfony´s dependency injection container with drupal.

  • Thursday, June 2, 2016
  • by janschumann
  • Repository
  • 0 Watchers
  • 0 Stars
  • 783 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

Drupal dependency injection container integration

Build Status, (*1)

Overview

Integrates the Symfony´s Dependency Injection Container with drupal., (*2)

Installation

This project can be checked out with composer., (*3)

{
  "require": {
    "janschumann/dic": "*"
  }
}

Confguration

Usually no configuration is necessary., (*4)

The default dic cache dir will be determined by DRUPAL_ROOT . '/' . variable_get('file_public_path', '') . '/dic'., (*5)

This can be customized by setting the dic_root_dir variable., (*6)

Via shell script:, (*7)

$ drush vset dic_root_dir <path/to/cache/dir>

Via php:, (*8)

variable_set('dic_root_dir', '<path/to/cache/dir>');

Usage

Class autoloading is done via composer using the composer_classloader module., (*9)

By default a settings.xml or an environment specific derivate (settings_<environment>.xml) is loaded., (*10)

Provided services

This module provides the symfony event dispacher as a service available through the container., (*11)

An instance of the event dispacher can be retrieved by, (*12)

$dispatcher = drupal_dic()->get('event_dispatcher');

To add a listener to an event, add te following to your settings.xml file., (*13)

<service id="my_service" class="%my_service.class%">
  <tag name="drupal.event_listener" event="<my_event_name>" method="<method_on_my_service>" />
</service>

An event is dispached by:, (*14)

drupal_dic()->get('event_dispatcher')->dispatch('<my_event_name>', <the event class>);

Register bundles

Your modules may implement hook_dic_bundle_info() as described in dic.api.php to register their bundles., (*15)

Example:, (*16)

/**
 * Implements @see hook_dic_bundle_info()
 */
function <my_module>_dic_bundle_info() {
  return array('bundles' => array("\\MyNamespace\\MyBundle\\Bundle\\MyBundle\\MyBundle"));
}

The Versions