2017 © Pedro Peláez
 

symfony1-plugin sf-dependency-injection-plugin

Supporing Symfony's DependencyInjection component for your symfony1 project

image

issei-m/sf-dependency-injection-plugin

Supporing Symfony's DependencyInjection component for your symfony1 project

  • Saturday, July 4, 2015
  • by issei-m
  • Repository
  • 1 Watchers
  • 7 Stars
  • 5,353 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

sfDependencyInjectionPlugin

Build Status, (*1)

Provides integration Symfony2's Dependency Injection component with your older symfony (1.4+) project., (*2)

Installation

Using Composer would be best way:, (*3)

$ composer require issei-m/sf-dependency-injection-plugin

Here, Composer would install this plugin in your plugins directory and some other libraries plugin depends on into vendor., (*4)

If you don't use Composer, you need to install this plugin and some others manually., (*5)

Usage

First, create your services.yml in %SF_ROOT%/config/services.yml. It can be defined your parameters/services to each different environments., (*6)

Something like:, (*7)

# config/services.yml

dev:
  parameters:
    mailer.transport: gmail

all:
  parameters:
    # ...
    mailer.transport: sendmail

  services:
    mailer:
      class:     Mailer
      arguments: ["%mailer.transport%"]
    newsletter_manager:
      class:     NewsletterManager
      calls:
        - [setMailer, ["@mailer"]]

The services.yml is supporting the configuratoin cascade like the settings.yml, and it can be located in several different config directory for apps (e.g.apps/frontend/config). When the ServiceContainer is compiled, the values from these are merged., (*8)

Next, enable this plugin at your ProjectConfiguration:, (*9)

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins('sfDependencyInjectionPlugin');
    ...
  }
}

Now, your sfContext has installed Symfony's service container, it is used as following in your code:, (*10)

// Get the ServiceContainer.
$container = sfContext::getInstance()->getContainer();

// Retrieve the NewsletterManager class which was initialized with the Mailer.
$newsletterManager = $container->get('newsletter_manager');

If you use lexpress/symfony1, sfServiceContainer is replaced with plugin's service container. But it might work almost as well as framework's one:, (*11)

$container = sfContext::getInstance()->getServiceContainer();
$newsletterManager = sfContext::getInstance()->getService('newsletter_manager');

At task

Even though you don't initialize the sfContext at task, you can initialize the service container manually like this:, (*12)

$containerClass = require $this->configuration->getConfigCache()->checkConfig('config/services.yml', true);
$container = new $containerClass();

Event

When container is compiled, service_container.build event is fired. You can expand container definitions if you subscribe this event., (*13)

It means you can have control your service container as you wish with your own extension, compiler pass etc...:, (*14)

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->dispatcher->connect('service_container.build', function (sfEvent $event) {
      /** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */
      $container = $event->getSubject();
      $container->addObjectResource($this);

      // additional parameter
      $container->setParameter('foo', 'bar');

      // add extension
      $container->registerExtension(new YourExtension());

      // add compiler pass
      $container->addCompilerPass(new YourPass());
    });
  }
}

The Versions

04/07 2015

dev-master

9999999-dev

Supporing Symfony's DependencyInjection component for your symfony1 project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Issei Murasawa

plugin service dependency-injection symfony1

03/07 2015

v1.3.1

1.3.1.0

Supporing Symfony's DependencyInjection component for your symfony1 project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Issei Murasawa

plugin service dependency-injection symfony1

12/05 2015

v1.3

1.3.0.0

Supporing Symfony's DependencyInjection component for your symfony1 project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Issei Murasawa

plugin service dependency-injection symfony1

14/04 2015

v1.2

1.2.0.0

Supporing Symfony's DependencyInjection component for your symfony1 project

  Sources   Download

MIT

The Requires

 

by Issei Murasawa

plugin service dependency-injection symfony1

19/10 2013

v1.1

1.1.0.0

Supporing Symfony's DependencyInjection component for your symfony1 project

  Sources   Download

MIT

The Requires

 

by Issei Murasawa

plugin service dependency-injection symfony1