From bc93e70d114daaccb6ccb86cf9af0c98f2faee2d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 May 2019 10:16:03 +0200 Subject: [PATCH 1/2] Force Twig 2.0 for now (testing and compatibility) --- composer.json | 4 +- composer.lock | 164 +++++++++++++++++++++++++++----------------------- 2 files changed, 90 insertions(+), 78 deletions(-) diff --git a/composer.json b/composer.json index d75d0d206..89c0dbea0 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "kodus/psr7-server": "*", "nyholm/psr7": "^1.0", - "twig/twig": "~1.40", + "twig/twig": "~2.0", "erusev/parsedown": "1.6.4", "erusev/parsedown-extra": "~0.7", "symfony/yaml": "~4.2", @@ -49,7 +49,7 @@ "miljar/php-exif": "^0.6.4", "composer/ca-bundle": "^1.0", "dragonmantank/cron-expression": "^1.2", - "phive/twig-extensions-deferred": "^1.0", + "phive/twig-extensions-deferred": "^2.0", "willdurand/negotiation": "^2.3", "itsgoingd/clockwork": "dev-master" }, diff --git a/composer.lock b/composer.lock index 0aa2e4bbe..1a2e4d2d9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b33c701d98f2944f5396b14688b6063e", + "content-hash": "493fc4e440a9ff186cafac7d04296987", "packages": [ { "name": "antoligy/dom-string-iterators", @@ -664,12 +664,12 @@ "source": { "type": "git", "url": "https://github.com/itsgoingd/clockwork.git", - "reference": "2bdf89ecf1ba893f5d0b2e668b94ce167d887216" + "reference": "71f01a566211397afa67b0fa9f8b2405761c3dad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/2bdf89ecf1ba893f5d0b2e668b94ce167d887216", - "reference": "2bdf89ecf1ba893f5d0b2e668b94ce167d887216", + "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/71f01a566211397afa67b0fa9f8b2405761c3dad", + "reference": "71f01a566211397afa67b0fa9f8b2405761c3dad", "shasum": "" }, "require": { @@ -717,7 +717,7 @@ "source": "https://github.com/itsgoingd/clockwork/tree/master", "issues": "https://github.com/itsgoingd/clockwork/issues" }, - "time": "2019-05-25T20:46:20+00:00" + "time": "2019-05-27T11:22:34+00:00" }, { "name": "kodus/psr7-server", @@ -1202,20 +1202,23 @@ }, { "name": "phive/twig-extensions-deferred", - "version": "v1.0.2", + "version": "v2.0.2", "source": { "type": "git", "url": "https://github.com/rybakit/twig-deferred-extension.git", - "reference": "5a2426d622afa74034e754ca5ea1d1ff7887627f" + "reference": "0c2da51bcaeefac09d94d9125d837f8f63b01325" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rybakit/twig-deferred-extension/zipball/5a2426d622afa74034e754ca5ea1d1ff7887627f", - "reference": "5a2426d622afa74034e754ca5ea1d1ff7887627f", + "url": "https://api.github.com/repos/rybakit/twig-deferred-extension/zipball/0c2da51bcaeefac09d94d9125d837f8f63b01325", + "reference": "0c2da51bcaeefac09d94d9125d837f8f63b01325", "shasum": "" }, "require": { - "twig/twig": "~1.18" + "twig/twig": "^2.8" + }, + "require-dev": { + "phpunit/phpunit": "^6.5" }, "type": "library", "autoload": { @@ -1241,7 +1244,7 @@ "lazy", "twig" ], - "time": "2017-03-17T21:39:21+00:00" + "time": "2019-05-24T21:57:45+00:00" }, { "name": "php-http/message-factory", @@ -1835,16 +1838,16 @@ }, { "name": "symfony/console", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "e2840bb38bddad7a0feaf85931e38fdcffdb2f81" + "reference": "7a293c9a4587a92e6a0e81edb0bea54071b1b99d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/e2840bb38bddad7a0feaf85931e38fdcffdb2f81", - "reference": "e2840bb38bddad7a0feaf85931e38fdcffdb2f81", + "url": "https://api.github.com/repos/symfony/console/zipball/7a293c9a4587a92e6a0e81edb0bea54071b1b99d", + "reference": "7a293c9a4587a92e6a0e81edb0bea54071b1b99d", "shasum": "" }, "require": { @@ -1903,25 +1906,32 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2019-04-08T14:23:48+00:00" + "time": "2019-05-09T09:19:46+00:00" }, { "name": "symfony/contracts", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/symfony/contracts.git", - "reference": "d3636025e8253c6144358ec0a62773cae588395b" + "reference": "b6e291a08e6b002fb56aa6f3e2a2beb6674d2b2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/d3636025e8253c6144358ec0a62773cae588395b", - "reference": "d3636025e8253c6144358ec0a62773cae588395b", + "url": "https://api.github.com/repos/symfony/contracts/zipball/b6e291a08e6b002fb56aa6f3e2a2beb6674d2b2f", + "reference": "b6e291a08e6b002fb56aa6f3e2a2beb6674d2b2f", "shasum": "" }, "require": { "php": "^7.1.3" }, + "replace": { + "symfony/cache-contracts": "self.version", + "symfony/event-dispatcher-contracts": "self.version", + "symfony/http-client-contracts": "self.version", + "symfony/service-contracts": "self.version", + "symfony/translation-contracts": "self.version" + }, "require-dev": { "psr/cache": "^1.0", "psr/container": "^1.0", @@ -1930,11 +1940,12 @@ "suggest": { "psr/cache": "When using the Cache contracts", "psr/container": "When using the Service contracts", - "symfony/cache-contracts-implementation": "", + "psr/event-dispatcher": "When using the EventDispatcher contracts", + "symfony/cache-implementation": "", "symfony/event-dispatcher-implementation": "", - "symfony/http-client-contracts-implementation": "", - "symfony/service-contracts-implementation": "", - "symfony/translation-contracts-implementation": "" + "symfony/http-client-implementation": "", + "symfony/service-implementation": "", + "symfony/translation-implementation": "" }, "type": "library", "extra": { @@ -1974,11 +1985,11 @@ "interoperability", "standards" ], - "time": "2019-04-27T14:29:50+00:00" + "time": "2019-05-28T07:50:59+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -2331,16 +2342,16 @@ }, { "name": "symfony/process", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "8cf39fb4ccff793340c258ee7760fd40bfe745fe" + "reference": "57f11a07b34f009ef64a3f95ad218f895ad95374" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/8cf39fb4ccff793340c258ee7760fd40bfe745fe", - "reference": "8cf39fb4ccff793340c258ee7760fd40bfe745fe", + "url": "https://api.github.com/repos/symfony/process/zipball/57f11a07b34f009ef64a3f95ad218f895ad95374", + "reference": "57f11a07b34f009ef64a3f95ad218f895ad95374", "shasum": "" }, "require": { @@ -2376,11 +2387,11 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2019-04-10T16:20:36+00:00" + "time": "2019-05-26T20:47:34+00:00" }, { "name": "symfony/var-dumper", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", @@ -2456,7 +2467,7 @@ }, { "name": "symfony/yaml", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", @@ -2515,21 +2526,22 @@ }, { "name": "twig/twig", - "version": "v1.41.0", + "version": "v2.10.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "575cd5028362da591facde1ef5d7b94553c375c9" + "reference": "5240e21982885b76629552d83b4ebb6d41ccde6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/575cd5028362da591facde1ef5d7b94553c375c9", - "reference": "575cd5028362da591facde1ef5d7b94553c375c9", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/5240e21982885b76629552d83b4ebb6d41ccde6b", + "reference": "5240e21982885b76629552d83b4ebb6d41ccde6b", "shasum": "" }, "require": { - "php": ">=5.4.0", - "symfony/polyfill-ctype": "^1.8" + "php": "^7.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { "psr/container": "^1.0", @@ -2539,7 +2551,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.41-dev" + "dev-master": "2.10-dev" } }, "autoload": { @@ -2577,7 +2589,7 @@ "keywords": [ "templating" ], - "time": "2019-05-14T11:59:08+00:00" + "time": "2019-05-14T12:03:52+00:00" }, { "name": "willdurand/negotiation", @@ -2859,16 +2871,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.3.2", + "version": "1.3.3", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "d17708133b6c276d6e42ef887a877866b909d892" + "reference": "46867cbf8ca9fb8d60c506895449eb799db1184f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/d17708133b6c276d6e42ef887a877866b909d892", - "reference": "d17708133b6c276d6e42ef887a877866b909d892", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/46867cbf8ca9fb8d60c506895449eb799db1184f", + "reference": "46867cbf8ca9fb8d60c506895449eb799db1184f", "shasum": "" }, "require": { @@ -2899,7 +2911,7 @@ "Xdebug", "performance" ], - "time": "2019-01-28T20:25:53+00:00" + "time": "2019-05-27T17:52:04+00:00" }, { "name": "doctrine/instantiator", @@ -4225,16 +4237,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "0.3.3", + "version": "0.3.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "472d3161d289f652713a5e353532fa4592663a57" + "reference": "ab518a5fc8f1d90f58bd2c5552ba915e2c477b66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/472d3161d289f652713a5e353532fa4592663a57", - "reference": "472d3161d289f652713a5e353532fa4592663a57", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ab518a5fc8f1d90f58bd2c5552ba915e2c477b66", + "reference": "ab518a5fc8f1d90f58bd2c5552ba915e2c477b66", "shasum": "" }, "require": { @@ -4268,20 +4280,20 @@ "MIT" ], "description": "PHPDoc parser with support for nullable, intersection and generic types", - "time": "2019-04-23T20:26:19+00:00" + "time": "2019-05-28T11:40:00+00:00" }, { "name": "phpstan/phpstan", - "version": "0.11.7", + "version": "0.11.8", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "32d87d746c70785f78d239855782d27cde0eb6ee" + "reference": "fcf0081bf3a254ddacffa03e78be87842d0c09c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/32d87d746c70785f78d239855782d27cde0eb6ee", - "reference": "32d87d746c70785f78d239855782d27cde0eb6ee", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/fcf0081bf3a254ddacffa03e78be87842d0c09c9", + "reference": "fcf0081bf3a254ddacffa03e78be87842d0c09c9", "shasum": "" }, "require": { @@ -4294,7 +4306,7 @@ "nette/utils": "^2.4.5 || ^3.0", "nikic/php-parser": "^4.0.2", "php": "~7.1", - "phpstan/phpdoc-parser": "^0.3", + "phpstan/phpdoc-parser": "^0.3.4", "symfony/console": "~3.2 || ~4.0", "symfony/finder": "~3.2 || ~4.0" }, @@ -4342,26 +4354,26 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2019-05-19T17:36:42+00:00" + "time": "2019-05-28T19:58:33+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "0.11.1", + "version": "0.11.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "4991f7599646f97f7a2fc2b74ead018f2104ac8e" + "reference": "5685fe48873efc5af1f2cc95d9c1b8ae82c728fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/4991f7599646f97f7a2fc2b74ead018f2104ac8e", - "reference": "4991f7599646f97f7a2fc2b74ead018f2104ac8e", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/5685fe48873efc5af1f2cc95d9c1b8ae82c728fe", + "reference": "5685fe48873efc5af1f2cc95d9c1b8ae82c728fe", "shasum": "" }, "require": { "nikic/php-parser": "^4.0", "php": "~7.1", - "phpstan/phpstan": "^0.11.4" + "phpstan/phpstan": "^0.11.8" }, "require-dev": { "consistence/coding-standard": "^3.0.1", @@ -4393,7 +4405,7 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", - "time": "2019-05-19T19:55:34+00:00" + "time": "2019-05-28T19:54:04+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4649,16 +4661,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.11", + "version": "7.5.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "64cb33f5b520da490a7b13149d39b43cf3c890c6" + "reference": "9ba59817745b0fe0c1a5a3032dfd4a6d2994ad1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/64cb33f5b520da490a7b13149d39b43cf3c890c6", - "reference": "64cb33f5b520da490a7b13149d39b43cf3c890c6", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9ba59817745b0fe0c1a5a3032dfd4a6d2994ad1c", + "reference": "9ba59817745b0fe0c1a5a3032dfd4a6d2994ad1c", "shasum": "" }, "require": { @@ -4729,7 +4741,7 @@ "testing", "xunit" ], - "time": "2019-05-14T04:53:02+00:00" + "time": "2019-05-28T11:59:40+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -5299,7 +5311,7 @@ }, { "name": "symfony/browser-kit", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", @@ -5356,7 +5368,7 @@ }, { "name": "symfony/css-selector", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -5409,7 +5421,7 @@ }, { "name": "symfony/dom-crawler", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", @@ -5466,16 +5478,16 @@ }, { "name": "symfony/finder", - "version": "v4.2.8", + "version": "v4.2.9", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "e45135658bd6c14b61850bf131c4f09a55133f69" + "reference": "e0ff582c4b038567a7c6630f136488b1d793e6a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/e45135658bd6c14b61850bf131c4f09a55133f69", - "reference": "e45135658bd6c14b61850bf131c4f09a55133f69", + "url": "https://api.github.com/repos/symfony/finder/zipball/e0ff582c4b038567a7c6630f136488b1d793e6a9", + "reference": "e0ff582c4b038567a7c6630f136488b1d793e6a9", "shasum": "" }, "require": { @@ -5511,7 +5523,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-04-06T13:51:08+00:00" + "time": "2019-05-26T20:47:34+00:00" }, { "name": "theseer/tokenizer", From 48c281024fc2a41e47a0c319ccf82ed8feb4ce3c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 29 May 2019 13:53:29 +0300 Subject: [PATCH 2/2] Fixed Twig 2.10 errors --- CHANGELOG.md | 7 +++ .../Common/Processors/InitializeProcessor.php | 60 ++++++++++--------- .../Grav/Common/Twig/Node/TwigNodeRender.php | 13 ++-- .../Grav/Common/Twig/Node/TwigNodeScript.php | 23 +++---- .../Grav/Common/Twig/Node/TwigNodeStyle.php | 23 +++---- .../Grav/Common/Twig/Node/TwigNodeSwitch.php | 7 ++- .../Common/Twig/Node/TwigNodeTryCatch.php | 7 ++- 7 files changed, 84 insertions(+), 56 deletions(-) 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")