Controller.php 1.5 KB

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