Skip to content

Commit

Permalink
Merge pull request #24 from xelmedia/master
Browse files Browse the repository at this point in the history
#- Refactored module with Cakephp 4.x compatibility
  • Loading branch information
lorenzo authored Nov 25, 2020
2 parents a326bed + 04fd1d0 commit 2ff1316
Show file tree
Hide file tree
Showing 7 changed files with 1,860 additions and 582 deletions.
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dependency Injection Container Plugin for CakePHP 3
# Dependency Injection Container Plugin for CakePHP 4

This plugin adds the ability to configure object instances and their dependencies before they are used,
and to store them into a container class to easy access.
Expand All @@ -20,25 +20,41 @@ composer require lorenzo/piping-bag=dev-master

## Configuration

You will need to add the following line to your application's bootstrap.php file:
### Upgrading from library version 1.x (Cake 3.x)

**DEPRECATED:**
- `ControllerFactoryFilter.php` for injecting controllers
- `ShellDispatcher.php` for injecting shell classes

Remove the following lines in your:
`config/bootstrap.php`:

```php
DispatcherFactory::add('PipingBag\Routing\Filter\ControllerFactoryFilter');
Plugin::load('PipingBag', ['bootstrap' => true]);
```

For getting injection in your controllers to work you need to to replace the following line in your
`config/bootstrap.php`:
### Controller Injection

For getting injection in your controllers to work you need to add the following line in the `bootstrap` method
of your `Application.php`:

```php
DispatcherFactory::add('ControllerFactory');
$this->addPlugin('PipingBag', ['bootstrap' => true]);
$this->controllerFactory = new \PipingBag\Controller\DIControllerFactory();
```

With the following:
### Shell Injection

For getting injection in your controllers to work you need to add the following line of your `bin/cake.php`:

```php
DispatcherFactory::add('PipingBag\Routing\Filter\ControllerFactoryFilter');
$commandFactory = new \PipingBag\Console\DICommandFactory();
$runner = new CommandRunner(new Application(dirname(__DIR__) . '/config'), 'cake', $commandFactory);
```

___

Additionally, you can configure the modules to be used and caching options in your `config/app.php` file.

```php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lorenzo/piping-bag",
"description": "CakePHP 3 plugin for using Ray.Di as a Dependency Injection Container",
"description": "CakePHP 4 plugin for using Ray.Di as a Dependency Injection Container",
"type": "cakephp-plugin",
"require": {
"ray/di": "^2.1"
Expand Down
Loading

0 comments on commit 2ff1316

Please sign in to comment.