From 215c07c94a53c196a88dc59286c83aba5cabc194 Mon Sep 17 00:00:00 2001 From: Patrick Louys Date: Tue, 1 Nov 2016 17:14:02 +0100 Subject: [PATCH] Update 10-dynamic-pages.md --- 10-dynamic-pages.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/10-dynamic-pages.md b/10-dynamic-pages.md index 5983b4c..ca41bb5 100644 --- a/10-dynamic-pages.md +++ b/10-dynamic-pages.md @@ -65,11 +65,8 @@ class FilePageReader implements PageReader { 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; } @@ -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. -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. 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.