InitializeProcessor.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @package Grav.Common.Processors
  4. *
  5. * @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Processors;
  9. use Grav\Common\Config\Config;
  10. use Grav\Common\Uri;
  11. use Grav\Common\Utils;
  12. class InitializeProcessor extends ProcessorBase implements ProcessorInterface
  13. {
  14. public $id = 'init';
  15. public $title = 'Initialize';
  16. public function process()
  17. {
  18. /** @var Config $config */
  19. $config = $this->container['config'];
  20. $config->debug();
  21. // Use output buffering to prevent headers from being sent too early.
  22. ob_start();
  23. if ($config->get('system.cache.gzip') && !@ob_start('ob_gzhandler')) {
  24. // Enable zip/deflate with a fallback in case of if browser does not support compressing.
  25. ob_start();
  26. }
  27. // Initialize the timezone.
  28. if ($config->get('system.timezone')) {
  29. date_default_timezone_set($this->container['config']->get('system.timezone'));
  30. }
  31. // FIXME: Initialize session should happen later after plugins have been loaded. This is a workaround to fix session issues in AWS.
  32. if (isset($this->container['session']) && $config->get('system.session.initialize', true)) {
  33. $this->container['session']->init();
  34. }
  35. /** @var Uri $uri */
  36. $uri = $this->container['uri'];
  37. $uri->init();
  38. // Redirect pages with trailing slash if configured to do so.
  39. $path = $uri->path() ?: '/';
  40. if ($path !== '/' && $config->get('system.pages.redirect_trailing_slash', false) && Utils::endsWith($path, '/')) {
  41. $this->container->redirect(rtrim($path, '/'), 302);
  42. }
  43. $this->container->setLocale();
  44. }
  45. }