Controller.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Typemill\Controllers;
  3. /* Use the slim-container */
  4. use Interop\Container\ContainerInterface;
  5. use Typemill\Events\OnPageReady;
  6. abstract class Controller
  7. {
  8. protected $c;
  9. public function __construct(ContainerInterface $c)
  10. {
  11. $this->c = $c;
  12. }
  13. protected function render($response, $route, $data)
  14. {
  15. $data = $this->c->dispatcher->dispatch('onPageReady', new OnPageReady($data))->getData();
  16. if(isset($_SESSION['old']))
  17. {
  18. unset($_SESSION['old']);
  19. }
  20. if($this->c->request->getUri()->getScheme() == 'https')
  21. {
  22. $response = $response->withAddedHeader('Strict-Transport-Security', 'max-age=63072000');
  23. $response = $response->withAddedHeader('Content-Security-Policy', 'default-src https:');
  24. }
  25. $response = $response->withAddedHeader('X-Content-Type-Options', 'nosniff');
  26. $response = $response->withAddedHeader('X-Frame-Options', 'SAMEORIGIN');
  27. $response = $response->withAddedHeader('X-XSS-Protection', '1;mode=block');
  28. $response = $response->withAddedHeader('Referrer-Policy', 'no-referrer-when-downgrade');
  29. return $this->c->view->render($response, $route, $data);
  30. }
  31. protected function render404($response, $data = NULL)
  32. {
  33. return $this->c->view->render($response->withStatus(404), '/404.twig', $data);
  34. }
  35. }