<commit_before># MiniDI
Minimal PHP Dependency Injector

# Usage

## Simple usage

```php
class TestClass1 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass2;
}

class TestClass2 extends \ArekX\MiniDI\InjectableObject {}

$injector = \ArekX\MiniDI\Injector::create([
	'testObject' => 'TestClass1',
	'dependsOnTestClass2' => 'TestClass2'
]);

$testObject = $injector->get('testObject');

echo $testObject->dependsOnTestClass2 instanceof TestClass2 ? 'Success!' : 'Fail'; // Outputs Success!
```

## Recursive dependencies are also automatically resolved

```php
class TestClass1 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass2;
}

class TestClass2 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass3;
}

class TestClass3 extends \ArekX\MiniDI\InjectableObject {}

$injector = \ArekX\MiniDI\Injector::create([
	'testObject' => 'TestClass1',
	'dependsOnTestClass2' => 'TestClass2',
	'dependsOnTestClass3' => 'TestClass3',
]);

$testObject = $injector->get('testObject');

echo $testObject->dependsOnTestClass2->dependsOnTestClass3 instanceof TestClass3 ? 'Success!' : 'Fail'; // Outputs Success!
```

# Installation

Install via composer

	composer require arekx/mini-di

# Testing

To run tests in injector you will need phpunit.phar in the directory of the project. 
Please run following command in cloned folder:
<commit_msg>Additional readme info.<commit_after># MiniDI
Minimal PHP Dependency Injector

# Usage

## Simple usage

```php
class TestClass1 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass2;
}

class TestClass2 extends \ArekX\MiniDI\InjectableObject {}

$injector = \ArekX\MiniDI\Injector::create([
	'testObject' => 'TestClass1',
	'dependsOnTestClass2' => 'TestClass2'
]);

$testObject = $injector->get('testObject');

echo $testObject->dependsOnTestClass2 instanceof TestClass2 ? 'Success!' : 'Fail'; // Outputs Success!
```

## Recursive dependencies are also automatically resolved

```php
class TestClass1 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass2;
}

class TestClass2 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass3;
}

class TestClass3 extends \ArekX\MiniDI\InjectableObject {}

$injector = \ArekX\MiniDI\Injector::create([
	'testObject' => 'TestClass1',
	'dependsOnTestClass2' => 'TestClass2',
	'dependsOnTestClass3' => 'TestClass3',
]);

$testObject = $injector->get('testObject');

echo $testObject->dependsOnTestClass2->dependsOnTestClass3 instanceof TestClass3 ? 'Success!' : 'Fail'; // Outputs Success!
```

## Without use of `\ArekX\MiniDI\InjectableObject` for cases when you need to wrap classes which do not usually support injection.

```php
class TestClass1 extends \ArekX\MiniDI\InjectableObject {
	public $dependsOnTestClass2;
}

class TestClass2 extends SomeStandardClass implements \ArekX\MiniDI\Injectable {
	use \ArekX\MiniDI\InjectableTrait;

	public $additionalDependentParam;
}

class TestClass3 extends \ArekX\MiniDI\InjectableObject {}

$injector = \ArekX\MiniDI\Injector::create([
	'testObject' => 'TestClass1',
	'dependsOnTestClass2' => 'TestClass2',
	'additionalDependentParam' => 'TestClass3'
]);

$testObject = $injector->get('testObject');

echo $testObject->dependsOnTestClass2 instanceof TestClass2 ? 'Success!' : 'Fail'; // Outputs Success!
echo $testObject->dependsOnTestClass2->additionalDependentParam instanceof TestClass3 ? 'Success!' : 'Fail'; // Outputs Success!
```

If you don't want or cannot use `\ArekX\MiniDI\InjectableTrait` for some reason. You can simply implement constructor interface by `\ArekX\MiniDI\Injectable` 
and get dependencies yourself via `$injector->get('dependency')`.

# Installation

Install via composer

	composer require arekx/mini-di

# Testing

To run tests in injector you will need phpunit.phar in the directory of the project. 
Please run following command in cloned folder:

{'fraction_non_alphanumeric': 0.11957916345907108, 'fraction_numerical': 0.013856812933025405, 'mean_word_length': 5.8506151142355005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '547212', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1302, 'n_words': 307}