<commit_before># Phapi Dependency Injection Container

Phapi has a Dependency Injector Container that can be used to store both objects and parameters. It's easy to use and it gives the opportunity to replace many of the built in functionality in Phapi since Phapi uses the Container to store most of it's objects, dependencies and parameters.

The container can be accessed in an endpoint by using the <code>$this->app</code> parameter.

## Defining parameters
The easiest example is to store parameters in the container:
```php
<?php
// Set parameter
$di['param'] = 'value';

// Get parameter
echo $di['param']; // Output: value
```

## Defining objects and dependencies
Objects and its dependencies are defined by **anonymous functions** that returns an instance of an object, you have two options you can use to define them. Either by using:
```php
<?php
// Define database configuration
$di['dbUserName'] = 'root';
$di['dbPassword'] = '<PASSWORD>';

// Add DB connection to container
$di['dbConn'] = function ($app) {
  return new PDO(
    'mysql:host=localhost;dbname=test',
    $app['dbUserName'],<commit_msg>Fixed typo<commit_after># Phapi Dependency Injection Container

Phapi has a Dependency Injector Container that can be used to store both objects and parameters. It's easy to use and it gives the opportunity to replace many of the built in functionality in Phapi since Phapi uses the Container to store most of it's objects, dependencies and parameters.

The container can be accessed in an resource by using the <code>$this->app</code> parameter.

## Defining parameters
The easiest example is to store parameters in the container:
```php
<?php
// Set parameter
$di['param'] = 'value';

// Get parameter
echo $di['param']; // Output: value
```

## Defining objects and dependencies
Objects and its dependencies are defined by **anonymous functions** that returns an instance of an object, you have two options you can use to define them. Either by using:
```php
<?php
// Define database configuration
$di['dbUserName'] = 'root';
$di['dbPassword'] = '<PASSWORD>';

// Add DB connection to container
$di['dbConn'] = function ($app) {
  return new PDO(
    'mysql:host=localhost;dbname=test',
    $app['dbUserName'],
{'fraction_non_alphanumeric': 0.10139075818752805, 'fraction_numerical': 0.0, 'mean_word_length': 4.837696335078534, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5228962', 'n_tokens_mistral': 595, 'n_tokens_neox': 580, 'n_words': 292}