Controller.php 1.4 KB

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