added code formatting

This commit is contained in:
Patrick 2014-09-17 22:06:16 +02:00
parent 479b5d3ff8
commit 13a5d0fb01
3 changed files with 5 additions and 6 deletions

View file

@ -6,7 +6,7 @@ When I talk about a controller in this tutorial then I am just referring to a cl
Create a new folder inside the `src/` folder with the name `HelloWorld`. This will be where all your hello world related code will end up in. In there, create `HelloWorldController.php`.
```
```php
<?php
namespace Example\HelloWorld;
@ -24,7 +24,7 @@ The autoloader will only work if the namespace of a class matches the file path
Now let's change the hello world route so that it calls your new controller method instead of the closure. Change your `Routes.php` to this:
```
```php
return [
['GET', '/hello-world', [
'Example\HelloWorld\HelloWorldController',
@ -37,7 +37,7 @@ Instead of just a callable you are now passing an array. The first value is the
To make this work, you will also have to do a small refactor to the routing part of the `Bootstrap.php`:
```
```php
case \FastRoute\Dispatcher::FOUND:
$className = $routeInfo[1][0];
$method = $routeInfo[1][1];

View file

@ -10,7 +10,7 @@ If it sounds a little complicated right now, don't worry. Just follow the tutori
Change your `HelloWorldController` to the following:
```
```php
<?php
namespace Example\HelloWorld;
@ -39,7 +39,7 @@ In the contructor you are now explicitly asking for a `Http\Response`. In this c
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:
```
```php
$class = new $className($response);
$class->$method($vars);
```

View file

@ -5,7 +5,6 @@
A dependency injector resolves the dependencies of your class and makes sure that the correct objects are injected when the class is instantiated.
My favorite injector is [Auryn](https://github.com/rdlowrey/Auryn), so install `rdlowrey/auryn` with composer or use one of the alternatives below:
[Pimple](http://pimple.sensiolabs.org/), [Orno DI](https://github.com/orno/di), [PHP-DI](https://github.com/mnapoli/PHP-DI)
Create a new file called `Dependencies.php` in your `src/` folder. In there add the following content: