Controller.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 Interop\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. protected function render($response, $route, $data)
  17. {
  18. # why commented this out??
  19. $data = $this->c->dispatcher->dispatch('onPageReady', new OnPageReady($data))->getData();
  20. if(isset($_SESSION['old']))
  21. {
  22. unset($_SESSION['old']);
  23. }
  24. $response = $response->withoutHeader('Server');
  25. $response = $response->withoutHeader('X-Powered-By');
  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. return $this->c->view->render($response, $route, $data);
  35. }
  36. protected function render404($response, $data = NULL)
  37. {
  38. return $this->c->view->render($response->withStatus(404), '/404.twig', $data);
  39. }
  40. }