<commit_before>Wandu DI
===

[![Latest Stable Version](https://poser.pugx.org/wandu/di/v/stable.svg)](https://packagist.org/packages/wandu/di)
[![Latest Unstable Version](https://poser.pugx.org/wandu/di/v/unstable.svg)](https://packagist.org/packages/wandu/di)
[![Total Downloads](https://poser.pugx.org/wandu/di/downloads.svg)](https://packagist.org/packages/wandu/di)
[![License](https://poser.pugx.org/wandu/di/license.svg)](https://packagist.org/packages/wandu/di)

[![Build Status](https://travis-ci.org/Wandu/DI.svg?branch=master)](https://travis-ci.org/Wandu/DI)
[![Code Coverage](https://scrutinizer-ci.com/g/Wandu/DI/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Wandu/DI/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Wandu/DI/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Wandu/DI/?branch=master)

Dependency Injection Container.

inspired by [pimple](http://pimple.sensiolabs.org) and [Laravel Container](http://laravel.com/docs/5.1/container)

## Installation

### via Composer

`composer require wandu/di`

## Hot to use

### Simple Example

```php
<?php
namespace Your\Own\Space;

use ArrayAccess;
use Wandu\DI\Container;
use Wandu\DI\ContainerInterface;
use Your\Own\Client;
use Your\Own\RequirePackage;
use Your\Own\RequirePackageInterface;

$container = new Container();

$container->bind(RequirePackageInterface::class, RequirePackage::class);
$container->closure(Client::class, function (ContainerInterface $app, ArrayAccess $config) {
    return new Client($app[RequirePackageInterface::class], $config['client']);
});
$container->alias('client', Client::class);

$container['client']; // return Manager
$container[Client::class]; // return Manager also;

$container['client'] === $container[Client::class]; // true

```

## Document

### Methods

Wandu-DI는 5가지 메서드를 이용하여 Container에 등록할 수 있습니다.

The Wandu-DI provides 4 type of default methods.

1. `closure` (same `singleton` of 1.x)
2. `instance`
3. `bind`
4. `wire` **new** on v2.2
5. `alias`

### 1. Closure

Closure는 클로저를 통해 Container에 내용을 등록할 수 있도록 도와줍니다.

#### Example.

```php
<?php
$container->closure('product', function (ContainerInterface $app, ArrayAccess $config) {
    return new Product();
});

$container['product'] instanceof Product; // true
```

### 2. Instance

Closure와 비슷하지만, Closure없이 직접 값을 바인딩 할 수 있습니다. `instance` 메서드는 `offsetSet`에 연결되어있습니다.

It is similar to the Closure. But, it doesn't need the Closure.

#### Example.

```php
<?php
$container->instance('product', new Product);
// $container['product'] = new Product; // right also. `offsetSet` alias to `instance`.

$container['product'] instanceof Product; // true
```

### 3. Bind

2.x에서 추가된 Bind입니다. Auto Resolve를 위한 메서드입니다. 생성자 전체가 타입힌트가 지정되어 있는 객체일 때 사용가능
합니다. 기준이 되는 Interface와 실제로 구현된 Class 한쌍을 매개변수로 사용하지만, Interface는 생략가능합니다.

#### Example.

```php
class Product
{
    public function __construct(RequireInterface $require)
    {
        /* ... */
    }
}

$container->bind(RequireInterface::class, RequirePackage::class);
// $container->bind(RequirePackage::class); // right also.
$container->bind(Product::class);

$container[Product::class] instanceof Product; // true
```
### 4. Wire

2.2d에서 추가된 메서드입니다. 동작은 Bind와 거의 유사합니다. Bind와 동일하게 객체를 생성합니다. 그리고 객체내에
`@Autowired`가 마킹된 Property가 있을 경우 해당 객체에 해당하는 값을 주입해줍니다.

#### Example.

```php
class Product
{
    /**
     * @Autowired 전체 경로로 사용가능합니다.
     * @var \Your\OwnNamespace\RequireInterface
     */
    private $property1;

    /**
     * @Autowired 상대 경로도 사용가능합니다. (단, use RequireInterface as Req로 선언된 경우 Req는 사용 불가능합니다.)
     * @var RequireInterface
     */
    private $property2;

    public function getProperty1()
    {
        return $this->property1;
    }

    public function getProperty2()
    {
        return $this->property2;
    }
}

$container->bind(RequireInterface::class, RequirePackage::class);

$container->wire(Product::class);

$container[Product::class] instanceof Product; // true
$container[Product::class]->getProperty1() instanceof RequireInterface; // true
$container[Product::class]->getProperty2() instanceof RequireInterface; // true
```


### 5. Alias
<commit_msg>add README (wire)<commit_after>Wandu DI
===

[![Latest Stable Version](https://poser.pugx.org/wandu/di/v/stable.svg)](https://packagist.org/packages/wandu/di)
[![Latest Unstable Version](https://poser.pugx.org/wandu/di/v/unstable.svg)](https://packagist.org/packages/wandu/di)
[![Total Downloads](https://poser.pugx.org/wandu/di/downloads.svg)](https://packagist.org/packages/wandu/di)
[![License](https://poser.pugx.org/wandu/di/license.svg)](https://packagist.org/packages/wandu/di)

[![Build Status](https://travis-ci.org/Wandu/DI.svg?branch=master)](https://travis-ci.org/Wandu/DI)
[![Code Coverage](https://scrutinizer-ci.com/g/Wandu/DI/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Wandu/DI/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Wandu/DI/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Wandu/DI/?branch=master)

Dependency Injection Container.

inspired by [pimple](http://pimple.sensiolabs.org) and [Laravel Container](http://laravel.com/docs/5.1/container)

## Installation

### via Composer

`composer require wandu/di`

## Hot to use

### Simple Example

```php
<?php
namespace Your\Own\Space;

use ArrayAccess;
use Wandu\DI\Container;
use Wandu\DI\ContainerInterface;
use Your\Own\Client;
use Your\Own\RequirePackage;
use Your\Own\RequirePackageInterface;

$container = new Container();

$container->bind(RequirePackageInterface::class, RequirePackage::class);
$container->closure(Client::class, function (ContainerInterface $app, ArrayAccess $config) {
    return new Client($app[RequirePackageInterface::class], $config['client']);
});
$container->alias('client', Client::class);

$container['client']; // return Manager
$container[Client::class]; // return Manager also;

$container['client'] === $container[Client::class]; // true

```

## Document

### Methods

Wandu-DI는 5가지 메서드를 이용하여 Container에 등록할 수 있습니다.

The Wandu-DI provides 4 type of default methods.

1. `closure` (same `singleton` of 1.x)
2. `instance`
3. `bind`
4. `wire` **new** on v2.2
5. `alias`

### 1. Closure

Closure는 클로저를 통해 Container에 내용을 등록할 수 있도록 도와줍니다.

#### Example.

```php
<?php
$container->closure('product', function (ContainerInterface $app, ArrayAccess $config) {
    return new Product();
});

$container['product'] instanceof Product; // true
```

### 2. Instance

Closure와 비슷하지만, Closure없이 직접 값을 바인딩 할 수 있습니다. `instance` 메서드는 `offsetSet`에 연결되어있습니다.

It is similar to the Closure. But, it doesn't need the Closure.

#### Example.

```php
<?php
$container->instance('product', new Product);
// $container['product'] = new Product; // right also. `offsetSet` alias to `instance`.

$container['product'] instanceof Product; // true
```

### 3. Bind

2.x에서 추가된 Bind입니다. Auto Resolve를 위한 메서드입니다. 생성자 전체가 타입힌트가 지정되어 있는 객체일 때 사용가능
합니다. 기준이 되는 Interface와 실제로 구현된 Class 한쌍을 매개변수로 사용하지만, Interface는 생략가능합니다.

#### Example.

```php
class Product
{
    public function __construct(RequireInterface $require)
    {
        /* ... */
    }
}

$container->bind(RequireInterface::class, RequirePackage::class);
// $container->bind(RequirePackage::class); // right also.
$container->bind(Product::class);

$container[Product::class] instanceof Product; // true
```
### 4. Wire

2.2d에서 추가된 메서드입니다. 동작은 Bind와 거의 유사합니다. Bind와 동일하게 객체를 생성합니다. 그리고 객체내에
`@Autowired`가 마킹된 Property가 있을 경우 해당 객체에 해당하는 값을 주입해줍니다.

#### Example.

```php
class Product
{
    /**
     * @Autowired 전체 경로로만 사용가능합니다.
     * @var \Your\OwnNamespace\RequireInterface
     */
    private $property;

    public function getProperty()
    {
        return $this->property;
    }
}

$container->bind(RequireInterface::class, RequirePackage::class);

$container->wire(Product::class);

$container[Product::class] instanceof Product; // true
$container[Product::class]->getProperty() instanceof RequireInterface; // true
```


### 5. Alias

{'fraction_non_alphanumeric': 0.16926336781752463, 'fraction_numerical': 0.005982799451576717, 'mean_word_length': 4.518569463548831, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1930220', 'n_tokens_mistral': 3188, 'n_tokens_neox': 3350, 'n_words': 611}