Update 10-dynamic-pages.md

This commit is contained in:
Patrick Louys 2016-11-01 17:14:02 +01:00 committed by GitHub
parent 20bd93a61c
commit 215c07c94a

View file

@ -65,11 +65,8 @@ class FilePageReader implements PageReader
{ {
private $pageFolder; private $pageFolder;
public function __construct($pageFolder) public function __construct(string $pageFolder)
{ {
if (!is_string($pageFolder)) {
throw new InvalidArgumentException('pageFolder must be a string');
}
$this->pageFolder = $pageFolder; $this->pageFolder = $pageFolder;
} }
@ -84,8 +81,6 @@ As you can see we are requiring the page folder path as a constructor argument.
You could also put the page related things into it's own package and reuse it in different applications. Because we are not tightly coupling things, things are very flexible. You could also put the page related things into it's own package and reuse it in different applications. Because we are not tightly coupling things, things are very flexible.
Because PHP does not have the ability to type hint for scalar values (things like strings and integers), we have to manually check that `$pageFolder` is a string. If we don't do that, there might be a bug in the future that is hard to find if a wrong type is injected. By throwing an exception, this can be caught and debugged immediately.
This will do for now. Let's create a template file for our pages with the name `Page.html` in the `templates` folder. For now just add `{{ content }}` in there. This will do for now. Let's create a template file for our pages with the name `Page.html` in the `templates` folder. For now just add `{{ content }}` in there.
Add the following to your `Dependencies.php` file so that the application know which implementation to inject for our new interface. We also define the the `pageFolder` there. Add the following to your `Dependencies.php` file so that the application know which implementation to inject for our new interface. We also define the the `pageFolder` there.