Controller.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // $data = $this->c->dispatcher->dispatch('onPageReady', new OnPageReady($data))->getData();
  19. if(isset($_SESSION['old']))
  20. {
  21. unset($_SESSION['old']);
  22. }
  23. $response = $response->withoutHeader('Server');
  24. $response = $response->withoutHeader('X-Powered-By');
  25. if($this->c->request->getUri()->getScheme() == 'https')
  26. {
  27. $response = $response->withAddedHeader('Strict-Transport-Security', 'max-age=63072000');
  28. }
  29. $response = $response->withAddedHeader('X-Content-Type-Options', 'nosniff');
  30. $response = $response->withAddedHeader('X-Frame-Options', 'SAMEORIGIN');
  31. $response = $response->withAddedHeader('X-XSS-Protection', '1;mode=block');
  32. $response = $response->withAddedHeader('Referrer-Policy', 'no-referrer-when-downgrade');
  33. return $this->c->view->render($response, $route, $data);
  34. }
  35. protected function render404($response, $data = NULL)
  36. {
  37. return $this->c->view->render($response->withStatus(404), '/404.twig', $data);
  38. }
  39. }