renamed method to readBySlug. closes #14

This commit is contained in:
Patrick 2015-01-14 21:04:27 +01:00
parent a99778b049
commit 03c012ece5

View file

@ -48,7 +48,7 @@ namespace Example\Page;
interface PageReader interface PageReader
{ {
public function getContentBySlug($slug); public function readBySlug($slug);
} }
``` ```
@ -73,7 +73,7 @@ class FilePageReader implements PageReader
$this->pageFolder = $pageFolder; $this->pageFolder = $pageFolder;
} }
public function getContentBySlug($slug) public function readBySlug($slug)
{ {
return 'I am a placeholder'; return 'I am a placeholder';
} }
@ -106,7 +106,7 @@ Now go back to the `Page` controller and change the `show` method to the followi
public function show($params) public function show($params)
{ {
$slug = $params['slug']; $slug = $params['slug'];
$data['content'] = $this->pageReader->getContentBySlug($slug); $data['content'] = $this->pageReader->readBySlug($slug);
$html = $this->renderer->render('Page', $data); $html = $this->renderer->render('Page', $data);
$this->response->setContent($html); $this->response->setContent($html);
} }
@ -150,7 +150,7 @@ So far so good, now let's make our `FilePageReader` actually do some work.
Again, let's check first that the proper type was passed into the method: Again, let's check first that the proper type was passed into the method:
```php ```php
public function getContentBySlug($slug) public function readBySlug($slug)
{ {
if (!is_string($slug)) { if (!is_string($slug)) {
throw new InvalidArgumentException('slug must be a string'); throw new InvalidArgumentException('slug must be a string');
@ -177,7 +177,7 @@ class InvalidPageException extends Exception
} }
``` ```
Then in the `FilePageReader` file add this code at the end of your `getContentBySlug` method: Then in the `FilePageReader` file add this code at the end of your `readBySlug` method:
``` ```
$path = "$this->pageFolder/$slug.md"; $path = "$this->pageFolder/$slug.md";
@ -201,7 +201,7 @@ public function show($params)
$slug = $params['slug']; $slug = $params['slug'];
try { try {
$data['content'] = $this->pageReader->getContentBySlug($slug); $data['content'] = $this->pageReader->readBySlug($slug);
} catch (InvalidPageException $e) { } catch (InvalidPageException $e) {
$this->response->setStatusCode(404); $this->response->setStatusCode(404);
return $this->response->setContent('404 - Page not found'); return $this->response->setContent('404 - Page not found');