<commit_before>## CakePimpleDi - Cake 3 Plugin
A cakephp plugin for dependency injection based on Pimple library

## Requirements
* CakePHP 3.X

# Installation
---------
To install this plugin you'll only have to add the plugin to your required section of composer.json then load in your bootstrap file.

```
composer require require rochamarcelo/cake-pimple-di
```

# Bootstrap
---------

Load the plugin as any other plugin:

```php
Plugin::load('RochaMarcelo/CakePimpleDi', ['bootstrap' => true, 'routes' => false]);
```

The bootstrap file must be loaded, to set up all configurations needed

## Register dependencies

In your configuration file you can define all the services:

```php
<?php
return [
    ...

    'CakePimpleDi' => [
        'services' => [
            'LibraryApp\Client' => function() {
                return new \Cake\Network\Http\Client;
            },
            'LibraryApp\Finder' => function($c) {
                $finder = new \LibraryApp\Finder\SimpleFinder(
                	$c['LibraryApp\Client']
                );

                return $finder;
            },
            'random_func' => [
                'value' => function () {
                    return rand();
                },
                'type' => 'parameter'
            ],
            'cookie_name' => 'SESSION_ID',
            [
                'id' => 'something',
                'value' => function () {
                    $std = new \stdClass;
                    $std->rand = rand();
                    return $std;
                },
                'type' => 'factory'
            ]
        ]
    ]
];
```

## Loading dependency
Get the shared instance then call method "get"

```php
use RochaMarcelo\CakePimpleDi\Di\Di;
$finder = Di::instance()->get('LibraryApp\Finder');
```

## Using the DiTrait

```php

namespace App\Controller;
<commit_msg>explications about the service types<commit_after>## CakePimpleDi - Cake 3 Plugin
A cakephp plugin for dependency injection based on Pimple library

## Requirements
* CakePHP 3.X

# Installation
---------
To install this plugin you'll only have to add the plugin to your required section of composer.json then load in your bootstrap file.

```
composer require require rochamarcelo/cake-pimple-di
```

# Bootstrap
---------

Load the plugin as any other plugin:

```php
Plugin::load('RochaMarcelo/CakePimpleDi', ['bootstrap' => true, 'routes' => false]);
```

The bootstrap file must be loaded, to set up all configurations needed

## Register dependencies

In your configuration file you can define all the services:

```php
<?php
return [
    ...

    'CakePimpleDi' => [
        'services' => [
            'LibraryApp\Client' => function() {//each time you get that service, will returns the same instance
                return new \Cake\Network\Http\Client;
            },
            'LibraryApp\Finder' => function($c) {//each time you get that service, will returns  the same instance
                $finder = new \LibraryApp\Finder\SimpleFinder(
                	$c['LibraryApp\Client']
                );

                return $finder;
            },
            'random_func' => [
                'value' => function () {
                    return rand();
                },
                'type' => 'parameter'//when you get that service, will return the original closure
            ],
            'cookie_name' => 'SESSION_ID',
            [
                'id' => 'something',
                'value' => function () {
                    $std = new \stdClass;
                    $std->rand = rand();
                    return $std;
                },
                'type' => 'factory'//will return  a different instance for all calls
            ]
        ]
    ]
];
```

## Loading dependency
Get the shared instance then call method "get"

```php
use RochaMarcelo\CakePimpleDi\Di\Di;
$finder = Di::instance()->get('LibraryApp\Finder');
```

## Using the DiTrait

```php

namespace App\Controller;

{'fraction_non_alphanumeric': 0.1256268806419258, 'fraction_numerical': 0.0010030090270812437, 'mean_word_length': 1.8594982078853046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1282927', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1050, 'n_words': 332}