petrgrishin/yiipimple

Integration dependency injection container Pimple in Yii framework

dev-master 2013-06-10 06:21 UTC

This package is not auto-updated.

Last update: 2024-12-16 15:44:05 UTC


README

Integration dependency injection container Pimple in Yii framework

  1. Install Pimple

composer.json:

{
  "require": {
    "petrgrishin/yiipimple": "dev-master"
  }
}
  1. Change the entry scripts

Just change this

Yii::createWebApplication($config)->run();

into

Yii::createApplication('\YiiPimple\WebApplication', $config)->run();
  1. Configuration
return array(
    // ...
    // dipendency injection configuration
    'container' => array(
        'class' => '\YiiPimple\CContainer',
        'services' => array(
            // ... put here your services
        );
    ),
    // ...
);
  1. Retrieve services
$service = Yii::app()->getContainer()->get('service');
// yii urlManager
$urlManager = Yii::app()->getContainer()->get('yii.core.urlManager');