Guest User

Untitled

a guest
Jun 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class HomeHandler implements RequestHandlerInterface
  2. {
  3. private $template;
  4. private $dataService;
  5.  
  6. public function __construct(
  7. TemplateTemplateRendererInterface $template = null,
  8. DataServiceInterface $dataService
  9. ) {
  10. $this->template = $template;
  11. $this->dataService = $dataService;
  12. }
  13.  
  14. public function handle(ServerRequestInterface $request) : ResponseInterface
  15. {
  16. $alias = $request->getAttribute('alias', '');
  17.  
  18. $item = $this->dataService->getItem($alias);
  19.  
  20. if(!isset($item)) {
  21. // Here you need to throw 404 error
  22. }
  23.  
  24. return new HtmlResponse($this->template->render('app::home-page', $item));
  25. }
  26. }
Add Comment
Please, Sign In to add comment