diff --git a/CHANGELOG.md b/CHANGELOG.md index 818c6f039..b2b8535f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.7.0 +## mm/dd/2019 + +1. [](#new) + * Added support for [clokcwork](https://underground.works/clockwork) developer tools + * Added support for Twig 2.10 + # v1.6.10 ## mm/dd/2019 diff --git a/system/src/Grav/Common/Processors/InitializeProcessor.php b/system/src/Grav/Common/Processors/InitializeProcessor.php index 6d23c67b0..d7d050c85 100644 --- a/system/src/Grav/Common/Processors/InitializeProcessor.php +++ b/system/src/Grav/Common/Processors/InitializeProcessor.php @@ -33,11 +33,11 @@ class InitializeProcessor extends ProcessorBase public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { $this->startTimer('_config', 'Configuration'); - $this->initializeConfig(); + $config = $this->initializeConfig(); $this->stopTimer('_config'); $this->startTimer('_logger', 'Logger'); - $this->initializeLogger(); + $this->initializeLogger($config); $this->stopTimer('_logger'); $this->startTimer('_errors', 'Error Handlers Reset'); @@ -70,11 +70,12 @@ class InitializeProcessor extends ProcessorBase } $this->stopTimer('_debugger'); - $this->startTimer('_init', 'Initialize'); - $this->initialize(); + $this->initialize($config); $this->stopTimer('_init'); + $this->initializeSession($config); + $response = $handler->handle($request); if ($clockwork) { @@ -154,7 +155,7 @@ class InitializeProcessor extends ProcessorBase return new Response(200, $headers, json_encode($data)); } - protected function initializeConfig() + protected function initializeConfig(): Config { // Initialize Configuration $grav = $this->container; @@ -162,14 +163,15 @@ class InitializeProcessor extends ProcessorBase $config = $grav['config']; $config->init(); $grav['plugins']->setup(); + + return $config; } - protected function initializeLogger() + protected function initializeLogger(Config $config) { // Initialize Logging $grav = $this->container; - /** @var Config $config */ - $config = $grav['config']; + switch ($config->get('system.log.handler', 'file')) { case 'syslog': $log = $grav['log']; @@ -191,11 +193,8 @@ class InitializeProcessor extends ProcessorBase $this->container['errors']->resetHandlers(); } - protected function initialize() + protected function initialize(Config $config) { - /** @var Config $config */ - $config = $this->container['config']; - // Use output buffering to prevent headers from being sent too early. ob_start(); if ($config->get('system.cache.gzip') && !@ob_start('ob_gzhandler')) { @@ -209,21 +208,6 @@ class InitializeProcessor extends ProcessorBase date_default_timezone_set($timezone); } - // FIXME: Initialize session should happen later after plugins have been loaded. This is a workaround to fix session issues in AWS. - if (isset($this->container['session']) && $config->get('system.session.initialize', true)) { - // TODO: remove in 2.0. - $this->container['accounts']; - - try { - $this->container['session']->init(); - } catch (SessionException $e) { - $this->container['session']->init(); - $message = 'Session corruption detected, restarting session...'; - $this->addMessage($message); - $this->container['messages']->add($message, 'error'); - } - } - /** @var Uri $uri */ $uri = $this->container['uri']; $uri->init(); @@ -240,4 +224,26 @@ class InitializeProcessor extends ProcessorBase $this->container->setLocale(); } + + protected function initializeSession(Config $config) + { + // FIXME: Initialize session should happen later after plugins have been loaded. This is a workaround to fix session issues in AWS. + if (isset($this->container['session']) && $config->get('system.session.initialize', true)) { + $this->startTimer('_session', 'Start Session'); + + // TODO: remove in 2.0. + $this->container['accounts']; + + try { + $this->container['session']->init(); + } catch (SessionException $e) { + $this->container['session']->init(); + $message = 'Session corruption detected, restarting session...'; + $this->addMessage($message); + $this->container['messages']->add($message, 'error'); + } + + $this->stopTimer('_session'); + } + } } diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeRender.php b/system/src/Grav/Common/Twig/Node/TwigNodeRender.php index 753adf01a..593bc3e54 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeRender.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeRender.php @@ -33,7 +33,10 @@ class TwigNodeRender extends Node implements NodeCaptureInterface $tag = null ) { - parent::__construct(['object' => $object, 'layout' => $layout, 'context' => $context], [], $lineno, $tag); + $nodes = ['object' => $object, 'layout' => $layout, 'context' => $context]; + $nodes = array_filter($nodes); + + parent::__construct($nodes, [], $lineno, $tag); } /** * Compiles the node to PHP. @@ -46,15 +49,15 @@ class TwigNodeRender extends Node implements NodeCaptureInterface $compiler->addDebugInfo($this); $compiler->write('$object = ')->subcompile($this->getNode('object'))->raw(';' . PHP_EOL); - $layout = $this->getNode('layout'); - if ($layout) { + if ($this->hasNode('layout')) { + $layout = $this->getNode('layout'); $compiler->write('$layout = ')->subcompile($layout)->raw(';' . PHP_EOL); } else { $compiler->write('$layout = null;' . PHP_EOL); } - $context = $this->getNode('context'); - if ($context) { + if ($this->hasNode('context')) { + $context = $this->getNode('context'); $compiler->write('$attributes = ')->subcompile($context)->raw(';' . PHP_EOL); } else { $compiler->write('$attributes = null;' . PHP_EOL); diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeScript.php b/system/src/Grav/Common/Twig/Node/TwigNodeScript.php index 4f6f7764b..a21a24bc2 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeScript.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeScript.php @@ -29,16 +29,19 @@ class TwigNodeScript extends Node implements NodeCaptureInterface * @param string|null $tag */ public function __construct( - Node $body = null, - AbstractExpression $file = null, - AbstractExpression $group = null, - AbstractExpression $priority = null, - AbstractExpression $attributes = null, + ?Node $body, + ?AbstractExpression $file, + ?AbstractExpression $group, + ?AbstractExpression $priority, + ?AbstractExpression $attributes, $lineno = 0, $tag = null ) { - parent::__construct(['body' => $body, 'file' => $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes], [], $lineno, $tag); + $nodes = ['body' => $body, 'file' => $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes]; + $nodes = array_filter($nodes); + + parent::__construct($nodes, [], $lineno, $tag); } /** * Compiles the node to PHP. @@ -52,7 +55,7 @@ class TwigNodeScript extends Node implements NodeCaptureInterface $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];\n"); - if ($this->getNode('attributes') !== null) { + if ($this->hasNode('attributes')) { $compiler ->write('$attributes = ') ->subcompile($this->getNode('attributes')) @@ -66,7 +69,7 @@ class TwigNodeScript extends Node implements NodeCaptureInterface $compiler->write('$attributes = [];' . "\n"); } - if ($this->getNode('group') !== null) { + if ($this->hasNode('group')) { $compiler ->write("\$attributes['group'] = ") ->subcompile($this->getNode('group')) @@ -78,14 +81,14 @@ class TwigNodeScript extends Node implements NodeCaptureInterface ->write("}\n"); } - if ($this->getNode('priority') !== null) { + if ($this->hasNode('priority')) { $compiler ->write("\$attributes['priority'] = (int)(") ->subcompile($this->getNode('priority')) ->raw(");\n"); } - if ($this->getNode('file') !== null) { + if ($this->hasNode('file')) { $compiler ->write('$assets->addJs(') ->subcompile($this->getNode('file')) diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php b/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php index 22f3302b5..edb24e91b 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php @@ -29,16 +29,19 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface * @param string|null $tag */ public function __construct( - Node $body = null, - AbstractExpression $file = null, - AbstractExpression $group = null, - AbstractExpression $priority = null, - AbstractExpression $attributes = null, + ?Node $body, + ?AbstractExpression $file, + ?AbstractExpression $group, + ?AbstractExpression $priority, + ?AbstractExpression $attributes, $lineno = 0, $tag = null ) { - parent::__construct(['body' => $body, 'file' => $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes], [], $lineno, $tag); + $nodes = ['body' => $body, 'file' => $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes]; + $nodes = array_filter($nodes); + + parent::__construct($nodes, [], $lineno, $tag); } /** * Compiles the node to PHP. @@ -52,7 +55,7 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];\n"); - if ($this->getNode('attributes') !== null) { + if ($this->hasNode('attributes')) { $compiler ->write('$attributes = ') ->subcompile($this->getNode('attributes')) @@ -66,7 +69,7 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface $compiler->write('$attributes = [];' . "\n"); } - if ($this->getNode('group') !== null) { + if ($this->hasNode('group')) { $compiler ->write("\$attributes['group'] = ") ->subcompile($this->getNode('group')) @@ -78,14 +81,14 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface ->write("}\n"); } - if ($this->getNode('priority') !== null) { + if ($this->hasNode('priority')) { $compiler ->write("\$attributes['priority'] = (int)(") ->subcompile($this->getNode('priority')) ->raw(");\n"); } - if ($this->getNode('file') !== null) { + if ($this->hasNode('file')) { $compiler ->write('$assets->addCss(') ->subcompile($this->getNode('file')) diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php b/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php index f29ed6dc0..973461635 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php @@ -30,7 +30,10 @@ class TwigNodeSwitch extends Node $tag = null ) { - parent::__construct(array('value' => $value, 'cases' => $cases, 'default' => $default), array(), $lineno, $tag); + $nodes = ['value' => $value, 'cases' => $cases, 'default' => $default]; + $nodes = array_filter($nodes); + + parent::__construct($nodes, [], $lineno, $tag); } /** @@ -68,7 +71,7 @@ class TwigNodeSwitch extends Node ->write("}\n"); } - if ($this->hasNode('default') && $this->getNode('default') !== null) { + if ($this->hasNode('default')) { $compiler ->write("default:\n") ->write("{\n") diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php index 4028e7416..8a65848d0 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php @@ -28,7 +28,10 @@ class TwigNodeTryCatch extends Node $tag = null ) { - parent::__construct(['try' => $try, 'catch' => $catch], [], $lineno, $tag); + $nodes = ['try' => $try, 'catch' => $catch]; + $nodes = array_filter($nodes); + + parent::__construct($nodes, [], $lineno, $tag); } /** @@ -50,7 +53,7 @@ class TwigNodeTryCatch extends Node ->subcompile($this->getNode('try')) ; - if ($this->hasNode('catch') && null !== $this->getNode('catch')) { + if ($this->hasNode('catch')) { $compiler ->outdent() ->write('} catch (\Exception $e) {' . "\n")