2017 © Pedro Peláez
 

symfony1-plugin sf-dependency-injection-plugin

Add Support for Symfony's DependencyInjection component to your symfony1.x project

image

fpeters/sf-dependency-injection-plugin

Add Support for Symfony's DependencyInjection component to your symfony1.x project

  • Wednesday, September 10, 2014
  • by fpeters
  • Repository
  • 2 Watchers
  • 1 Stars
  • 227 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

sfDependencyInjectionPlugin

It provides supporting the Symfony's DependencyInjection component in your older symfony (1.4) project with Composer., (*1)

This Plugin is inspired by https://github.com/issei-m/sfDependencyInjectionPlugin but uses some other approach to load the configuration files., (*2)

Installation

Create the following composer.json in your symfony 1.4 project's root., (*3)

{
    "config": {
        "vendor-dir": "lib/vendor"
    },
    "require": {
        "fpeters/symfony-dependency-injection-plugin": "dev-master"
    },
    "autoload": {
        "psr-0": { "": "psr" }
    },
}

Here, Composer would install the plugin in your plugins directory and some Symfony2 components into vendor/symfony/. Also, You can locate your PSR supported libraries to be auto-loaded in %SF_ROOT%/psr (optional)., (*4)

Install the Composer and install some libraries., (*5)

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install

To register the autoloader for libraries installed with composer, you must add this at the top of your ProjectConfiguration class:, (*6)

``` php, (*7)

config/ProjectConfiguration.class.php

// Composer autoload require_once dirname(DIR).'/lib/vendor/autoload.php';, (*8)

// symfony1 autoload require_once dirname(DIR).'/lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register();, (*9)

class ProjectConfiguration extends sfProjectConfiguration { // ... }, (*10)


Usage ----- The Plugin only creates an empty ContainerBuilder object.To add your service configuration, simply listen for the service_container.load_configuration event in your ProjectConfiguration. The following example will load the services.yml from the global config directory ``` php // Load Services from services.yml $this->dispatcher->connect( 'service_container.load_configuration', function (sfEvent $event) { // load global config dir $loader = new YamlFileLoader($event->getSubject(), new FileLocator(sfConfig::get('sf_config_dir'))); $loader->load('services.yml'); } ); $this->dispatcher->connect( 'service_container.loaded', function (sfEvent $event) { // here you can do stuff when container is loaded $service = $event->getSubject()->get('myCoolService'); } );

You can do nearly anything with this ContainerBuilder. So maybe have a look at documentation: http://symfony.com/doc/current/components/dependency_injection/compilation.html, (*11)

To use a Service in your Code, simply call the Service Container., (*12)


// in a action.class $container = $this->getServiceContainer(); $container->get('myCoolService'); // there is a short version of that $this->getService('myCoolService');

This will also work in your Templates anc Components., (*13)

= $this->getService('myCoolService')->doStuff(); ?>

The Versions

10/09 2014

dev-master

9999999-dev

Add Support for Symfony's DependencyInjection component to your symfony1.x project

  Sources   Download

MIT

The Requires

 

by Felix Peters

plugin service dependency-injection symfony1

29/07 2014

0.1.0

0.1.0.0

Add Support for Symfony's DependencyInjection component to your symfony1.x project

  Sources   Download

MIT

The Requires

 

by Felix Peters

plugin service dependency-injection symfony1