From 31bbb0fff7533c2e16cefeb62d71f3406c037d4e Mon Sep 17 00:00:00 2001 From: Patrick Louys Date: Tue, 1 Nov 2016 16:26:05 +0100 Subject: [PATCH] Improved sentences --- 07-inversion-of-control.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/07-inversion-of-control.md b/07-inversion-of-control.md index 5a13293..a5d82de 100644 --- a/07-inversion-of-control.md +++ b/07-inversion-of-control.md @@ -2,11 +2,11 @@ ### Inversion of Control -In the last part you have set up a controller class and generated output with `echo`. But let's not forget that you have a nice object oriented HTTP abstraction available. But right now it's not accessible inside your class. +In the last part you have set up a controller class and generated output with `echo`. But let's not forget that we have a nice object oriented HTTP abstraction available. But right now it's not accessible inside your class. The sane option is to use [inversion of control](http://en.wikipedia.org/wiki/Inversion_of_control). This means that instead of giving the class the responsiblity of creating the object it needs, you just ask for them. This is done with [dependency injection](http://en.wikipedia.org/wiki/Dependency_injection). -If it sounds a little complicated right now, don't worry. Just follow the tutorial and once you see how it is implemented things will make more sense. +If this sounds a little complicated right now, don't worry. Just follow the tutorial and once you see how it is implemented, it will make sense. Change your `Homepage` controller to the following: @@ -33,11 +33,11 @@ class Homepage } ``` -Note that you are [importing](http://php.net/manual/en/language.namespaces.importing.php) `Http\Response` at the top of the file. This means that whenever you use `Response` inside this file, it will resolve to the fully qualified name. +Note that we are [importing](http://php.net/manual/en/language.namespaces.importing.php) `Http\Response` at the top of the file. This means that whenever you use `Response` inside this file, it will resolve to the fully qualified name. -In the constructor you are now explicitly asking for a `Http\Response`. In this case, `Http\Response` is an interface. So any class that implements the interface can be injected. See [type hinting](http://php.net/manual/en/language.oop5.typehinting.php) and [interfaces](http://php.net/manual/en/language.oop5.interfaces.php) for reference. +In the constructor we are now explicitly asking for a `Http\Response`. In this case, `Http\Response` is an interface. So any class that implements the interface can be injected. See [type hinting](http://php.net/manual/en/language.oop5.typehinting.php) and [interfaces](http://php.net/manual/en/language.oop5.interfaces.php) for reference. -Now the code will result in an error because you are not actually injecting anything. So let's fix that in your `Bootstrap.php` where you dispatch when a route was found: +Now the code will result in an error because we are not actually injecting anything. So let's fix that in the `Bootstrap.php` where we dispatch when a route was found: ```php $class = new $className($response);