"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/guide/concept-di-container.md" between
yii2-2.0.35.tar.gz and yii2-2.0.36.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

concept-di-container.md  (yii2-2.0.35):concept-di-container.md  (yii2-2.0.36)
skipping to change at line 372 skipping to change at line 372
If you access this controller from browser, you will see an error complaining th e `BookingInterface` If you access this controller from browser, you will see an error complaining th e `BookingInterface`
cannot be instantiated. This is because you need to tell the DI container how to deal with this dependency: cannot be instantiated. This is because you need to tell the DI container how to deal with this dependency:
```php ```php
\Yii::$container->set('app\components\BookingInterface', 'app\components\Booking Service'); \Yii::$container->set('app\components\BookingInterface', 'app\components\Booking Service');
``` ```
Now if you access the controller again, an instance of `app\components\BookingSe rvice` will be Now if you access the controller again, an instance of `app\components\BookingSe rvice` will be
created and injected as the 3rd parameter to the controller's constructor. created and injected as the 3rd parameter to the controller's constructor.
Since Yii 2.0.36 when using PHP 7 action injection is available for both web and
console controllers:
```php
namespace app\controllers;
use yii\web\Controller;
use app\components\BookingInterface;
class HotelController extends Controller
{
public function actionBook($id, BookingInterface $bookingService)
{
$result = $bookingService->book($id);
// ...
}
}
```
Advanced Practical Usage <span id="advanced-practical-usage"></span> Advanced Practical Usage <span id="advanced-practical-usage"></span>
--------------- ---------------
Say we work on API application and have: Say we work on API application and have:
- `app\components\Request` class that extends `yii\web\Request` and provides add itional functionality - `app\components\Request` class that extends `yii\web\Request` and provides add itional functionality
- `app\components\Response` class that extends `yii\web\Response` and should hav e `format` property - `app\components\Response` class that extends `yii\web\Response` and should hav e `format` property
set to `json` on creation set to `json` on creation
- `app\storage\FileStorage` and `app\storage\DocumentsReader` classes that imple ment some logic on - `app\storage\FileStorage` and `app\storage\DocumentsReader` classes that imple ment some logic on
working with documents that are located in some file storage: working with documents that are located in some file storage:
 End of changes. 1 change blocks. 
0 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)