2017 © Pedro Peláez
 

library zf2-bridge

Integrates PHP-DI to Zend Framework 2

image

php-di/zf2-bridge

Integrates PHP-DI to Zend Framework 2

  • Monday, November 13, 2017
  • by mnapoli
  • Repository
  • 3 Watchers
  • 11 Stars
  • 1,620 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 1 Open issues
  • 24 Versions
  • 4 % Grown

The README.md

PHP-DI integration with Zend Framework 2

Build Status, (*1)

This library provides integration for PHP-DI with Zend Framework 2., (*2)

PHP-DI is a Dependency Injection Container for PHP., (*3)

If you are looking for Zend Framework 1 integration, head over here., (*4)

Use

Require the libraries with Composer:, (*5)

{
    "require": {
        "php-di/php-di": "*",
        "php-di/zf2-bridge": "*"
    }
}

To use PHP-DI in your ZF2 application, you need to edit application_root/config/application.config.php:, (*6)

    // ...
    'modules' => [
        ...
        'DI\ZendFramework2',
        ...
    ],

    'service_manager' => [
        // ...
        'factories' => [
            'DI\Container' => 'DI\ZendFramework2\Service\DIContainerFactory',
        ],
    ],

That's it!, (*7)

Now you dependencies are injected in your controllers!, (*8)

If you'd like to specify the di configuration yourself, create this file: application_root/config/php-di.config.php and save it with your PHP DI configuration e.g. like this:, (*9)

return [
    'Application\Service\GreetingServiceInterface' => Di\object('Application\Service\GreetingService'),
];

Head over to PHP-DI's documentation if needed., (*10)

Fine tuning

To configure the module, you have to override the module config somewhere at config/autoload/global.php or config/autoload/local.php., (*11)

return [
    'phpdi-zf2' => [
        ...
    ]
];

Override definitions file location

return [
    'phpdi-zf2' => [
        'definitionsFile' => realpath(__DIR__ . '/../my.custom.def.config.php'),
    ]
];

Enable or disable annotations

return [
    'phpdi-zf2' => [
        'useAnntotations' => true,
    ]
];

Enable APCu

return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'apcu',
            'namespace' => 'your_di_cache_key',
        ],
    ]
];

Enable file cache

return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'filesystem',
            'namespace' => 'your_di_cache_key',
            'directory' => 'your_cache_directory', // default value is data/php-di/cache
        ],
    ]
];

Enable redis cache

If you are also using Redis for storing php sessions, it is very useful to configure the php-di cache handler to use a different database, since you might accidentally delete all your sessions when clearing the php-di definitions cache., (*12)

return [
    'phpdi-zf2' => [
        'cache' => [
            'namespace' => 'your_di_cache_key',
            'adapter' => 'redis',
            'host' => 'localhost', // default is localhost
            'port' => 6379, // default is 6379
            'database' => 1, // default is the same as phpredis default
        ],
    ]
];

Enable Memcached cache

If you're using Memcached, you should have only one project per memcached instance., (*13)

return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'memcached',
            'host' => 'localhost', // default is localhost
            'port' => 11211, // default is 11211
        ],
    ]
];

Console commands

Clear definition cache

To clear the definition cache, run the following command from the project root:, (*14)

php public/index.php php-di-clear-cache

The Versions

24/05 2015
04/02 2014

0.3.0

0.3.0.0 https://github.com/mnapoli/PHP-DI-ZF2/

Integrates PHP-DI to Zend Framework 2

  Sources   Download

MIT

The Requires

 

25/10 2013

0.2.0

0.2.0.0 https://github.com/mnapoli/PHP-DI-ZF2/

Integrates PHP-DI to Zend Framework 2

  Sources   Download

MIT

The Requires

 

03/08 2013

0.1.0

0.1.0.0 https://github.com/mnapoli/PHP-DI-ZF2/

Integrates PHP-DI to Zend Framework 2

  Sources   Download

MIT

The Requires