diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0c0eb3..5b396bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,120 @@
+# v1.7.31
+## 03/14/2022
+
+1. [](#new)
+ * Added new local Multiavatar (local generation). **This will be default in Grav 1.8**
+ * Added support to get image size for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533)
+ * Added XSS check for uploaded SVG files before they get stored
+ * Fixed phpstan issues (All level 2, Framework level 5)
+2. [](#improved)
+ * Moved Accounts out of Experimental section of System configuration to new "Accounts" tab
+3. [](#bugfix)
+ * Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504)
+ * Fixed new `Utils::pathinfo()` and `Utils::basename()` being too strict for legacy use [#3542](https://github.com/getgrav/grav/issues/3542)
+ * Fixed non-standard video html atributes generated by `{{ media.html() }}` [#3540](https://github.com/getgrav/grav/issues/3540)
+ * Fixed entity sanitization for XSS detection
+ * Fixed avatar save location when `account://` stream points to custom directory
+ * Fixed bug in `Utils::url()` when path contains part of root
+
+# v1.7.30
+## 02/07/2022
+
+1. [](#new)
+ * Added twig filter `|field_parent` to get parent field name
+2. [](#bugfix)
+ * Fixed error while deleting retina image in admin
+ * Fixed "Page Authors" field in Security tab, wrongly loading and saving the value [#3525](https://github.com/getgrav/grav/issues/3525)
+ * Fixed accounts filter only matches against email address [getgrav/grav-plugin-admin#2224](https://github.com/getgrav/grav-plugin-admin/issues/2224)
+
+# v1.7.29.1
+## 01/31/2022
+
+1. [](#bugfix)
+ * Fixed `Call to undefined method` error when upgrading from Grav 1.6 [#3523](https://github.com/getgrav/grav/issues/3523)
+
+# v1.7.29
+## 01/28/2022
+
+1. [](#new)
+ * Added support for registering assets from `HtmlBlock`
+ * Added unicode-safe `Utils::basename()` and `Utils::pathinfo()` methods
+2. [](#improved)
+ * Improved `Filesystem::basename()` and `Filesystem::pathinfo()` to be unicode-safe
+ * Made path handling unicode-safe, use new `Utils::basename()` and `Utils::pathinfo()` everywhere
+3. [](#bugfix)
+ * Fixed error on thumbnail image creation
+ * Fixed MimeType for `gzip` (`application/x-gzip`)
+
+# v1.7.28
+## 01/24/2022
+
+1. [](#new)
+ * Added links and modules support to `HtmlBlock` class
+ * Added module support for twig script tag: `{% script module 'theme://js/module.mjs' %}`
+ * Added twig tag for links: `{% link icon 'theme://images/favicon.png' priority: 20 with { type: 'image/png' } %}`
+ * Added `HtmlBlock` support for `{% style %}`, `{% script %}` and `{% link %}` tags
+ * Support for page-level `redirect_default_route` frontmatter header override
+3. [](#bugfix)
+ * Fixed XSS check not detecting escaped `:`
+
+# v1.7.27.1
+## 01/12/2022
+
+3. [](#bugfix)
+ * Fixed a typo in CSS Asset pipeline that was erroneously joining files with `;`
+
+# v1.7.27
+## 01/12/2022
+
+1. [](#new)
+ * Support for `YubiKey OTP` 2-Factor authenticator
+ * Added support for generic `assets.link()` for external references. No pipeline support
+ * Added support for `assets.addJsModule()` with full pipeline support
+ * Added `Utils::getExtensionsByMime()` method to get all the registered extensions for the specific mime type
+ * Added `Media::getRoute()` and `Media::getRawRoute()` methods to get page route if available
+ * Added `Medium::getAlternatives()` to be able to list all the retina sizes
+2. [](#improved)
+ * Improved `Utils::download()` method to allow overrides on download name, mime and expires header
+ * Improved `onPageFallBackUrl` event
+ * Reorganized the Asset system configuration blueprint for clarity
+3. [](#bugfix)
+ * Fixed CLI `--env` and `--lang` options having no effect if they aren't added before all the other options
+ * Fixed scaled image medium filename when using non-existing retina file
+ * Fixed an issue with JS `imports` and pipelining Assets
+
+# v1.7.26.1
+## 01/04/2022
+
+3. [](#bugfix)
+ * Fixed `UserObject::getAccess()` after cloning the object
+
+# v1.7.26
+## 01/03/2022
+
+1. [](#new)
+ * Made `Grav::redirect()` to accept `Route` class
+ * Added `translated()` method to `PageTranslateInterface`
+ * Added second parameter to `UserObject::isMyself()` method
+ * Added `UserObject::$isAuthorizedCallable` to allow `$user->isAuthorized()` customization
+ * Use secure session cookies in HTTPS by default (`system.session.secure_https: true`)
+ * Added new `Plugin::inheritedConfigOption()` function to access plugin specific functions for page overrides
+2. [](#improved)
+ * Upgraded vendor libs for PHP 8.1 compatibility
+ * Upgraded to **composer v2.1.14** for PHP 8.1 compatibility
+ * Added third `$name` parameter to `Blueprint::flattenData()` method, useful for flattening repeating data
+ * `ControllerResponseTrait`: Redirect response should be json if the extension is .json
+ * When symlinking Grav install, include also tests
+ * Updated copyright year to `2022`
+3. [](#bugfix)
+ * Fixed bad key lookup in `FlexRelatedDirectoryTrait::getCollectionByProperty()`
+ * Fixed RequestHandlers `NotFoundException` having empty request
+ * Block `.json` files in web server configs
+ * Disabled pretty debug info for Flex as it slows down Twig rendering
+ * Fixed Twig being very slow when template overrides do not exist
+ * Fixed `UserObject::$authorizeCallable` binding to the user object
+ * Fixed `FlexIndex::call()` to return null instead of failing to call undefined method
+ * Fixed Flex directory configuration creating environment configuration when it should not
+
# v1.7.25
## 11/16/2021
diff --git a/README.md b/README.md
index 31a4a7e..f16f62b 100644
--- a/README.md
+++ b/README.md
@@ -2,18 +2,18 @@
[](https://github.com/phpstan/phpstan)
[](https://chat.getgrav.org)
- [](https://github.com/getgrav/grav/actions?query=workflow%3A%22PHP+Tests%22) [](#backers) [](#sponsors)
+ [](https://github.com/getgrav/grav/actions?query=workflow%3A%22PHP+Tests%22) [](#backers) [](#supporters) [](#sponsors)
Grav is a **Fast**, **Simple**, and **Flexible**, file-based Web-platform. There is **Zero** installation required. Just extract the ZIP archive, and you are already up and running. It follows similar principles to other flat-file CMS platforms, but has a different design philosophy than most. Grav comes with a powerful **Package Management System** to allow for simple installation and upgrading of plugins and themes, as well as simple updating of Grav itself.
The underlying architecture of Grav is designed to use well-established and _best-in-class_ technologies to ensure that Grav is simple to use and easy to extend. Some of these key technologies include:
-* [Twig Templating](https://twig.sensiolabs.org/): for powerful control of the user interface
+* [Twig Templating](https://twig.symfony.com/): for powerful control of the user interface
* [Markdown](https://en.wikipedia.org/wiki/Markdown): for easy content creation
* [YAML](https://yaml.org): for simple configuration
* [Parsedown](https://parsedown.org/): for fast Markdown and Markdown Extra support
* [Doctrine Cache](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html): layer for performance
-* [Pimple Dependency Injection Container](https://pimple.sensiolabs.org/): for extensibility and maintainability
+* [Pimple Dependency Injection Container](https://github.com/silexphp/Pimple): for extensibility and maintainability
* [Symfony Event Dispatcher](https://symfony.com/doc/current/components/event_dispatcher/introduction.html): for plugin event handling
* [Symfony Console](https://symfony.com/doc/current/components/console/introduction.html): for CLI interface
* [Gregwar Image Library](https://github.com/Gregwar/Image): for dynamic image manipulation
@@ -117,12 +117,19 @@ If you discover a possible security issue related to Grav or one of its plugins,
* More [Awesome Grav Stuff](https://github.com/getgrav/awesome-grav)
# Backers
-Support Grav with a monthly donation to help us continue development. [[Become a backer](https://opencollective.com/grav#backer)]
+Support Grav with a monthly donation to help us continue development. [[Become a backer](https://opencollective.com/grav/contribute)]
+
+# Supporters
+Support Grav with a monthly donation to help us continue development. [[Become a supporter](https://opencollective.com/grav/contribute)]
+
+
+
+
# Sponsors
-Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/grav#sponsor)]
+Support Grav with a yearly donation to help us continue development. [[Become a sponsor](https://opencollective.com/grav/contribute)]
diff --git a/assets/.gitkeep b/assets/.gitkeep
index 33a9aed..8efbf1f 100644
--- a/assets/.gitkeep
+++ b/assets/.gitkeep
@@ -1 +1 @@
-/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
+/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
diff --git a/bin/composer.phar b/bin/composer.phar
index 3791ce3..f046190 100755
Binary files a/bin/composer.phar and b/bin/composer.phar differ
diff --git a/bin/gpm b/bin/gpm
index a2eebc6..12d0c3d 100755
--- a/bin/gpm
+++ b/bin/gpm
@@ -2,7 +2,7 @@
user/pages/14.api/default.17.md",
"post-create-project-cmd": "bin/grav install",
- "phpstan": "vendor/bin/phpstan analyse -l 1 -c ./tests/phpstan/phpstan.neon --memory-limit=520M system/src",
- "phpstan-framework": "vendor/bin/phpstan analyse -l 3 -c ./tests/phpstan/phpstan.neon --memory-limit=480M system/src/Grav/Framework system/src/Grav/Events system/src/Grav/Installer",
+ "phpstan": "vendor/bin/phpstan analyse -l 2 -c ./tests/phpstan/phpstan.neon --memory-limit=720M system/src",
+ "phpstan-framework": "vendor/bin/phpstan analyse -l 5 -c ./tests/phpstan/phpstan.neon --memory-limit=480M system/src/Grav/Framework system/src/Grav/Events system/src/Grav/Installer",
"phpstan-plugins": "vendor/bin/phpstan analyse -l 1 -c ./tests/phpstan/plugins.neon --memory-limit=400M user/plugins",
"test": "vendor/bin/codecept run unit",
"test-windows": "vendor\\bin\\codecept run unit"
diff --git a/composer.lock b/composer.lock
index 3b66c8a..d0dc8df 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,56 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "072f00e1bf64b4ef43f7125fe80b15a7",
+ "content-hash": "f0530b0fd3e574fef0852376653da5a0",
"packages": [
- {
- "name": "antoligy/dom-string-iterators",
- "version": "v1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/antoligy/dom-string-iterators.git",
- "reference": "fae88f66e1970d68c5585fc42db44f1217bf74e6"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/antoligy/dom-string-iterators/zipball/fae88f66e1970d68c5585fc42db44f1217bf74e6",
- "reference": "fae88f66e1970d68c5585fc42db44f1217bf74e6",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "CC0-1.0"
- ],
- "authors": [
- {
- "name": "Alex Wilson",
- "email": "a@ax.gy"
- },
- {
- "name": "Kornel Lesinski",
- "email": "pornel@pornel.net"
- },
- {
- "name": "Patrick Galbraith",
- "email": "patrick.j.galbraith@gmail.com"
- }
- ],
- "description": "Composer package for DOMWordsIterator and DOMLettersIterator",
- "support": {
- "issues": "https://github.com/antoligy/dom-string-iterators/issues",
- "source": "https://github.com/antoligy/dom-string-iterators/tree/v1.0.1"
- },
- "time": "2018-02-03T16:01:11+00:00"
- },
{
"name": "composer/ca-bundle",
"version": "1.3.1",
@@ -596,16 +548,16 @@
},
{
"name": "filp/whoops",
- "version": "2.14.4",
+ "version": "2.14.5",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
- "reference": "f056f1fe935d9ed86e698905a957334029899895"
+ "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/filp/whoops/zipball/f056f1fe935d9ed86e698905a957334029899895",
- "reference": "f056f1fe935d9ed86e698905a957334029899895",
+ "url": "https://api.github.com/repos/filp/whoops/zipball/a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
+ "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
"shasum": ""
},
"require": {
@@ -655,7 +607,7 @@
],
"support": {
"issues": "https://github.com/filp/whoops/issues",
- "source": "https://github.com/filp/whoops/tree/2.14.4"
+ "source": "https://github.com/filp/whoops/tree/2.14.5"
},
"funding": [
{
@@ -663,7 +615,7 @@
"type": "github"
}
],
- "time": "2021-10-03T12:00:00+00:00"
+ "time": "2022-01-07T12:00:00+00:00"
},
{
"name": "getgrav/cache",
@@ -812,12 +764,12 @@
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\Psr7\\": "src/"
- },
"files": [
"src/functions_include.php"
- ]
+ ],
+ "psr-4": {
+ "GuzzleHttp\\Psr7\\": "src/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -888,22 +840,21 @@
},
{
"name": "itsgoingd/clockwork",
- "version": "v5.1.1",
+ "version": "v5.1.5",
"source": {
"type": "git",
"url": "https://github.com/itsgoingd/clockwork.git",
- "reference": "2daf30fa6dfc5a1ccfdb2142df59243a72c473d8"
+ "reference": "6a7b3942224fa53cf3704d9adba636e1f3dfeb9a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/2daf30fa6dfc5a1ccfdb2142df59243a72c473d8",
- "reference": "2daf30fa6dfc5a1ccfdb2142df59243a72c473d8",
+ "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/6a7b3942224fa53cf3704d9adba636e1f3dfeb9a",
+ "reference": "6a7b3942224fa53cf3704d9adba636e1f3dfeb9a",
"shasum": ""
},
"require": {
"ext-json": "*",
- "php": ">=5.6",
- "psr/log": "1.* || ^2.0"
+ "php": ">=5.6"
},
"type": "library",
"extra": {
@@ -945,7 +896,7 @@
],
"support": {
"issues": "https://github.com/itsgoingd/clockwork/issues",
- "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.1"
+ "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.5"
},
"funding": [
{
@@ -953,20 +904,20 @@
"type": "github"
}
],
- "time": "2021-11-01T17:38:35+00:00"
+ "time": "2022-02-13T22:57:42+00:00"
},
{
"name": "league/climate",
- "version": "3.7.0",
+ "version": "3.8.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/climate.git",
- "reference": "5c717c3032c5118be7ad2395dbe0813d9894e8c7"
+ "reference": "22243322c6f049240e0fa6ad6c3873343b6f6055"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/climate/zipball/5c717c3032c5118be7ad2395dbe0813d9894e8c7",
- "reference": "5c717c3032c5118be7ad2395dbe0813d9894e8c7",
+ "url": "https://api.github.com/repos/thephpleague/climate/zipball/22243322c6f049240e0fa6ad6c3873343b6f6055",
+ "reference": "22243322c6f049240e0fa6ad6c3873343b6f6055",
"shasum": ""
},
"require": {
@@ -1016,9 +967,9 @@
],
"support": {
"issues": "https://github.com/thephpleague/climate/issues",
- "source": "https://github.com/thephpleague/climate/tree/3.7.0"
+ "source": "https://github.com/thephpleague/climate/tree/3.8.1"
},
- "time": "2021-01-10T20:18:52+00:00"
+ "time": "2022-01-23T14:38:49+00:00"
},
{
"name": "matthiasmullie/minify",
@@ -1153,25 +1104,26 @@
},
{
"name": "maximebf/debugbar",
- "version": "v1.17.3",
+ "version": "v1.18.0",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
- "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c"
+ "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e8ac3499af0ea5b440908e06cc0abe5898008b3c",
- "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c",
+ "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6",
+ "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6",
"shasum": ""
},
"require": {
"php": "^7.1|^8",
"psr/log": "^1|^2|^3",
- "symfony/var-dumper": "^2.6|^3|^4|^5"
+ "symfony/var-dumper": "^2.6|^3|^4|^5|^6"
},
"require-dev": {
- "phpunit/phpunit": "^7.5.20 || ^9.4.2"
+ "phpunit/phpunit": "^7.5.20 || ^9.4.2",
+ "twig/twig": "^1.38|^2.7|^3.0"
},
"suggest": {
"kriswallsmith/assetic": "The best way to manage assets",
@@ -1212,9 +1164,9 @@
],
"support": {
"issues": "https://github.com/maximebf/php-debugbar/issues",
- "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.3"
+ "source": "https://github.com/maximebf/php-debugbar/tree/v1.18.0"
},
- "time": "2021-10-19T12:33:27+00:00"
+ "time": "2021-12-27T18:49:48+00:00"
},
{
"name": "miljar/php-exif",
@@ -1363,17 +1315,64 @@
"time": "2021-05-28T08:32:12+00:00"
},
{
- "name": "nyholm/psr7",
- "version": "1.4.1",
+ "name": "multiavatar/multiavatar-php",
+ "version": "v1.0.5",
"source": {
"type": "git",
- "url": "https://github.com/Nyholm/psr7.git",
- "reference": "2212385b47153ea71b1c1b1374f8cb5e4f7892ec"
+ "url": "https://github.com/multiavatar/multiavatar-php.git",
+ "reference": "13a62a656b1c2ca1c62dee57b4c1d8a3b04e6574"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Nyholm/psr7/zipball/2212385b47153ea71b1c1b1374f8cb5e4f7892ec",
- "reference": "2212385b47153ea71b1c1b1374f8cb5e4f7892ec",
+ "url": "https://api.github.com/repos/multiavatar/multiavatar-php/zipball/13a62a656b1c2ca1c62dee57b4c1d8a3b04e6574",
+ "reference": "13a62a656b1c2ca1c62dee57b4c1d8a3b04e6574",
+ "shasum": ""
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "Multiavatar.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "proprietary"
+ ],
+ "authors": [
+ {
+ "name": "Gie Katon",
+ "homepage": "https://giekaton.com"
+ }
+ ],
+ "description": "Multicultural Avatar Generator",
+ "homepage": "https://multiavatar.com",
+ "keywords": [
+ "avatar",
+ "creator",
+ "generator",
+ "image",
+ "maker",
+ "picture",
+ "profile"
+ ],
+ "support": {
+ "issues": "https://github.com/multiavatar/multiavatar-php/issues",
+ "source": "https://github.com/multiavatar/multiavatar-php/tree/v1.0.5"
+ },
+ "time": "2021-03-02T07:33:46+00:00"
+ },
+ {
+ "name": "nyholm/psr7",
+ "version": "1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Nyholm/psr7.git",
+ "reference": "1461e07a0f2a975a52082ca3b769ca912b816226"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Nyholm/psr7/zipball/1461e07a0f2a975a52082ca3b769ca912b816226",
+ "reference": "1461e07a0f2a975a52082ca3b769ca912b816226",
"shasum": ""
},
"require": {
@@ -1425,7 +1424,7 @@
],
"support": {
"issues": "https://github.com/Nyholm/psr7/issues",
- "source": "https://github.com/Nyholm/psr7/tree/1.4.1"
+ "source": "https://github.com/Nyholm/psr7/tree/1.5.0"
},
"funding": [
{
@@ -1437,7 +1436,7 @@
"type": "github"
}
],
- "time": "2021-07-02T08:32:20+00:00"
+ "time": "2022-02-02T18:37:57+00:00"
},
{
"name": "nyholm/psr7-server",
@@ -1561,29 +1560,29 @@
},
{
"name": "pimple/pimple",
- "version": "v3.3.1",
+ "version": "v3.5.0",
"source": {
"type": "git",
"url": "https://github.com/silexphp/Pimple.git",
- "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0"
+ "reference": "a94b3a4db7fb774b3d78dad2315ddc07629e1bed"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/silexphp/Pimple/zipball/21e45061c3429b1e06233475cc0e1f6fc774d5b0",
- "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0",
+ "url": "https://api.github.com/repos/silexphp/Pimple/zipball/a94b3a4db7fb774b3d78dad2315ddc07629e1bed",
+ "reference": "a94b3a4db7fb774b3d78dad2315ddc07629e1bed",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
- "psr/container": "^1.0"
+ "psr/container": "^1.1 || ^2.0"
},
"require-dev": {
- "symfony/phpunit-bridge": "^5.0"
+ "symfony/phpunit-bridge": "^5.4@dev"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.3.x-dev"
+ "dev-master": "3.4.x-dev"
}
},
"autoload": {
@@ -1608,9 +1607,9 @@
"dependency injection"
],
"support": {
- "source": "https://github.com/silexphp/Pimple/tree/v3.3.1"
+ "source": "https://github.com/silexphp/Pimple/tree/v3.5.0"
},
- "time": "2020-11-24T20:35:42+00:00"
+ "time": "2021-10-28T11:13:42+00:00"
},
{
"name": "psr/cache",
@@ -1663,27 +1662,22 @@
},
{
"name": "psr/container",
- "version": "1.0.0",
+ "version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
- "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
+ "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
- "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
+ "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf",
+ "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf",
"shasum": ""
},
"require": {
- "php": ">=5.3.0"
+ "php": ">=7.2.0"
},
"type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
@@ -1696,7 +1690,7 @@
"authors": [
{
"name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
+ "homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
@@ -1710,9 +1704,9 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
- "source": "https://github.com/php-fig/container/tree/master"
+ "source": "https://github.com/php-fig/container/tree/1.1.1"
},
- "time": "2017-02-14T16:28:37+00:00"
+ "time": "2021-03-05T17:36:06+00:00"
},
{
"name": "psr/http-factory",
@@ -2128,43 +2122,41 @@
},
{
"name": "rockettheme/toolbox",
- "version": "1.5.10",
+ "version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/rockettheme/toolbox.git",
- "reference": "d9738de013fa12df77754a0f11dded220b246efb"
+ "reference": "fdf0195ced25b83525d3b084c3e81f05de96ac8c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/rockettheme/toolbox/zipball/d9738de013fa12df77754a0f11dded220b246efb",
- "reference": "d9738de013fa12df77754a0f11dded220b246efb",
+ "url": "https://api.github.com/repos/rockettheme/toolbox/zipball/fdf0195ced25b83525d3b084c3e81f05de96ac8c",
+ "reference": "fdf0195ced25b83525d3b084c3e81f05de96ac8c",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=5.6.0",
- "pimple/pimple": "~3.0",
- "symfony/event-dispatcher": "^3.4|^4.0",
- "symfony/yaml": "^3.4|^4.0"
- },
- "require-dev": {
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-deprecation-rules": "^0.12",
- "phpunit/phpunit": "~7.0"
+ "pimple/pimple": "^3.0",
+ "symfony/event-dispatcher": "^3.4|^4.0|^5.0",
+ "symfony/yaml": "^3.4|^4.0|^5.0"
},
"type": "library",
"autoload": {
"psr-4": {
- "RocketTheme\\Toolbox\\ArrayTraits\\": "ArrayTraits/src",
- "RocketTheme\\Toolbox\\Blueprints\\": "Blueprints/src",
- "RocketTheme\\Toolbox\\Compat\\": "Compat/src",
"RocketTheme\\Toolbox\\DI\\": "DI/src",
- "RocketTheme\\Toolbox\\Event\\": "Event/src",
"RocketTheme\\Toolbox\\File\\": "File/src",
- "RocketTheme\\Toolbox\\ResourceLocator\\": "ResourceLocator/src",
+ "RocketTheme\\Toolbox\\Event\\": "Event/src",
+ "RocketTheme\\Toolbox\\Compat\\": "Compat/src",
"RocketTheme\\Toolbox\\Session\\": "Session/src",
- "RocketTheme\\Toolbox\\StreamWrapper\\": "StreamWrapper/src"
- }
+ "RocketTheme\\Toolbox\\Blueprints\\": "Blueprints/src",
+ "RocketTheme\\Toolbox\\ArrayTraits\\": "ArrayTraits/src",
+ "RocketTheme\\Toolbox\\StreamWrapper\\": "StreamWrapper/src",
+ "RocketTheme\\Toolbox\\ResourceLocator\\": "ResourceLocator/src"
+ },
+ "exclude-from-classmap": [
+ "**/tests/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2178,9 +2170,9 @@
],
"support": {
"issues": "https://github.com/rockettheme/toolbox/issues",
- "source": "https://github.com/rockettheme/toolbox/tree/1.5.10"
+ "source": "https://github.com/rockettheme/toolbox/tree/1.6.1"
},
- "time": "2021-09-29T16:50:13+00:00"
+ "time": "2022-02-08T08:36:03+00:00"
},
{
"name": "seld/cli-prompt",
@@ -2239,16 +2231,16 @@
},
{
"name": "symfony/console",
- "version": "v4.4.33",
+ "version": "v4.4.38",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "8dbd23ef7a8884051482183ddee8d9061b5feed0"
+ "reference": "5a50085bf5460f0c0d60a50b58388c1249826b8a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/8dbd23ef7a8884051482183ddee8d9061b5feed0",
- "reference": "8dbd23ef7a8884051482183ddee8d9061b5feed0",
+ "url": "https://api.github.com/repos/symfony/console/zipball/5a50085bf5460f0c0d60a50b58388c1249826b8a",
+ "reference": "5a50085bf5460f0c0d60a50b58388c1249826b8a",
"shasum": ""
},
"require": {
@@ -2309,7 +2301,7 @@
"description": "Eases the creation of beautiful and testable command line interfaces",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/console/tree/v4.4.33"
+ "source": "https://github.com/symfony/console/tree/v4.4.38"
},
"funding": [
{
@@ -2325,25 +2317,25 @@
"type": "tidelift"
}
],
- "time": "2021-10-25T16:36:08+00:00"
+ "time": "2022-01-30T21:23:57+00:00"
},
{
"name": "symfony/contracts",
- "version": "v1.1.10",
+ "version": "v1.1.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/contracts.git",
- "reference": "011c20407c4b99d454f44021d023fb39ce23b73d"
+ "reference": "cf2984f7a99bfae197f9c96f5a16a4041ff6ffb1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/contracts/zipball/011c20407c4b99d454f44021d023fb39ce23b73d",
- "reference": "011c20407c4b99d454f44021d023fb39ce23b73d",
+ "url": "https://api.github.com/repos/symfony/contracts/zipball/cf2984f7a99bfae197f9c96f5a16a4041ff6ffb1",
+ "reference": "cf2984f7a99bfae197f9c96f5a16a4041ff6ffb1",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
- "psr/cache": "^1.0",
+ "psr/cache": "^1.0|^2.0|^3.0",
"psr/container": "^1.0"
},
"replace": {
@@ -2367,7 +2359,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.1-dev"
+ "dev-main": "1.1-dev"
}
},
"autoload": {
@@ -2403,7 +2395,7 @@
"standards"
],
"support": {
- "source": "https://github.com/symfony/contracts/tree/v1.1.10"
+ "source": "https://github.com/symfony/contracts/tree/v1.1.11"
},
"funding": [
{
@@ -2419,20 +2411,20 @@
"type": "tidelift"
}
],
- "time": "2020-09-02T16:08:58+00:00"
+ "time": "2021-11-04T13:32:43+00:00"
},
{
"name": "symfony/event-dispatcher",
- "version": "v4.4.30",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
- "reference": "2fe81680070043c4c80e7cedceb797e34f377bac"
+ "reference": "3ccfcfb96ecce1217d7b0875a0736976bc6e63dc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2fe81680070043c4c80e7cedceb797e34f377bac",
- "reference": "2fe81680070043c4c80e7cedceb797e34f377bac",
+ "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/3ccfcfb96ecce1217d7b0875a0736976bc6e63dc",
+ "reference": "3ccfcfb96ecce1217d7b0875a0736976bc6e63dc",
"shasum": ""
},
"require": {
@@ -2487,7 +2479,7 @@
"description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/event-dispatcher/tree/v4.4.30"
+ "source": "https://github.com/symfony/event-dispatcher/tree/v4.4.37"
},
"funding": [
{
@@ -2503,20 +2495,20 @@
"type": "tidelift"
}
],
- "time": "2021-08-04T20:31:23+00:00"
+ "time": "2022-01-02T09:41:36+00:00"
},
{
"name": "symfony/http-client",
- "version": "v4.4.33",
+ "version": "v4.4.39",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-client.git",
- "reference": "9a5fdf129b522a06a46d13400500d326c41d8a73"
+ "reference": "40342406a975385c5b21e929df46e3fc0278853d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/http-client/zipball/9a5fdf129b522a06a46d13400500d326c41d8a73",
- "reference": "9a5fdf129b522a06a46d13400500d326c41d8a73",
+ "url": "https://api.github.com/repos/symfony/http-client/zipball/40342406a975385c5b21e929df46e3fc0278853d",
+ "reference": "40342406a975385c5b21e929df46e3fc0278853d",
"shasum": ""
},
"require": {
@@ -2568,7 +2560,7 @@
"description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/http-client/tree/v4.4.33"
+ "source": "https://github.com/symfony/http-client/tree/v4.4.39"
},
"funding": [
{
@@ -2584,25 +2576,28 @@
"type": "tidelift"
}
],
- "time": "2021-10-18T16:39:13+00:00"
+ "time": "2022-02-28T13:17:32+00:00"
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce"
+ "reference": "30885182c981ab175d4d034db0f6f469898070ab"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce",
- "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab",
+ "reference": "30885182c981ab175d4d034db0f6f469898070ab",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
+ "provide": {
+ "ext-ctype": "*"
+ },
"suggest": {
"ext-ctype": "For best performance"
},
@@ -2617,12 +2612,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Ctype\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Ctype\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2647,7 +2642,7 @@
"portable"
],
"support": {
- "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-ctype/tree/v1.25.0"
},
"funding": [
{
@@ -2663,25 +2658,28 @@
"type": "tidelift"
}
],
- "time": "2021-02-19T12:13:01+00:00"
+ "time": "2021-10-20T20:35:02+00:00"
},
{
"name": "symfony/polyfill-iconv",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-iconv.git",
- "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933"
+ "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/63b5bb7db83e5673936d6e3b8b3e022ff6474933",
- "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933",
+ "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/f1aed619e28cb077fc83fac8c4c0383578356e40",
+ "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
+ "provide": {
+ "ext-iconv": "*"
+ },
"suggest": {
"ext-iconv": "For best performance"
},
@@ -2696,12 +2694,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Iconv\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Iconv\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2727,7 +2725,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-iconv/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-iconv/tree/v1.25.0"
},
"funding": [
{
@@ -2743,25 +2741,28 @@
"type": "tidelift"
}
],
- "time": "2021-05-27T09:27:20+00:00"
+ "time": "2022-01-04T09:04:05+00:00"
},
{
"name": "symfony/polyfill-mbstring",
- "version": "v1.23.1",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
- "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6"
+ "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6",
- "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
+ "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
+ "provide": {
+ "ext-mbstring": "*"
+ },
"suggest": {
"ext-mbstring": "For best performance"
},
@@ -2776,12 +2777,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Mbstring\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2807,7 +2808,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.25.0"
},
"funding": [
{
@@ -2823,11 +2824,11 @@
"type": "tidelift"
}
],
- "time": "2021-05-27T12:26:48+00:00"
+ "time": "2021-11-30T18:21:41+00:00"
},
{
"name": "symfony/polyfill-php74",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php74.git",
@@ -2853,12 +2854,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Php74\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php74\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2887,7 +2888,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-php74/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-php74/tree/v1.25.0"
},
"funding": [
{
@@ -2907,16 +2908,16 @@
},
{
"name": "symfony/polyfill-php80",
- "version": "v1.23.1",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
- "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be"
+ "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be",
- "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be",
+ "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4407588e0d3f1f52efb65fbe92babe41f37fe50c",
+ "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c",
"shasum": ""
},
"require": {
@@ -2933,12 +2934,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Php80\\": ""
- },
"files": [
"bootstrap.php"
],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php80\\": ""
+ },
"classmap": [
"Resources/stubs"
]
@@ -2970,7 +2971,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-php80/tree/v1.25.0"
},
"funding": [
{
@@ -2986,20 +2987,20 @@
"type": "tidelift"
}
],
- "time": "2021-07-28T13:41:28+00:00"
+ "time": "2022-03-04T08:16:47+00:00"
},
{
"name": "symfony/polyfill-php81",
- "version": "v1.23.0",
+ "version": "v1.25.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php81.git",
- "reference": "e66119f3de95efc359483f810c4c3e6436279436"
+ "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/e66119f3de95efc359483f810c4c3e6436279436",
- "reference": "e66119f3de95efc359483f810c4c3e6436279436",
+ "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/5de4ba2d41b15f9bd0e19b2ab9674135813ec98f",
+ "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f",
"shasum": ""
},
"require": {
@@ -3016,12 +3017,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Php81\\": ""
- },
"files": [
"bootstrap.php"
],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php81\\": ""
+ },
"classmap": [
"Resources/stubs"
]
@@ -3049,7 +3050,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-php81/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-php81/tree/v1.25.0"
},
"funding": [
{
@@ -3065,20 +3066,20 @@
"type": "tidelift"
}
],
- "time": "2021-05-21T13:25:03+00:00"
+ "time": "2021-09-13T13:58:11+00:00"
},
{
"name": "symfony/process",
- "version": "v4.4.30",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
- "reference": "13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d"
+ "reference": "b2d924e5a4cb284f293d5092b1dbf0d364cb8b67"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/process/zipball/13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d",
- "reference": "13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d",
+ "url": "https://api.github.com/repos/symfony/process/zipball/b2d924e5a4cb284f293d5092b1dbf0d364cb8b67",
+ "reference": "b2d924e5a4cb284f293d5092b1dbf0d364cb8b67",
"shasum": ""
},
"require": {
@@ -3111,7 +3112,7 @@
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/process/tree/v4.4.30"
+ "source": "https://github.com/symfony/process/tree/v4.4.37"
},
"funding": [
{
@@ -3127,20 +3128,20 @@
"type": "tidelift"
}
],
- "time": "2021-08-04T20:31:23+00:00"
+ "time": "2022-01-27T17:14:04+00:00"
},
{
"name": "symfony/var-dumper",
- "version": "v4.4.33",
+ "version": "v4.4.39",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-dumper.git",
- "reference": "50286e2b7189bfb4f419c0731e86632cddf7c5ee"
+ "reference": "35237c5e5dcb6593a46a860ba5b29c1d4683d80e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/var-dumper/zipball/50286e2b7189bfb4f419c0731e86632cddf7c5ee",
- "reference": "50286e2b7189bfb4f419c0731e86632cddf7c5ee",
+ "url": "https://api.github.com/repos/symfony/var-dumper/zipball/35237c5e5dcb6593a46a860ba5b29c1d4683d80e",
+ "reference": "35237c5e5dcb6593a46a860ba5b29c1d4683d80e",
"shasum": ""
},
"require": {
@@ -3200,7 +3201,7 @@
"dump"
],
"support": {
- "source": "https://github.com/symfony/var-dumper/tree/v4.4.33"
+ "source": "https://github.com/symfony/var-dumper/tree/v4.4.39"
},
"funding": [
{
@@ -3216,20 +3217,20 @@
"type": "tidelift"
}
],
- "time": "2021-10-25T20:24:58+00:00"
+ "time": "2022-02-25T10:38:15+00:00"
},
{
"name": "symfony/yaml",
- "version": "v4.4.29",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "3abcc4db06d4e776825eaa3ed8ad924d5bc7432a"
+ "reference": "d7f637cc0f0cc14beb0984f2bb50da560b271311"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/3abcc4db06d4e776825eaa3ed8ad924d5bc7432a",
- "reference": "3abcc4db06d4e776825eaa3ed8ad924d5bc7432a",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/d7f637cc0f0cc14beb0984f2bb50da560b271311",
+ "reference": "d7f637cc0f0cc14beb0984f2bb50da560b271311",
"shasum": ""
},
"require": {
@@ -3271,7 +3272,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/yaml/tree/v4.4.29"
+ "source": "https://github.com/symfony/yaml/tree/v4.4.37"
},
"funding": [
{
@@ -3287,20 +3288,20 @@
"type": "tidelift"
}
],
- "time": "2021-07-27T16:19:30+00:00"
+ "time": "2022-01-24T20:11:01+00:00"
},
{
"name": "twig/twig",
- "version": "v1.44.5",
+ "version": "v1.44.6",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
- "reference": "dd4353357c5a116322e92a00d16043a31881a81e"
+ "reference": "ae39480f010ef88adc7938503c9b02d3baf2f3b3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/twigphp/Twig/zipball/dd4353357c5a116322e92a00d16043a31881a81e",
- "reference": "dd4353357c5a116322e92a00d16043a31881a81e",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/ae39480f010ef88adc7938503c9b02d3baf2f3b3",
+ "reference": "ae39480f010ef88adc7938503c9b02d3baf2f3b3",
"shasum": ""
},
"require": {
@@ -3353,7 +3354,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
- "source": "https://github.com/twigphp/Twig/tree/v1.44.5"
+ "source": "https://github.com/twigphp/Twig/tree/v1.44.6"
},
"funding": [
{
@@ -3365,20 +3366,20 @@
"type": "tidelift"
}
],
- "time": "2021-09-17T08:35:19+00:00"
+ "time": "2021-11-25T13:31:46+00:00"
},
{
"name": "willdurand/negotiation",
- "version": "3.0.0",
+ "version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/willdurand/Negotiation.git",
- "reference": "04e14f38d4edfcc974114a07d2777d90c98f3d9c"
+ "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/willdurand/Negotiation/zipball/04e14f38d4edfcc974114a07d2777d90c98f3d9c",
- "reference": "04e14f38d4edfcc974114a07d2777d90c98f3d9c",
+ "url": "https://api.github.com/repos/willdurand/Negotiation/zipball/68e9ea0553ef6e2ee8db5c1d98829f111e623ec2",
+ "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2",
"shasum": ""
},
"require": {
@@ -3419,9 +3420,9 @@
],
"support": {
"issues": "https://github.com/willdurand/Negotiation/issues",
- "source": "https://github.com/willdurand/Negotiation/tree/3.0.0"
+ "source": "https://github.com/willdurand/Negotiation/tree/3.1.0"
},
- "time": "2020-09-25T08:01:41+00:00"
+ "time": "2022-01-30T20:08:53+00:00"
}
],
"packages-dev": [
@@ -3490,23 +3491,23 @@
},
{
"name": "codeception/codeception",
- "version": "4.1.22",
+ "version": "4.1.30",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
- "reference": "9777ec3690ceedc4bce2ed13af7af4ca4ee3088f"
+ "reference": "a035d77d070fa57fad438e07a65447aeca248c45"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Codeception/Codeception/zipball/9777ec3690ceedc4bce2ed13af7af4ca4ee3088f",
- "reference": "9777ec3690ceedc4bce2ed13af7af4ca4ee3088f",
+ "url": "https://api.github.com/repos/Codeception/Codeception/zipball/a035d77d070fa57fad438e07a65447aeca248c45",
+ "reference": "a035d77d070fa57fad438e07a65447aeca248c45",
"shasum": ""
},
"require": {
"behat/gherkin": "^4.4.0",
- "codeception/lib-asserts": "^1.0",
+ "codeception/lib-asserts": "^1.0 | 2.0.*@dev",
"codeception/phpunit-wrapper": ">6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.1.1 | ^9.0",
- "codeception/stub": "^2.0 | ^3.0",
+ "codeception/stub": "^2.0 | ^3.0 | ^4.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
@@ -3519,11 +3520,11 @@
"symfony/yaml": ">=2.7 <6.0"
},
"require-dev": {
- "codeception/module-asserts": "1.*@dev",
- "codeception/module-cli": "1.*@dev",
- "codeception/module-db": "1.*@dev",
- "codeception/module-filesystem": "1.*@dev",
- "codeception/module-phpbrowser": "1.*@dev",
+ "codeception/module-asserts": "^1.0 | 2.0.*@dev",
+ "codeception/module-cli": "^1.0 | 2.0.*@dev",
+ "codeception/module-db": "^1.0 | 2.0.*@dev",
+ "codeception/module-filesystem": "^1.0 | 2.0.*@dev",
+ "codeception/module-phpbrowser": "^1.0 | 2.0.*@dev",
"codeception/specify": "~0.3",
"codeception/util-universalframework": "*@dev",
"monolog/monolog": "~1.8",
@@ -3546,6 +3547,9 @@
"branch-alias": []
},
"autoload": {
+ "files": [
+ "functions.php"
+ ],
"psr-4": {
"Codeception\\": "src/Codeception",
"Codeception\\Extension\\": "ext"
@@ -3573,7 +3577,7 @@
],
"support": {
"issues": "https://github.com/Codeception/Codeception/issues",
- "source": "https://github.com/Codeception/Codeception/tree/4.1.22"
+ "source": "https://github.com/Codeception/Codeception/tree/4.1.30"
},
"funding": [
{
@@ -3581,7 +3585,7 @@
"type": "open_collective"
}
],
- "time": "2021-08-06T17:15:34+00:00"
+ "time": "2022-03-05T18:12:30+00:00"
},
{
"name": "codeception/lib-asserts",
@@ -3816,16 +3820,16 @@
},
{
"name": "codeception/phpunit-wrapper",
- "version": "9.0.6",
+ "version": "9.0.7",
"source": {
"type": "git",
"url": "https://github.com/Codeception/phpunit-wrapper.git",
- "reference": "b0c06abb3181eedca690170f7ed0fd26a70bfacc"
+ "reference": "7d6b1a5ea4ed28d010e5d36b993db813eb49710b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Codeception/phpunit-wrapper/zipball/b0c06abb3181eedca690170f7ed0fd26a70bfacc",
- "reference": "b0c06abb3181eedca690170f7ed0fd26a70bfacc",
+ "url": "https://api.github.com/repos/Codeception/phpunit-wrapper/zipball/7d6b1a5ea4ed28d010e5d36b993db813eb49710b",
+ "reference": "7d6b1a5ea4ed28d010e5d36b993db813eb49710b",
"shasum": ""
},
"require": {
@@ -3859,9 +3863,9 @@
"description": "PHPUnit classes used by Codeception",
"support": {
"issues": "https://github.com/Codeception/phpunit-wrapper/issues",
- "source": "https://github.com/Codeception/phpunit-wrapper/tree/9.0.6"
+ "source": "https://github.com/Codeception/phpunit-wrapper/tree/9.0.7"
},
- "time": "2020-12-28T13:59:47+00:00"
+ "time": "2022-01-26T14:43:10+00:00"
},
{
"name": "codeception/stub",
@@ -3899,29 +3903,30 @@
},
{
"name": "doctrine/instantiator",
- "version": "1.4.0",
+ "version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b"
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b",
- "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc",
+ "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"require-dev": {
- "doctrine/coding-standard": "^8.0",
+ "doctrine/coding-standard": "^9",
"ext-pdo": "*",
"ext-phar": "*",
- "phpbench/phpbench": "^0.13 || 1.0.0-alpha2",
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
+ "phpbench/phpbench": "^0.16 || ^1",
+ "phpstan/phpstan": "^1.4",
+ "phpstan/phpstan-phpunit": "^1",
+ "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
+ "vimeo/psalm": "^4.22"
},
"type": "library",
"autoload": {
@@ -3948,7 +3953,7 @@
],
"support": {
"issues": "https://github.com/doctrine/instantiator/issues",
- "source": "https://github.com/doctrine/instantiator/tree/1.4.0"
+ "source": "https://github.com/doctrine/instantiator/tree/1.4.1"
},
"funding": [
{
@@ -3964,7 +3969,7 @@
"type": "tidelift"
}
],
- "time": "2020-11-10T18:47:58+00:00"
+ "time": "2022-03-03T08:28:38+00:00"
},
{
"name": "getgrav/markdowndocs",
@@ -4020,16 +4025,16 @@
},
{
"name": "guzzlehttp/guzzle",
- "version": "7.4.0",
+ "version": "7.4.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94"
+ "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/868b3571a039f0ebc11ac8f344f4080babe2cb94",
- "reference": "868b3571a039f0ebc11ac8f344f4080babe2cb94",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79",
+ "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79",
"shasum": ""
},
"require": {
@@ -4038,7 +4043,7 @@
"guzzlehttp/psr7": "^1.8.3 || ^2.1",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
- "symfony/deprecation-contracts": "^2.2"
+ "symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
@@ -4062,12 +4067,12 @@
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\": "src/"
- },
"files": [
"src/functions_include.php"
- ]
+ ],
+ "psr-4": {
+ "GuzzleHttp\\": "src/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -4124,7 +4129,7 @@
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
- "source": "https://github.com/guzzle/guzzle/tree/7.4.0"
+ "source": "https://github.com/guzzle/guzzle/tree/7.4.1"
},
"funding": [
{
@@ -4140,7 +4145,7 @@
"type": "tidelift"
}
],
- "time": "2021-10-18T09:52:00+00:00"
+ "time": "2021-12-06T18:43:05+00:00"
},
{
"name": "guzzlehttp/promises",
@@ -4169,12 +4174,12 @@
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\Promise\\": "src/"
- },
"files": [
"src/functions_include.php"
- ]
+ ],
+ "psr-4": {
+ "GuzzleHttp\\Promise\\": "src/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -4228,37 +4233,38 @@
},
{
"name": "myclabs/deep-copy",
- "version": "1.10.2",
+ "version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220"
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220",
- "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614",
+ "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
- "replace": {
- "myclabs/deep-copy": "self.version"
+ "conflict": {
+ "doctrine/collections": "<1.6.8",
+ "doctrine/common": "<2.13.3 || >=3,<3.2.2"
},
"require-dev": {
- "doctrine/collections": "^1.0",
- "doctrine/common": "^2.6",
- "phpunit/phpunit": "^7.1"
+ "doctrine/collections": "^1.6.8",
+ "doctrine/common": "^2.13.3 || ^3.2.2",
+ "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
- "psr-4": {
- "DeepCopy\\": "src/DeepCopy/"
- },
"files": [
"src/DeepCopy/deep_copy.php"
- ]
+ ],
+ "psr-4": {
+ "DeepCopy\\": "src/DeepCopy/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -4274,7 +4280,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0"
},
"funding": [
{
@@ -4282,20 +4288,20 @@
"type": "tidelift"
}
],
- "time": "2020-11-13T09:40:50+00:00"
+ "time": "2022-03-03T13:19:32+00:00"
},
{
"name": "nikic/php-parser",
- "version": "v4.13.1",
+ "version": "v4.13.2",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd"
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/63a79e8daa781cac14e5195e63ed8ae231dd10fd",
- "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077",
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077",
"shasum": ""
},
"require": {
@@ -4336,9 +4342,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.1"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2"
},
- "time": "2021-11-03T20:52:16+00:00"
+ "time": "2021-11-30T19:35:32+00:00"
},
{
"name": "phar-io/manifest",
@@ -4402,16 +4408,16 @@
},
{
"name": "phar-io/version",
- "version": "3.1.0",
+ "version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
- "reference": "bae7c545bef187884426f042434e561ab1ddb182"
+ "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182",
- "reference": "bae7c545bef187884426f042434e561ab1ddb182",
+ "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
+ "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
"shasum": ""
},
"require": {
@@ -4447,9 +4453,9 @@
"description": "Library for handling version information and constraints",
"support": {
"issues": "https://github.com/phar-io/version/issues",
- "source": "https://github.com/phar-io/version/tree/3.1.0"
+ "source": "https://github.com/phar-io/version/tree/3.2.1"
},
- "time": "2021-02-23T14:00:09+00:00"
+ "time": "2022-02-21T01:04:05+00:00"
},
{
"name": "phpdocumentor/reflection-common",
@@ -4563,16 +4569,16 @@
},
{
"name": "phpdocumentor/type-resolver",
- "version": "1.5.1",
+ "version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
- "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae"
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae",
- "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"shasum": ""
},
"require": {
@@ -4607,22 +4613,22 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
- "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1"
+ "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
},
- "time": "2021-10-02T14:08:47+00:00"
+ "time": "2022-01-04T19:58:01+00:00"
},
{
"name": "phpspec/prophecy",
- "version": "1.14.0",
+ "version": "v1.15.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
- "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
+ "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
- "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
+ "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
+ "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"shasum": ""
},
"require": {
@@ -4674,22 +4680,22 @@
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
- "source": "https://github.com/phpspec/prophecy/tree/1.14.0"
+ "source": "https://github.com/phpspec/prophecy/tree/v1.15.0"
},
- "time": "2021-09-10T09:02:12+00:00"
+ "time": "2021-12-08T12:19:24+00:00"
},
{
"name": "phpstan/phpstan",
- "version": "1.1.2",
+ "version": "1.4.8",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
- "reference": "bcea0ae85868a89d5789c75f012c93129f842934"
+ "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bcea0ae85868a89d5789c75f012c93129f842934",
- "reference": "bcea0ae85868a89d5789c75f012c93129f842934",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2a6d6704b17c4db6190cc3104056c0aad740cb15",
+ "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15",
"shasum": ""
},
"require": {
@@ -4705,7 +4711,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-master": "1.4-dev"
}
},
"autoload": {
@@ -4720,7 +4726,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
- "source": "https://github.com/phpstan/phpstan/tree/1.1.2"
+ "source": "https://github.com/phpstan/phpstan/tree/1.4.8"
},
"funding": [
{
@@ -4740,7 +4746,7 @@
"type": "tidelift"
}
],
- "time": "2021-11-09T12:41:09+00:00"
+ "time": "2022-03-04T13:03:56+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
@@ -4794,16 +4800,16 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "9.2.8",
+ "version": "9.2.15",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "cf04e88a2e3c56fc1a65488afd493325b4c1bc3e"
+ "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/cf04e88a2e3c56fc1a65488afd493325b4c1bc3e",
- "reference": "cf04e88a2e3c56fc1a65488afd493325b4c1bc3e",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
+ "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f",
"shasum": ""
},
"require": {
@@ -4859,7 +4865,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.8"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15"
},
"funding": [
{
@@ -4867,20 +4873,20 @@
"type": "github"
}
],
- "time": "2021-10-30T08:01:38+00:00"
+ "time": "2022-03-07T09:28:20+00:00"
},
{
"name": "phpunit/php-file-iterator",
- "version": "3.0.5",
+ "version": "3.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
- "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8"
+ "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8",
- "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
+ "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
"shasum": ""
},
"require": {
@@ -4919,7 +4925,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
- "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5"
+ "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6"
},
"funding": [
{
@@ -4927,7 +4933,7 @@
"type": "github"
}
],
- "time": "2020-09-28T05:57:25+00:00"
+ "time": "2021-12-02T12:48:52+00:00"
},
{
"name": "phpunit/php-invoker",
@@ -5112,16 +5118,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.10",
+ "version": "9.5.18",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a"
+ "reference": "1b5856028273bfd855e60a887278857d872ec67a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a",
+ "reference": "1b5856028273bfd855e60a887278857d872ec67a",
"shasum": ""
},
"require": {
@@ -5137,7 +5143,7 @@
"phar-io/version": "^3.0.2",
"php": ">=7.3",
"phpspec/prophecy": "^1.12.1",
- "phpunit/php-code-coverage": "^9.2.7",
+ "phpunit/php-code-coverage": "^9.2.13",
"phpunit/php-file-iterator": "^3.0.5",
"phpunit/php-invoker": "^3.1.1",
"phpunit/php-text-template": "^2.0.3",
@@ -5172,11 +5178,11 @@
}
},
"autoload": {
- "classmap": [
- "src/"
- ],
"files": [
"src/Framework/Assert/Functions.php"
+ ],
+ "classmap": [
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
@@ -5199,11 +5205,11 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18"
},
"funding": [
{
- "url": "https://phpunit.de/donate.html",
+ "url": "https://phpunit.de/sponsors.html",
"type": "custom"
},
{
@@ -5211,7 +5217,7 @@
"type": "github"
}
],
- "time": "2021-09-25T07:38:51+00:00"
+ "time": "2022-03-08T06:52:28+00:00"
},
{
"name": "psr/http-client",
@@ -5771,16 +5777,16 @@
},
{
"name": "sebastian/global-state",
- "version": "5.0.3",
+ "version": "5.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49"
+ "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49",
- "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2",
+ "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2",
"shasum": ""
},
"require": {
@@ -5823,7 +5829,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
- "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3"
+ "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5"
},
"funding": [
{
@@ -5831,7 +5837,7 @@
"type": "github"
}
],
- "time": "2021-06-11T13:31:12+00:00"
+ "time": "2022-02-14T08:28:10+00:00"
},
{
"name": "sebastian/lines-of-code",
@@ -6231,28 +6237,28 @@
},
{
"name": "symfony/browser-kit",
- "version": "v5.3.4",
+ "version": "v5.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
- "reference": "c1e3f64fcc631c96e2c5843b666db66679ced11c"
+ "reference": "18e73179c6a33d520de1b644941eba108dd811ad"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/browser-kit/zipball/c1e3f64fcc631c96e2c5843b666db66679ced11c",
- "reference": "c1e3f64fcc631c96e2c5843b666db66679ced11c",
+ "url": "https://api.github.com/repos/symfony/browser-kit/zipball/18e73179c6a33d520de1b644941eba108dd811ad",
+ "reference": "18e73179c6a33d520de1b644941eba108dd811ad",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
- "symfony/dom-crawler": "^4.4|^5.0",
+ "symfony/dom-crawler": "^4.4|^5.0|^6.0",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
- "symfony/css-selector": "^4.4|^5.0",
- "symfony/http-client": "^4.4|^5.0",
- "symfony/mime": "^4.4|^5.0",
- "symfony/process": "^4.4|^5.0"
+ "symfony/css-selector": "^4.4|^5.0|^6.0",
+ "symfony/http-client": "^4.4|^5.0|^6.0",
+ "symfony/mime": "^4.4|^5.0|^6.0",
+ "symfony/process": "^4.4|^5.0|^6.0"
},
"suggest": {
"symfony/process": ""
@@ -6283,7 +6289,7 @@
"description": "Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/browser-kit/tree/v5.3.4"
+ "source": "https://github.com/symfony/browser-kit/tree/v5.4.3"
},
"funding": [
{
@@ -6299,20 +6305,20 @@
"type": "tidelift"
}
],
- "time": "2021-07-21T12:40:44+00:00"
+ "time": "2022-01-02T09:53:40+00:00"
},
{
"name": "symfony/css-selector",
- "version": "v5.3.4",
+ "version": "v5.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
- "reference": "7fb120adc7f600a59027775b224c13a33530dd90"
+ "reference": "b0a190285cd95cb019237851205b8140ef6e368e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/css-selector/zipball/7fb120adc7f600a59027775b224c13a33530dd90",
- "reference": "7fb120adc7f600a59027775b224c13a33530dd90",
+ "url": "https://api.github.com/repos/symfony/css-selector/zipball/b0a190285cd95cb019237851205b8140ef6e368e",
+ "reference": "b0a190285cd95cb019237851205b8140ef6e368e",
"shasum": ""
},
"require": {
@@ -6349,7 +6355,7 @@
"description": "Converts CSS selectors to XPath expressions",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/css-selector/tree/v5.3.4"
+ "source": "https://github.com/symfony/css-selector/tree/v5.4.3"
},
"funding": [
{
@@ -6365,20 +6371,20 @@
"type": "tidelift"
}
],
- "time": "2021-07-21T12:38:00+00:00"
+ "time": "2022-01-02T09:53:40+00:00"
},
{
"name": "symfony/deprecation-contracts",
- "version": "v2.4.0",
+ "version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
- "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627"
+ "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627",
- "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627",
+ "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8",
+ "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"shasum": ""
},
"require": {
@@ -6387,7 +6393,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "2.4-dev"
+ "dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -6416,7 +6422,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0"
+ "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.0"
},
"funding": [
{
@@ -6432,25 +6438,25 @@
"type": "tidelift"
}
],
- "time": "2021-03-23T23:28:01+00:00"
+ "time": "2021-07-12T14:48:14+00:00"
},
{
"name": "symfony/dom-crawler",
- "version": "v5.3.7",
+ "version": "v5.4.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
- "reference": "c7eef3a60ccfdd8eafe07f81652e769ac9c7146c"
+ "reference": "c0bda97480d96337bd3866026159a8b358665457"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/c7eef3a60ccfdd8eafe07f81652e769ac9c7146c",
- "reference": "c7eef3a60ccfdd8eafe07f81652e769ac9c7146c",
+ "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/c0bda97480d96337bd3866026159a8b358665457",
+ "reference": "c0bda97480d96337bd3866026159a8b358665457",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
- "symfony/deprecation-contracts": "^2.1",
+ "symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16"
@@ -6460,7 +6466,7 @@
},
"require-dev": {
"masterminds/html5": "^2.6",
- "symfony/css-selector": "^4.4|^5.0"
+ "symfony/css-selector": "^4.4|^5.0|^6.0"
},
"suggest": {
"symfony/css-selector": ""
@@ -6491,7 +6497,7 @@
"description": "Eases DOM navigation for HTML and XML documents",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/dom-crawler/tree/v5.3.7"
+ "source": "https://github.com/symfony/dom-crawler/tree/v5.4.6"
},
"funding": [
{
@@ -6507,24 +6513,25 @@
"type": "tidelift"
}
],
- "time": "2021-08-29T19:32:13+00:00"
+ "time": "2022-03-02T12:42:23+00:00"
},
{
"name": "symfony/finder",
- "version": "v5.3.7",
+ "version": "v5.4.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
- "reference": "a10000ada1e600d109a6c7632e9ac42e8bf2fb93"
+ "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/finder/zipball/a10000ada1e600d109a6c7632e9ac42e8bf2fb93",
- "reference": "a10000ada1e600d109a6c7632e9ac42e8bf2fb93",
+ "url": "https://api.github.com/repos/symfony/finder/zipball/231313534dded84c7ecaa79d14bc5da4ccb69b7d",
+ "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
+ "symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-php80": "^1.16"
},
"type": "library",
@@ -6553,7 +6560,7 @@
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/finder/tree/v5.3.7"
+ "source": "https://github.com/symfony/finder/tree/v5.4.3"
},
"funding": [
{
@@ -6569,7 +6576,7 @@
"type": "tidelift"
}
],
- "time": "2021-08-04T21:20:46+00:00"
+ "time": "2022-01-26T16:34:36+00:00"
},
{
"name": "theseer/tokenizer",
@@ -6698,5 +6705,5 @@
"platform-overrides": {
"php": "7.3.6"
},
- "plugin-api-version": "2.0.0"
+ "plugin-api-version": "2.2.0"
}
diff --git a/index.php b/index.php
index 091e9a8..b6b86e1 100644
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
/**
* @package Grav.Core
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -12,10 +12,6 @@ namespace Grav;
\define('GRAV_REQUEST_TIME', microtime(true));
\define('GRAV_PHP_MIN', '7.3.6');
-if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
- die(sprintf('You are running PHP %s, but Grav needs at least PHP %s to run.', $ver, $req));
-}
-
if (PHP_SAPI === 'cli-server') {
$symfony_server = stripos(getenv('_'), 'symfony') !== false || stripos($_SERVER['SERVER_SOFTWARE'] ?? '', 'symfony') !== false || stripos($_ENV['SERVER_SOFTWARE'] ?? '', 'symfony') !== false;
@@ -24,16 +20,6 @@ if (PHP_SAPI === 'cli-server') {
}
}
-// Set timezone to default, falls back to system if php.ini not set
-date_default_timezone_set(@date_default_timezone_get());
-
-// Set internal encoding.
-if (!\extension_loaded('mbstring')) {
- die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
-}
-@ini_set('default_charset', 'UTF-8');
-mb_internal_encoding('UTF-8');
-
// Ensure vendor libraries exist
$autoload = __DIR__ . '/vendor/autoload.php';
if (!is_file($autoload)) {
@@ -43,23 +29,23 @@ if (!is_file($autoload)) {
// Register the auto-loader.
$loader = require $autoload;
+// Set timezone to default, falls back to system if php.ini not set
+date_default_timezone_set(@date_default_timezone_get());
+
+// Set internal encoding.
+@ini_set('default_charset', 'UTF-8');
+mb_internal_encoding('UTF-8');
+
use Grav\Common\Grav;
use RocketTheme\Toolbox\Event\Event;
// Get the Grav instance
-$grav = Grav::instance(
- array(
- 'loader' => $loader
- )
-);
+$grav = Grav::instance(array('loader' => $loader));
// Process the page
try {
$grav->process();
-} catch (\Error $e) {
- $grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
- throw $e;
-} catch (\Exception $e) {
+} catch (\Error|\Exception $e) {
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
throw $e;
}
diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml
index 1aeaf2b..787fcd5 100644
--- a/system/blueprints/config/system.yaml
+++ b/system/blueprints/config/system.yaml
@@ -888,9 +888,45 @@ form:
title: PLUGIN_ADMIN.ASSETS
fields:
- assets_section:
+ general_config_section:
type: section
- title: PLUGIN_ADMIN.ASSETS
+ title: PLUGIN_ADMIN.GENERAL_CONFIG
+ underline: true
+
+ assets.enable_asset_timestamp:
+ type: toggle
+ label: PLUGIN_ADMIN.ENABLED_TIMESTAMPS_ON_ASSETS
+ help: PLUGIN_ADMIN.ENABLED_TIMESTAMPS_ON_ASSETS_HELP
+ highlight: 0
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ validate:
+ type: bool
+
+ assets.enable_asset_sri:
+ type: toggle
+ label: PLUGIN_ADMIN.ENABLED_SRI_ON_ASSETS
+ help: PLUGIN_ADMIN.ENABLED_SRI_ON_ASSETS_HELP
+ highlight: 0
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ validate:
+ type: bool
+
+ assets.collections:
+ type: multilevel
+ label: PLUGIN_ADMIN.COLLECTIONS
+ placeholder_key: collection_name
+ placeholder_value: collection_path
+ validate:
+ type: array
+
+
+ css_assets_section:
+ type: section
+ title: PLUGIN_ADMIN.CSS_ASSETS
underline: true
assets.css_pipeline:
@@ -959,6 +995,11 @@ form:
validate:
type: bool
+ js_assets_section:
+ type: section
+ title: PLUGIN_ADMIN.JS_ASSETS
+ underline: true
+
assets.js_pipeline:
type: toggle
label: PLUGIN_ADMIN.JAVASCRIPT_PIPELINE
@@ -1003,10 +1044,15 @@ form:
validate:
type: bool
- assets.enable_asset_timestamp:
+ js_module_assets_section:
+ type: section
+ title: PLUGIN_ADMIN.JS_MODULE_ASSETS
+ underline: true
+
+ assets.js_module_pipeline:
type: toggle
- label: PLUGIN_ADMIN.ENABLED_TIMESTAMPS_ON_ASSETS
- help: PLUGIN_ADMIN.ENABLED_TIMESTAMPS_ON_ASSETS_HELP
+ label: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE
+ help: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
@@ -1014,24 +1060,29 @@ form:
validate:
type: bool
- assets.enable_asset_sri:
+ assets.js_module_pipeline_include_externals:
type: toggle
- label: PLUGIN_ADMIN.ENABLED_SRI_ON_ASSETS
- help: PLUGIN_ADMIN.ENABLED_SRI_ON_ASSETS_HELP
- highlight: 0
+ label: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE_INCLUDE_EXTERNALS
+ help: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE_INCLUDE_EXTERNALS_HELP
+ highlight: 1
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
- assets.collections:
- type: multilevel
- label: PLUGIN_ADMIN.COLLECTIONS
- placeholder_key: collection_name
- placeholder_value: collection_path
+ assets.js_module_pipeline_before_excludes:
+ type: toggle
+ label: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE_BEFORE_EXCLUDES
+ help: PLUGIN_ADMIN.JAVASCRIPT_MODULE_PIPELINE_BEFORE_EXCLUDES_HELP
+ highlight: 1
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
validate:
- type: array
+ type: bool
+
+
errors:
type: tab
@@ -1394,6 +1445,18 @@ form:
validate:
type: bool
+ session.secure_https:
+ type: toggle
+ label: PLUGIN_ADMIN.SESSION_SECURE_HTTPS
+ help: PLUGIN_ADMIN.SESSION_SECURE_HTTPS_HELP
+ highlight: 1
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ default: true
+ validate:
+ type: bool
+
session.httponly:
type: toggle
label: PLUGIN_ADMIN.SESSION_HTTPONLY
@@ -1723,35 +1786,15 @@ form:
validate:
type: bool
- experimental:
+
+ accounts:
type: tab
- title: PLUGIN_ADMIN.EXPERIMENTAL
+ title: PLUGIN_ADMIN.ACCOUNTS
fields:
- experimental_section:
- type: section
- title: PLUGIN_ADMIN.EXPERIMENTAL
- underline: true
-
-# flex_pages:
-# type: section
-# title: Flex Pages
-#
-# pages.type:
-# type: select
-# label: PLUGIN_ADMIN.PAGES_TYPE
-# highlight: regular
-# help: PLUGIN_ADMIN.PAGES_TYPE_HELP
-# options:
-# regular: PLUGIN_ADMIN.REGULAR
-# flex: PLUGIN_ADMIN.FLEX
-
- pages.type:
- type: hidden
-
flex_accounts:
type: section
- title: Flex Accounts
+ title: User Accounts
accounts.type:
type: select
@@ -1770,3 +1813,41 @@ form:
options:
file: PLUGIN_ADMIN.FILE
folder: PLUGIN_ADMIN.FOLDER
+
+ accounts.avatar:
+ type: select
+ label: PLUGIN_ADMIN.AVATAR
+ default: gravatar
+ help: PLUGIN_ADMIN.AVATAR_HELP
+ options:
+ multiavatar: Multiavatar [local]
+ gravatar: Gravatar [external]
+
+# experimental:
+# type: tab
+# title: PLUGIN_ADMIN.EXPERIMENTAL
+#
+# fields:
+# experimental_section:
+# type: section
+# title: PLUGIN_ADMIN.EXPERIMENTAL
+# underline: true
+#
+# flex_pages:
+# type: section
+# title: Flex Pages
+#
+# pages.type:
+# type: select
+# label: PLUGIN_ADMIN.PAGES_TYPE
+# highlight: regular
+# help: PLUGIN_ADMIN.PAGES_TYPE_HELP
+# options:
+# regular: PLUGIN_ADMIN.REGULAR
+# flex: PLUGIN_ADMIN.FLEX
+#
+# pages.type:
+# type: hidden
+
+
+
diff --git a/system/blueprints/flex/pages.yaml b/system/blueprints/flex/pages.yaml
index 5c6ed8e..89dab6a 100644
--- a/system/blueprints/flex/pages.yaml
+++ b/system/blueprints/flex/pages.yaml
@@ -104,7 +104,7 @@ config:
edit:
title:
- template: "{% if object.root %}Root ( <root> ){% else %}{{ (form.value('header.title') ?? form.value('folder'))|e }} ( {{ (object.getRoute().toString(false) ?: '/')|e }} ){% endif %}"
+ template: "{% if object.root %}Root ( <root> ){% else %}{{ (form.value('header.title') ?? form.value('folder'))|e }} ( {{ (object.getRoute().toString(false) ?: '/')|e }} ){% endif %}"
# TODO: not used yet
buttons:
diff --git a/system/blueprints/flex/user-accounts.yaml b/system/blueprints/flex/user-accounts.yaml
index 384bf97..8d336f9 100644
--- a/system/blueprints/flex/user-accounts.yaml
+++ b/system/blueprints/flex/user-accounts.yaml
@@ -122,6 +122,8 @@ config:
fields:
- key
- email
+ - username
+ - fullname
blueprints:
configure:
diff --git a/system/blueprints/flex/user-groups.yaml b/system/blueprints/flex/user-groups.yaml
index 05ba87b..a5d348b 100644
--- a/system/blueprints/flex/user-groups.yaml
+++ b/system/blueprints/flex/user-groups.yaml
@@ -113,6 +113,7 @@ config:
fields:
- key
- groupname
+ - readableName
- description
blueprints:
diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml
index f3ef29f..a573a83 100644
--- a/system/blueprints/pages/default.yaml
+++ b/system/blueprints/pages/default.yaml
@@ -320,6 +320,18 @@ form:
fields:
+ header.redirect_default_route:
+ type: toggle
+ toggleable: true
+ label: PLUGIN_ADMIN.REDIRECT_DEFAULT_ROUTE
+ help: PLUGIN_ADMIN.REDIRECT_DEFAULT_ROUTE_HELP
+ config-highlight@: system.pages.redirect_default_route
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ validate:
+ type: bool
+
header.routes.default:
type: text
toggleable: true
diff --git a/system/blueprints/pages/external.yaml b/system/blueprints/pages/external.yaml
index df1d7b0..d3bb57a 100644
--- a/system/blueprints/pages/external.yaml
+++ b/system/blueprints/pages/external.yaml
@@ -1,7 +1,7 @@
-title: PLUGIN_ADMIN:EXTERNAL
+title: PLUGIN_ADMIN.EXTERNAL
extends@:
- type: default
- context: blueprints://pages
+ type: default
+ context: blueprints://pages
form:
validation: loose
@@ -29,16 +29,16 @@ form:
unset@: true
header.external_url:
- type: text
- label: PLUGIN_ADMIN.EXTERNAL_URL
- placeholder: https://getgrav.org
- validate:
- required: true
+ type: text
+ label: PLUGIN_ADMIN.EXTERNAL_URL
+ placeholder: https://getgrav.org
+ validate:
+ required: true
+
options:
fields:
publishing:
-
fields:
header.date:
diff --git a/system/blueprints/pages/partials/security.yaml b/system/blueprints/pages/partials/security.yaml
index d7619b9..26d8c7d 100644
--- a/system/blueprints/pages/partials/security.yaml
+++ b/system/blueprints/pages/partials/security.yaml
@@ -51,17 +51,13 @@ form:
type: bool
header.permissions.authors:
- type: list
+ type: array
toggleable: true
+ value_only: true
+ placeholder_value: PLUGIN_ADMIN.USERNAME
label: PLUGIN_ADMIN.PAGE_AUTHORS
help: PLUGIN_ADMIN.PAGE_AUTHORS_HELP
- fields:
- value:
- type: text
- placeholder: PLUGIN_ADMIN.USERNAME
- style: vertical
-
header.permissions.groups:
ignore@: true
type: acl_picker
diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml
index 127a99e..ef5f25b 100644
--- a/system/blueprints/user/account.yaml
+++ b/system/blueprints/user/account.yaml
@@ -11,10 +11,21 @@ form:
avatar:
type: file
size: large
- destination: 'user://accounts/avatars'
+ destination: 'account://avatars'
multiple: false
random_name: true
+ multiavatar_only:
+ type: conditional
+ condition: config.system.accounts.avatar == 'multiavatar'
+ fields:
+ avatar_hash:
+ type: text
+ label: ''
+ placeholder: 'e.g. dceaadcfda491f4e45'
+ description: PLUGIN_ADMIN.AVATAR_HASH
+ size: large
+
content:
type: section
title: PLUGIN_ADMIN.ACCOUNT
@@ -107,6 +118,12 @@ form:
label: PLUGIN_ADMIN.2FA_SECRET
sublabel: PLUGIN_ADMIN.2FA_SECRET_HELP
+ yubikey_id:
+ type: text
+ label: PLUGIN_ADMIN.YUBIKEY_ID
+ description: PLUGIN_ADMIN.YUBIKEY_HELP
+ size: small
+ maxlength: 12
diff --git a/system/config/media.yaml b/system/config/media.yaml
index b118a21..fad5e0d 100644
--- a/system/config/media.yaml
+++ b/system/config/media.yaml
@@ -199,7 +199,7 @@ types:
gz:
type: file
thumb: media/thumb-gz.png
- mime: application/gzip
+ mime: application/x-gzip
tar:
type: file
thumb: media/thumb-tar.png
diff --git a/system/config/system.yaml b/system/config/system.yaml
index 652910d..380d650 100644
--- a/system/config/system.yaml
+++ b/system/config/system.yaml
@@ -127,6 +127,9 @@ assets: # Configuration for Assets Mana
js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file
js_pipeline_include_externals: true # Include external URLs in the pipeline by default
js_pipeline_before_excludes: true # Render the pipeline before any excluded files
+ js_module_pipeline: false # The JS Module pipeline is the unification of multiple JS Module resources into one file
+ js_module_pipeline_include_externals: true # Include external URLs in the pipeline by default
+ js_module_pipeline_before_excludes: true # Render the pipeline before any excluded files
js_minify: true # Minify the JS during pipelining
enable_asset_timestamp: false # Enable asset timestamps
enable_asset_sri: false # Enable asset SRI
@@ -182,6 +185,7 @@ session:
name: grav-site # Name prefix of the session cookie. Use alphanumeric, dashes or underscores only. Do not use dots in the session name
uniqueness: path # Should sessions be `path` based or `security.salt` based
secure: false # Set session secure. If true, indicates that communication for this cookie must be over an encrypted transmission. Enable this only on sites that run exclusively on HTTPS
+ secure_https: true # Set session secure on HTTPS but not on HTTP. Has no effect if you have `session.secure: true`. Set to false if your site jumps between HTTP and HTTPS.
httponly: true # Set session HTTP only. If true, indicates that cookies should be used only over HTTP, and JavaScript modification is not allowed.
samesite: Lax # Set session SameSite. Possible values are Lax, Strict and None. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
split: true # Sessions should be independent between site and plugins (such as admin)
@@ -204,6 +208,7 @@ http:
accounts:
type: regular # EXPERIMENTAL: Account type: regular or flex
storage: file # EXPERIMENTAL: Flex storage type: file or folder
+ avatar: gravatar # Avatar generator [multiavatar|gravatar]
flex:
cache:
diff --git a/system/defines.php b/system/defines.php
index f5ccba9..5f743db 100644
--- a/system/defines.php
+++ b/system/defines.php
@@ -3,13 +3,13 @@
/**
* @package Grav\Core
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
// Some standard defines
define('GRAV', true);
-define('GRAV_VERSION', '1.7.25');
+define('GRAV_VERSION', '1.7.31');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);
diff --git a/system/install.php b/system/install.php
index e8cd582..5c9440f 100644
--- a/system/install.php
+++ b/system/install.php
@@ -2,7 +2,7 @@
/**
* @package Grav\Core
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/languages/es.yaml b/system/languages/es.yaml
index 95827ee..a8a47aa 100644
--- a/system/languages/es.yaml
+++ b/system/languages/es.yaml
@@ -44,7 +44,7 @@ GRAV:
WK: sem
MO: mes
YR: año
- DEC: dic
+ DEC: déc
SECOND_PLURAL: segundos
MINUTE_PLURAL: minutos
HOUR_PLURAL: horas
@@ -64,7 +64,7 @@ GRAV:
VALIDATION_FAIL: 'Falló la validación: '
INVALID_INPUT: 'Dato inválido en: '
MISSING_REQUIRED_FIELD: 'Falta el campo requerido: '
- XSS_ISSUES: "Se detectaron problemas XSS potenciales en el campo '%s'"
+ XSS_ISSUES: "Se detectaron potenciales problemas XSS en el campo '%s'"
MONTHS_OF_THE_YEAR:
- 'Enero'
- 'Febrero'
@@ -86,7 +86,7 @@ GRAV:
- 'Viernes'
- 'Sábado'
- 'Domingo'
- YES: "Si"
+ YES: "Sí"
NO: "No"
CRON:
EVERY: cada
@@ -96,12 +96,12 @@ GRAV:
EVERY_DAY_OF_MONTH: cada día del mes
EVERY_MONTH: cada mes
TEXT_PERIOD: Cada
- TEXT_MINS: ' a minuto(s) despues de la hora'
+ TEXT_MINS: ' a minuto(s) después de la hora'
TEXT_TIME: ' a :'
TEXT_DOW: ' en '
TEXT_MONTH: ' de'
TEXT_DOM: ' en'
- ERROR1: La etiqueta %s no está soportada!
- ERROR2: El número de elementos es erroneo
+ ERROR1: '¡La etiqueta %s no está soportada!'
+ ERROR2: El número de elementos es erróneo
ERROR3: El jquery_element debería establecerse en la configuración del jqCron
ERROR4: Expresión no reconocida
diff --git a/system/router.php b/system/router.php
index d58609c..c19f814 100644
--- a/system/router.php
+++ b/system/router.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Core
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,9 +22,9 @@ if ($path !== '/index.php' && is_file($root . $path)) {
// Block all direct access for these folders
|| preg_match('`^/(\.git|cache|bin|logs|backup|webserver-configs|tests)/`ui', $path)
// Block access to specific file types for these system folders
- || preg_match('`^/(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
+ || preg_match('`^/(system|vendor)/(.*)\.(txt|xml|md|html|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
// Block access to specific file types for these user folders
- || preg_match('`^/(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
+ || preg_match('`^/(user)/(.*)\.(txt|md|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
// Block all direct access to .md files
|| preg_match('`\.md$`ui', $path)
// Block access to specific files in the root folder
diff --git a/system/src/DOMLettersIterator.php b/system/src/DOMLettersIterator.php
new file mode 100644
index 0000000..e3c2c4a
--- /dev/null
+++ b/system/src/DOMLettersIterator.php
@@ -0,0 +1,165 @@
+load('example.xml');
+ * foreach(new DOMLettersIterator($doc) as $letter) echo $letter;
+ *
+ * NB: If you only need characters without their position
+ * in the document, use DOMNode->textContent instead.
+ *
+ * @author porneL http://pornel.net
+ * @license Public Domain
+ * @url https://github.com/antoligy/dom-string-iterators
+ *
+ * @implements Iterator
+ */
+final class DOMLettersIterator implements Iterator
+{
+ /** @var DOMElement */
+ private $start;
+ /** @var DOMElement|null */
+ private $current;
+ /** @var int */
+ private $offset = -1;
+ /** @var int|null */
+ private $key;
+ /** @var array|null */
+ private $letters;
+
+ /**
+ * expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML)
+ *
+ * @param DOMNode $el
+ */
+ public function __construct(DOMNode $el)
+ {
+ if ($el instanceof DOMDocument) {
+ $el = $el->documentElement;
+ }
+
+ if (!$el instanceof DOMElement) {
+ throw new InvalidArgumentException('Invalid arguments, expected DOMElement or DOMDocument');
+ }
+
+ $this->start = $el;
+ }
+
+ /**
+ * Returns position in text as DOMText node and character offset.
+ * (it's NOT a byte offset, you must use mb_substr() or similar to use this offset properly).
+ * node may be NULL if iterator has finished.
+ *
+ * @return array
+ */
+ public function currentTextPosition(): array
+ {
+ return [$this->current, $this->offset];
+ }
+
+ /**
+ * Returns DOMElement that is currently being iterated or NULL if iterator has finished.
+ *
+ * @return DOMElement|null
+ */
+ public function currentElement(): ?DOMElement
+ {
+ return $this->current ? $this->current->parentNode : null;
+ }
+
+ // Implementation of Iterator interface
+
+ /**
+ * @return int|null
+ */
+ public function key(): ?int
+ {
+ return $this->key;
+ }
+
+ /**
+ * @return void
+ */
+ public function next(): void
+ {
+ if (null === $this->current) {
+ return;
+ }
+
+ if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) {
+ if ($this->offset === -1) {
+ preg_match_all('/./us', $this->current->textContent, $m);
+ $this->letters = $m[0];
+ }
+
+ $this->offset++;
+ $this->key++;
+ if ($this->letters && $this->offset < count($this->letters)) {
+ return;
+ }
+
+ $this->offset = -1;
+ }
+
+ while ($this->current->nodeType === XML_ELEMENT_NODE && $this->current->firstChild) {
+ $this->current = $this->current->firstChild;
+ if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) {
+ $this->next();
+ return;
+ }
+ }
+
+ while (!$this->current->nextSibling && $this->current->parentNode) {
+ $this->current = $this->current->parentNode;
+ if ($this->current === $this->start) {
+ $this->current = null;
+ return;
+ }
+ }
+
+ $this->current = $this->current->nextSibling;
+
+ $this->next();
+ }
+
+ /**
+ * Return the current element
+ * @link https://php.net/manual/en/iterator.current.php
+ *
+ * @return string|null
+ */
+ public function current(): ?string
+ {
+ return $this->letters ? $this->letters[$this->offset] : null;
+ }
+
+ /**
+ * Checks if current position is valid
+ * @link https://php.net/manual/en/iterator.valid.php
+ *
+ * @return bool
+ */
+ public function valid(): bool
+ {
+ return (bool)$this->current;
+ }
+
+ /**
+ * @return void
+ */
+ public function rewind(): void
+ {
+ $this->current = $this->start;
+ $this->offset = -1;
+ $this->key = 0;
+ $this->letters = [];
+
+ $this->next();
+ }
+}
+
diff --git a/system/src/DOMWordsIterator.php b/system/src/DOMWordsIterator.php
new file mode 100644
index 0000000..fb7c2e3
--- /dev/null
+++ b/system/src/DOMWordsIterator.php
@@ -0,0 +1,158 @@
+load('example.xml');
+ * foreach(new DOMWordsIterator($doc) as $word) echo $word;
+ *
+ * @author pjgalbraith http://www.pjgalbraith.com
+ * @author porneL http://pornel.net (based on DOMLettersIterator available at http://pornel.net/source/domlettersiterator.php)
+ * @license Public Domain
+ * @url https://github.com/antoligy/dom-string-iterators
+ *
+ * @implements Iterator
+ */
+
+final class DOMWordsIterator implements Iterator
+{
+ /** @var DOMElement */
+ private $start;
+ /** @var DOMElement|null */
+ private $current;
+ /** @var int */
+ private $offset = -1;
+ /** @var int|null */
+ private $key;
+ /** @var array>|null */
+ private $words;
+
+ /**
+ * expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML)
+ *
+ * @param DOMNode $el
+ */
+ public function __construct(DOMNode $el)
+ {
+ if ($el instanceof DOMDocument) {
+ $el = $el->documentElement;
+ }
+
+ if (!$el instanceof DOMElement) {
+ throw new InvalidArgumentException('Invalid arguments, expected DOMElement or DOMDocument');
+ }
+
+ $this->start = $el;
+ }
+
+ /**
+ * Returns position in text as DOMText node and character offset.
+ * (it's NOT a byte offset, you must use mb_substr() or similar to use this offset properly).
+ * node may be NULL if iterator has finished.
+ *
+ * @return array
+ */
+ public function currentWordPosition(): array
+ {
+ return [$this->current, $this->offset, $this->words];
+ }
+
+ /**
+ * Returns DOMElement that is currently being iterated or NULL if iterator has finished.
+ *
+ * @return DOMElement|null
+ */
+ public function currentElement(): ?DOMElement
+ {
+ return $this->current ? $this->current->parentNode : null;
+ }
+
+ // Implementation of Iterator interface
+
+ /**
+ * Return the key of the current element
+ * @link https://php.net/manual/en/iterator.key.php
+ * @return int|null
+ */
+ public function key(): ?int
+ {
+ return $this->key;
+ }
+
+ /**
+ * @return void
+ */
+ public function next(): void
+ {
+ if (null === $this->current) {
+ return;
+ }
+
+ if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) {
+ if ($this->offset === -1) {
+ $this->words = preg_split("/[\n\r\t ]+/", $this->current->textContent, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_OFFSET_CAPTURE) ?: [];
+ }
+ $this->offset++;
+
+ if ($this->words && $this->offset < count($this->words)) {
+ $this->key++;
+ return;
+ }
+ $this->offset = -1;
+ }
+
+ while ($this->current->nodeType === XML_ELEMENT_NODE && $this->current->firstChild) {
+ $this->current = $this->current->firstChild;
+ if ($this->current->nodeType === XML_TEXT_NODE || $this->current->nodeType === XML_CDATA_SECTION_NODE) {
+ $this->next();
+ return;
+ }
+ }
+
+ while (!$this->current->nextSibling && $this->current->parentNode) {
+ $this->current = $this->current->parentNode;
+ if ($this->current === $this->start) {
+ $this->current = null;
+ return;
+ }
+ }
+
+ $this->current = $this->current->nextSibling;
+
+ $this->next();
+ }
+
+ /**
+ * Return the current element
+ * @link https://php.net/manual/en/iterator.current.php
+ * @return string|null
+ */
+ public function current(): ?string
+ {
+ return $this->words ? (string)$this->words[$this->offset][0] : null;
+ }
+
+ /**
+ * Checks if current position is valid
+ * @link https://php.net/manual/en/iterator.valid.php
+ * @return bool
+ */
+ public function valid(): bool
+ {
+ return (bool)$this->current;
+ }
+
+ public function rewind(): void
+ {
+ $this->current = $this->start;
+ $this->offset = -1;
+ $this->key = 0;
+ $this->words = [];
+
+ $this->next();
+ }
+}
diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php
index a9b930b..621a140 100644
--- a/system/src/Grav/Common/Assets.php
+++ b/system/src/Grav/Common/Assets.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,8 +16,8 @@ use Grav\Common\Assets\Traits\TestingAssetsTrait;
use Grav\Common\Config\Config;
use Grav\Framework\Object\PropertyObject;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
+use function array_slice;
use function call_user_func_array;
-use function count;
use function func_get_args;
use function is_array;
@@ -30,14 +30,21 @@ class Assets extends PropertyObject
use TestingAssetsTrait;
use LegacyAssetsTrait;
+ const LINK = 'link';
const CSS = 'css';
const JS = 'js';
+ const JS_MODULE = 'js_module';
+ const LINK_COLLECTION = 'assets_link';
const CSS_COLLECTION = 'assets_css';
const JS_COLLECTION = 'assets_js';
+ const JS_MODULE_COLLECTION = 'assets_js_module';
+ const LINK_TYPE = Assets\Link::class;
const CSS_TYPE = Assets\Css::class;
const JS_TYPE = Assets\Js::class;
+ const JS_MODULE_TYPE = Assets\JsModule::class;
const INLINE_CSS_TYPE = Assets\InlineCss::class;
const INLINE_JS_TYPE = Assets\InlineJs::class;
+ const INLINE_JS_MODULE_TYPE = Assets\InlineJsModule::class;
/** @const Regex to match CSS and JavaScript files */
const DEFAULT_REGEX = '/.\.(css|js)$/i';
@@ -48,15 +55,24 @@ class Assets extends PropertyObject
/** @const Regex to match JavaScript files */
const JS_REGEX = '/.\.js$/i';
+ /** @const Regex to match JavaScriptModyle files */
+ const JS_MODULE_REGEX = '/.\.mjs$/i';
+
/** @var string */
protected $assets_dir;
/** @var string */
protected $assets_url;
+ /** @var array */
+ protected $assets_link = [];
/** @var array */
protected $assets_css = [];
/** @var array */
protected $assets_js = [];
+ /** @var array */
+ protected $assets_js_module = [];
+
+
// Following variables come from the configuration:
/** @var bool */
@@ -66,19 +82,17 @@ class Assets extends PropertyObject
/** @var bool */
protected $css_pipeline_before_excludes;
/** @var bool */
- protected $inlinecss_pipeline_include_externals;
- /** @var bool */
- protected $inlinecss_pipeline_before_excludes;
- /** @var bool */
protected $js_pipeline;
/** @var bool */
protected $js_pipeline_include_externals;
/** @var bool */
protected $js_pipeline_before_excludes;
/** @var bool */
- protected $inlinejs_pipeline_include_externals;
+ protected $js_module_pipeline;
/** @var bool */
- protected $inlinejs_pipeline_before_excludes;
+ protected $js_module_pipeline_include_externals;
+ /** @var bool */
+ protected $js_module_pipeline_before_excludes;
/** @var array */
protected $pipeline_options = [];
@@ -160,6 +174,10 @@ class Assets extends PropertyObject
*/
public function add($asset)
{
+ if (!$asset) {
+ return $this;
+ }
+
$args = func_get_args();
// More than one asset
@@ -184,7 +202,8 @@ class Assets extends PropertyObject
call_user_func_array([$this, 'add'], $args);
} else {
// Get extension
- $extension = pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION);
+ $path = parse_url($asset, PHP_URL_PATH);
+ $extension = $path ? Utils::pathinfo($path, PATHINFO_EXTENSION) : '';
// JavaScript or CSS
if ($extension !== '') {
@@ -193,6 +212,8 @@ class Assets extends PropertyObject
call_user_func_array([$this, 'addCss'], $args);
} elseif ($extension === 'js') {
call_user_func_array([$this, 'addJs'], $args);
+ } elseif ($extension === 'mjs') {
+ call_user_func_array([$this, 'addJsModule'], $args);
}
}
}
@@ -222,7 +243,7 @@ class Assets extends PropertyObject
return $this;
}
- if (($type === $this::CSS_TYPE || $type === $this::JS_TYPE) && isset($this->collections[$asset])) {
+ if ($this->isValidType($type) && isset($this->collections[$asset])) {
$this->addType($collection, $type, $this->collections[$asset], $options);
return $this;
}
@@ -230,7 +251,9 @@ class Assets extends PropertyObject
// If pipeline disabled, set to position if provided, else after
if (isset($options['pipeline'])) {
if ($options['pipeline'] === false) {
- $exclude_type = ($type === $this::JS_TYPE || $type === $this::INLINE_JS_TYPE) ? $this::JS : $this::CSS;
+
+ $exclude_type = $this->getBaseType($type);
+
$excludes = strtolower($exclude_type . '_pipeline_before_excludes');
if ($this->{$excludes}) {
$default = 'after';
@@ -269,6 +292,16 @@ class Assets extends PropertyObject
return $this;
}
+ /**
+ * Add a CSS asset or a collection of assets.
+ *
+ * @return $this
+ */
+ public function addLink($asset)
+ {
+ return $this->addType($this::LINK_COLLECTION, $this::LINK_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::LINK_TYPE));
+ }
+
/**
* Add a CSS asset or a collection of assets.
*
@@ -309,6 +342,25 @@ class Assets extends PropertyObject
return $this->addType($this::JS_COLLECTION, $this::INLINE_JS_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_TYPE));
}
+ /**
+ * Add a JS asset or a collection of assets.
+ *
+ * @return $this
+ */
+ public function addJsModule($asset)
+ {
+ return $this->addType($this::JS_MODULE_COLLECTION, $this::JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::JS_MODULE_TYPE));
+ }
+
+ /**
+ * Add an Inline JS asset or a collection of assets.
+ *
+ * @return $this
+ */
+ public function addInlineJsModule($asset)
+ {
+ return $this->addType($this::JS_MODULE_COLLECTION, $this::INLINE_JS_MODULE_TYPE, $asset, $this->unifyLegacyArguments(func_get_args(), $this::INLINE_JS_MODULE_TYPE));
+ }
/**
* Add/replace collection.
@@ -400,7 +452,7 @@ class Assets extends PropertyObject
$after_assets = $this->filterAssets($group_assets, 'position', 'after', true);
// Pipeline
- if ($this->{$pipeline_enabled}) {
+ if ($this->{$pipeline_enabled} ?? false) {
$options = array_merge($this->pipeline_options, ['timestamp' => $this->timestamp]);
$pipeline = new Pipeline($options);
@@ -432,9 +484,29 @@ class Assets extends PropertyObject
* @param array $attributes
* @return string
*/
- public function css($group = 'head', $attributes = [])
+ public function css($group = 'head', $attributes = [], $include_link = true)
{
- return $this->render('css', $group, $attributes);
+ $output = '';
+
+ if ($include_link) {
+ $output = $this->link($group, $attributes);
+ }
+
+ $output .= $this->render(self::CSS, $group, $attributes);
+
+ return $output;
+ }
+
+ /**
+ * Build the CSS link tags.
+ *
+ * @param string $group name of the group
+ * @param array $attributes
+ * @return string
+ */
+ public function link($group = 'head', $attributes = [])
+ {
+ return $this->render(self::LINK, $group, $attributes);
}
/**
@@ -444,8 +516,71 @@ class Assets extends PropertyObject
* @param array $attributes
* @return string
*/
- public function js($group = 'head', $attributes = [])
+ public function js($group = 'head', $attributes = [], $include_js_module = true)
{
- return $this->render('js', $group, $attributes);
+ $output = $this->render(self::JS, $group, $attributes);
+
+ if ($include_js_module) {
+ $output .= $this->jsModule($group, $attributes);
+ }
+
+ return $output;
+ }
+
+ /**
+ * Build the Javascript Modules tags
+ *
+ * @param string $group
+ * @param array $attributes
+ * @return string
+ */
+ public function jsModule($group = 'head', $attributes = [])
+ {
+ return $this->render(self::JS_MODULE, $group, $attributes);
+ }
+
+ /**
+ * @param string $group
+ * @param array $attributes
+ * @return string
+ */
+ public function all($group = 'head', $attributes = [])
+ {
+ $output = $this->css($group, $attributes, false);
+ $output .= $this->link($group, $attributes);
+ $output .= $this->js($group, $attributes, false);
+ $output .= $this->jsModule($group, $attributes);
+ return $output;
+ }
+
+ /**
+ * @param class-string $type
+ * @return bool
+ */
+ protected function isValidType($type)
+ {
+ return in_array($type, [self::CSS_TYPE, self::JS_TYPE, self::JS_MODULE_TYPE]);
+ }
+
+ /**
+ * @param class-string $type
+ * @return string
+ */
+ protected function getBaseType($type)
+ {
+ switch ($type) {
+ case $this::JS_TYPE:
+ case $this::INLINE_JS_TYPE:
+ $base_type = $this::JS;
+ break;
+ case $this::JS_MODULE_TYPE:
+ case $this::INLINE_JS_MODULE_TYPE:
+ $base_type = $this::JS_MODULE;
+ break;
+ default:
+ $base_type = $this::CSS;
+ }
+
+ return $base_type;
}
}
diff --git a/system/src/Grav/Common/Assets/BaseAsset.php b/system/src/Grav/Common/Assets/BaseAsset.php
index a115ce9..d062d75 100644
--- a/system/src/Grav/Common/Assets/BaseAsset.php
+++ b/system/src/Grav/Common/Assets/BaseAsset.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -26,8 +26,9 @@ abstract class BaseAsset extends PropertyObject
{
use AssetUtilsTrait;
- protected const CSS_ASSET = true;
- protected const JS_ASSET = false;
+ protected const CSS_ASSET = 1;
+ protected const JS_ASSET = 2;
+ protected const JS_MODULE_ASSET = 3;
/** @var string|false */
protected $asset;
@@ -69,7 +70,7 @@ abstract class BaseAsset extends PropertyObject
* @param array $elements
* @param string|null $key
*/
- public function __construct(array $elements = [], $key = null)
+ public function __construct(array $elements = [], ?string $key = null)
{
$base_config = [
'group' => 'head',
@@ -248,6 +249,7 @@ abstract class BaseAsset extends PropertyObject
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return ['type' => $this->getType(), 'elements' => $this->getElements()];
@@ -265,4 +267,17 @@ abstract class BaseAsset extends PropertyObject
{
return '';
}
+
+ /**
+ * Finds relative JS urls() and rewrites the URL with an absolute one
+ *
+ * @param string $file the css source file
+ * @param string $dir local relative path to the css file
+ * @param bool $local is this a local or remote asset
+ * @return string
+ */
+ protected function jsRewrite($file, $dir, $local)
+ {
+ return '';
+ }
}
diff --git a/system/src/Grav/Common/Assets/BlockAssets.php b/system/src/Grav/Common/Assets/BlockAssets.php
new file mode 100644
index 0000000..7d97960
--- /dev/null
+++ b/system/src/Grav/Common/Assets/BlockAssets.php
@@ -0,0 +1,207 @@
+getAssets();
+ foreach ($types as $type => $groups) {
+ switch ($type) {
+ case 'frameworks':
+ static::registerFrameworks($assets, $groups);
+ break;
+ case 'styles':
+ static::registerStyles($assets, $groups);
+ break;
+ case 'scripts':
+ static::registerScripts($assets, $groups);
+ break;
+ case 'links':
+ static::registerLinks($assets, $groups);
+ break;
+ case 'html':
+ static::registerHtml($assets, $groups);
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param Assets $assets
+ * @param array $list
+ * @return void
+ */
+ protected static function registerFrameworks(Assets $assets, array $list): void
+ {
+ if ($list) {
+ throw new \RuntimeException('Not Implemented');
+ }
+ }
+
+ /**
+ * @param Assets $assets
+ * @param array $groups
+ * @return void
+ */
+ protected static function registerStyles(Assets $assets, array $groups): void
+ {
+ $grav = Grav::instance();
+
+ /** @var Config $config */
+ $config = $grav['config'];
+
+ foreach ($groups as $group => $styles) {
+ foreach ($styles as $style) {
+ switch ($style[':type']) {
+ case 'file':
+ $options = [
+ 'priority' => $style[':priority'],
+ 'group' => $group,
+ 'type' => $style['type'],
+ 'media' => $style['media']
+ ] + $style['element'];
+
+ $assets->addCss(static::getRelativeUrl($style['href'], $config->get('system.assets.css_pipeline')), $options);
+ break;
+ case 'inline':
+ $options = [
+ 'priority' => $style[':priority'],
+ 'group' => $group,
+ 'type' => $style['type'],
+ ] + $style['element'];
+
+ $assets->addInlineCss($style['content'], $options);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * @param Assets $assets
+ * @param array $groups
+ * @return void
+ */
+ protected static function registerScripts(Assets $assets, array $groups): void
+ {
+ $grav = Grav::instance();
+
+ /** @var Config $config */
+ $config = $grav['config'];
+
+ foreach ($groups as $group => $scripts) {
+ $group = $group === 'footer' ? 'bottom' : $group;
+
+ foreach ($scripts as $script) {
+ switch ($script[':type']) {
+ case 'file':
+ $options = [
+ 'group' => $group,
+ 'priority' => $script[':priority'],
+ 'src' => $script['src'],
+ 'type' => $script['type'],
+ 'loading' => $script['loading'],
+ 'defer' => $script['defer'],
+ 'async' => $script['async'],
+ 'handle' => $script['handle']
+ ] + $script['element'];
+
+ $assets->addJs(static::getRelativeUrl($script['src'], $config->get('system.assets.js_pipeline')), $options);
+ break;
+ case 'inline':
+ $options = [
+ 'priority' => $script[':priority'],
+ 'group' => $group,
+ 'type' => $script['type'],
+ 'loading' => $script['loading']
+ ] + $script['element'];
+
+ $assets->addInlineJs($script['content'], $options);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * @param Assets $assets
+ * @param array $groups
+ * @return void
+ */
+ protected static function registerLinks(Assets $assets, array $groups): void
+ {
+ foreach ($groups as $group => $links) {
+ foreach ($links as $link) {
+ $href = $link['href'];
+ $options = [
+ 'group' => $group,
+ 'priority' => $link[':priority'],
+ 'rel' => $link['rel'],
+ ] + $link['element'];
+
+ $assets->addLink($href, $options);
+ }
+ }
+ }
+
+ /**
+ * @param Assets $assets
+ * @param array $groups
+ * @return void
+ */
+ protected static function registerHtml(Assets $assets, array $groups): void
+ {
+ if ($groups) {
+ throw new \RuntimeException('Not Implemented');
+ }
+ }
+
+ /**
+ * @param string $url
+ * @param bool $pipeline
+ * @return string
+ */
+ protected static function getRelativeUrl($url, $pipeline)
+ {
+ $grav = Grav::instance();
+
+ $base = rtrim($grav['base_url'], '/') ?: '/';
+
+ if (strpos($url, $base) === 0) {
+ if ($pipeline) {
+ // Remove file timestamp if CSS pipeline has been enabled.
+ $url = preg_replace('|[?#].*|', '', $url);
+ }
+
+ return substr($url, strlen($base) - 1);
+ }
+ return $url;
+ }
+}
diff --git a/system/src/Grav/Common/Assets/Css.php b/system/src/Grav/Common/Assets/Css.php
index 4c6a9c9..ea6b388 100644
--- a/system/src/Grav/Common/Assets/Css.php
+++ b/system/src/Grav/Common/Assets/Css.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,7 +22,7 @@ class Css extends BaseAsset
* @param array $elements
* @param string|null $key
*/
- public function __construct(array $elements = [], $key = null)
+ public function __construct(array $elements = [], ?string $key = null)
{
$base_options = [
'asset_type' => 'css',
diff --git a/system/src/Grav/Common/Assets/InlineCss.php b/system/src/Grav/Common/Assets/InlineCss.php
index f024a95..4984db4 100644
--- a/system/src/Grav/Common/Assets/InlineCss.php
+++ b/system/src/Grav/Common/Assets/InlineCss.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,7 +22,7 @@ class InlineCss extends BaseAsset
* @param array $elements
* @param string|null $key
*/
- public function __construct(array $elements = [], $key = null)
+ public function __construct(array $elements = [], ?string $key = null)
{
$base_options = [
'asset_type' => 'css',
diff --git a/system/src/Grav/Common/Assets/InlineJs.php b/system/src/Grav/Common/Assets/InlineJs.php
index 6787608..e38a51a 100644
--- a/system/src/Grav/Common/Assets/InlineJs.php
+++ b/system/src/Grav/Common/Assets/InlineJs.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,7 +22,7 @@ class InlineJs extends BaseAsset
* @param array $elements
* @param string|null $key
*/
- public function __construct(array $elements = [], $key = null)
+ public function __construct(array $elements = [], ?string $key = null)
{
$base_options = [
'asset_type' => 'js',
diff --git a/system/src/Grav/Common/Assets/InlineJsModule.php b/system/src/Grav/Common/Assets/InlineJsModule.php
new file mode 100644
index 0000000..42ce6f1
--- /dev/null
+++ b/system/src/Grav/Common/Assets/InlineJsModule.php
@@ -0,0 +1,46 @@
+ 'js_module',
+ 'attributes' => ['type' => 'module'],
+ 'position' => 'after'
+ ];
+
+ $merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
+
+ parent::__construct($merged_attributes, $key);
+ }
+
+ /**
+ * @return string
+ */
+ public function render()
+ {
+ return '\n";
+ }
+
+}
diff --git a/system/src/Grav/Common/Assets/Js.php b/system/src/Grav/Common/Assets/Js.php
index fc2a472..8687a86 100644
--- a/system/src/Grav/Common/Assets/Js.php
+++ b/system/src/Grav/Common/Assets/Js.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,7 +22,7 @@ class Js extends BaseAsset
* @param array $elements
* @param string|null $key
*/
- public function __construct(array $elements = [], $key = null)
+ public function __construct(array $elements = [], ?string $key = null)
{
$base_options = [
'asset_type' => 'js',
diff --git a/system/src/Grav/Common/Assets/JsModule.php b/system/src/Grav/Common/Assets/JsModule.php
new file mode 100644
index 0000000..5c2a836
--- /dev/null
+++ b/system/src/Grav/Common/Assets/JsModule.php
@@ -0,0 +1,49 @@
+ 'js_module',
+ 'attributes' => ['type' => 'module']
+ ];
+
+ $merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
+
+ parent::__construct($merged_attributes, $key);
+ }
+
+ /**
+ * @return string
+ */
+ public function render()
+ {
+ if (isset($this->attributes['loading']) && $this->attributes['loading'] === 'inline') {
+ $buffer = $this->gatherLinks([$this], self::JS_MODULE_ASSET);
+ return '\n";
+ }
+
+ return '\n";
+ }
+}
diff --git a/system/src/Grav/Common/Assets/Link.php b/system/src/Grav/Common/Assets/Link.php
new file mode 100644
index 0000000..ecafcea
--- /dev/null
+++ b/system/src/Grav/Common/Assets/Link.php
@@ -0,0 +1,43 @@
+ 'link',
+ ];
+
+ $merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
+
+ parent::__construct($merged_attributes, $key);
+ }
+
+ /**
+ * @return string
+ */
+ public function render()
+ {
+ return 'renderAttributes() . $this->integrityHash($this->asset) . ">\n";
+ }
+}
diff --git a/system/src/Grav/Common/Assets/Pipeline.php b/system/src/Grav/Common/Assets/Pipeline.php
index 948104a..0010d7b 100644
--- a/system/src/Grav/Common/Assets/Pipeline.php
+++ b/system/src/Grav/Common/Assets/Pipeline.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -29,12 +29,16 @@ class Pipeline extends PropertyObject
{
use AssetUtilsTrait;
- protected const CSS_ASSET = true;
- protected const JS_ASSET = false;
+ protected const CSS_ASSET = 1;
+ protected const JS_ASSET = 2;
+ protected const JS_MODULE_ASSET = 3;
/** @const Regex to match CSS urls */
protected const CSS_URL_REGEX = '{url\(([\'\"]?)(.*?)\1\)}';
+ /** @const Regex to match JS imports */
+ protected const JS_IMPORT_REGEX = '{import.+from\s?[\'|\"](.+?)[\'|\"]}';
+
/** @const Regex to match CSS sourcemap comments */
protected const CSS_SOURCEMAP_REGEX = '{\/\*# (.*?) \*\/}';
@@ -122,7 +126,7 @@ class Pipeline extends PropertyObject
// Compute uid based on assets and timestamp
$json_assets = json_encode($assets);
- $uid = md5($json_assets . $this->css_minify . $this->css_rewrite . $group);
+ $uid = md5($json_assets . (int)$this->css_minify . (int)$this->css_rewrite . $group);
$file = $uid . '.css';
$relative_path = "{$this->base_url}{$this->assets_url}/{$file}";
@@ -169,7 +173,7 @@ class Pipeline extends PropertyObject
* @param array $attributes
* @return bool|string URL or generated content if available, else false
*/
- public function renderJs($assets, $group, $attributes = [])
+ public function renderJs($assets, $group, $attributes = [], $type = self::JS_ASSET)
{
// temporary list of assets to pipeline
$inline_group = false;
@@ -198,7 +202,7 @@ class Pipeline extends PropertyObject
}
// Concatenate files
- $buffer = $this->gatherLinks($assets, self::JS_ASSET);
+ $buffer = $this->gatherLinks($assets, $type);
// Minify if required
if ($this->shouldMinify('js')) {
@@ -223,6 +227,19 @@ class Pipeline extends PropertyObject
return $output;
}
+ /**
+ * Minify and concatenate JS files.
+ *
+ * @param array $assets
+ * @param string $group
+ * @param array $attributes
+ * @return bool|string URL or generated content if available, else false
+ */
+ public function renderJs_Module($assets, $group, $attributes = [])
+ {
+ $attributes['type'] = 'module';
+ return $this->renderJs($assets, $group, $attributes, self::JS_MODULE_ASSET);
+ }
/**
* Finds relative CSS urls() and rewrites the URL with an absolute one
@@ -262,6 +279,42 @@ class Pipeline extends PropertyObject
return $file;
}
+ /**
+ * Finds relative JS urls() and rewrites the URL with an absolute one
+ *
+ * @param string $file the css source file
+ * @param string $dir local relative path to the css file
+ * @param bool $local is this a local or remote asset
+ * @return string
+ */
+ protected function jsRewrite($file, $dir, $local)
+ {
+ // Find any js import elements, grab the URLs and calculate an absolute path
+ // Then replace the old url with the new one
+ $file = (string)preg_replace_callback(self::JS_IMPORT_REGEX, function ($matches) use ($dir, $local) {
+
+ $old_url = $matches[1];
+
+ // Ensure link is not rooted to web server, a data URL, or to a remote host
+ if (preg_match(self::FIRST_FORWARDSLASH_REGEX, $old_url) || $this->isRemoteLink($old_url)) {
+ return $matches[0];
+ }
+
+ // clean leading /
+ $old_url = Utils::normalizePath($dir . '/' . $old_url);
+ $old_url = str_replace('/./', '/', $old_url);
+ if (preg_match(self::FIRST_FORWARDSLASH_REGEX, $old_url)) {
+ $old_url = ltrim($old_url, '/');
+ }
+
+ $new_url = ($local ? $this->base_url : '') . $old_url;
+
+ return str_replace($matches[1], $new_url, $matches[0]);
+ }, $file);
+
+ return $file;
+ }
+
/**
* @param string $type
* @return bool
diff --git a/system/src/Grav/Common/Assets/Traits/AssetUtilsTrait.php b/system/src/Grav/Common/Assets/Traits/AssetUtilsTrait.php
index 3f5a690..0e3f392 100644
--- a/system/src/Grav/Common/Assets/Traits/AssetUtilsTrait.php
+++ b/system/src/Grav/Common/Assets/Traits/AssetUtilsTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets\Traits
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -62,13 +62,13 @@ trait AssetUtilsTrait
* Download and concatenate the content of several links.
*
* @param array $assets
- * @param bool $css
+ * @param int $type
* @return string
*/
- protected function gatherLinks(array $assets, $css = true)
+ protected function gatherLinks(array $assets, int $type = self::CSS_ASSET): string
{
$buffer = '';
- foreach ($assets as $id => $asset) {
+ foreach ($assets as $asset) {
$local = true;
$link = $asset->getAsset();
@@ -100,21 +100,25 @@ trait AssetUtilsTrait
}
// Double check last character being
- if (!$css) {
+ if ($type === self::JS_ASSET || $type === self::JS_MODULE_ASSET) {
$file = rtrim($file, ' ;') . ';';
}
// If this is CSS + the file is local + rewrite enabled
- if ($css && $this->css_rewrite) {
+ if ($type === self::CSS_ASSET && $this->css_rewrite) {
$file = $this->cssRewrite($file, $relative_dir, $local);
}
+ if ($type === self::JS_MODULE_ASSET) {
+ $file = $this->jsRewrite($file, $relative_dir, $local);
+ }
+
$file = rtrim($file) . PHP_EOL;
$buffer .= $file;
}
// Pull out @imports and move to top
- if ($css) {
+ if ($type === self::CSS_ASSET) {
$buffer = $this->moveImports($buffer);
}
diff --git a/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php b/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php
index 36b2152..c1ef0a3 100644
--- a/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php
+++ b/system/src/Grav/Common/Assets/Traits/LegacyAssetsTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets\Traits
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php
index 15dc00e..b11b439 100644
--- a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php
+++ b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Assets\Traits
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -285,6 +285,15 @@ trait TestingAssetsTrait
return $this;
}
+ // Add JavaScript Module files
+ if ($pattern === self::JS_MODULE_REGEX) {
+ foreach ($files as $file) {
+ $this->addJsModule($file);
+ }
+
+ return $this;
+ }
+
// Unknown pattern.
foreach ($files as $asset) {
$this->add($asset);
diff --git a/system/src/Grav/Common/Backup/Backups.php b/system/src/Grav/Common/Backup/Backups.php
index 4680f85..ff4789d 100644
--- a/system/src/Grav/Common/Backup/Backups.php
+++ b/system/src/Grav/Common/Backup/Backups.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Backup
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -104,8 +104,8 @@ class Backups
*/
public function getBackupDownloadUrl($backup, $base_url)
{
- $param_sep = $param_sep = Grav::instance()['config']->get('system.param_sep', ':');
- $download = urlencode(base64_encode(basename($backup)));
+ $param_sep = Grav::instance()['config']->get('system.param_sep', ':');
+ $download = urlencode(base64_encode(Utils::basename($backup)));
$url = rtrim(Grav::instance()['uri']->rootUrl(true), '/') . '/' . trim(
$base_url,
'/'
@@ -145,7 +145,7 @@ class Backups
{
$backups = static::getAvailableBackups();
- return array_sum(array_column($backups, 'size'));
+ return $backups ? array_sum(array_column($backups, 'size')) : 0;
}
/**
diff --git a/system/src/Grav/Common/Browser.php b/system/src/Grav/Common/Browser.php
index e4a6513..ffc8da3 100644
--- a/system/src/Grav/Common/Browser.php
+++ b/system/src/Grav/Common/Browser.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php
index a503518..ed40a08 100644
--- a/system/src/Grav/Common/Cache.php
+++ b/system/src/Grav/Common/Cache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -177,7 +177,7 @@ class Cache extends Getters
public function purgeOldCache()
{
$cache_dir = dirname($this->cache_dir);
- $current = basename($this->cache_dir);
+ $current = Utils::basename($this->cache_dir);
$count = 0;
foreach (new DirectoryIterator($cache_dir) as $file) {
diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php
index f1f6e5d..667edf2 100644
--- a/system/src/Grav/Common/Composer.php
+++ b/system/src/Grav/Common/Composer.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/CompiledBase.php b/system/src/Grav/Common/Config/CompiledBase.php
index 0764189..b462b4c 100644
--- a/system/src/Grav/Common/Config/CompiledBase.php
+++ b/system/src/Grav/Common/Config/CompiledBase.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/CompiledBlueprints.php b/system/src/Grav/Common/Config/CompiledBlueprints.php
index 7743054..e838591 100644
--- a/system/src/Grav/Common/Config/CompiledBlueprints.php
+++ b/system/src/Grav/Common/Config/CompiledBlueprints.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/CompiledConfig.php b/system/src/Grav/Common/Config/CompiledConfig.php
index 22225bc..2db6de5 100644
--- a/system/src/Grav/Common/Config/CompiledConfig.php
+++ b/system/src/Grav/Common/Config/CompiledConfig.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/CompiledLanguages.php b/system/src/Grav/Common/Config/CompiledLanguages.php
index 6674389..0a26686 100644
--- a/system/src/Grav/Common/Config/CompiledLanguages.php
+++ b/system/src/Grav/Common/Config/CompiledLanguages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php
index 7adb523..ca027bf 100644
--- a/system/src/Grav/Common/Config/Config.php
+++ b/system/src/Grav/Common/Config/Config.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/ConfigFileFinder.php b/system/src/Grav/Common/Config/ConfigFileFinder.php
index e6b1afe..28f9dc1 100644
--- a/system/src/Grav/Common/Config/ConfigFileFinder.php
+++ b/system/src/Grav/Common/Config/ConfigFileFinder.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/Languages.php b/system/src/Grav/Common/Config/Languages.php
index 4a863a1..05798c5 100644
--- a/system/src/Grav/Common/Config/Languages.php
+++ b/system/src/Grav/Common/Config/Languages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php
index 6ff7372..f8ce943 100644
--- a/system/src/Grav/Common/Config/Setup.php
+++ b/system/src/Grav/Common/Config/Setup.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Config
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -401,7 +401,7 @@ class Setup extends Data
}
// Create security.yaml salt if it doesn't exist into existing configuration environment if possible.
- $securityFile = basename(static::$securityFile);
+ $securityFile = Utils::basename(static::$securityFile);
$securityFolder = substr(static::$securityFile, 0, -\strlen($securityFile));
$securityFolder = $locator->findResource($securityFolder, true) ?: $locator->findResource($securityFolder, true, true);
$filename = "{$securityFolder}/{$securityFile}";
diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php
index 2878199..ef6aef5 100644
--- a/system/src/Grav/Common/Data/Blueprint.php
+++ b/system/src/Grav/Common/Data/Blueprint.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -99,7 +99,7 @@ class Blueprint extends BlueprintForm
*/
public function getDefaultValue(string $name)
{
- $path = explode('.', $name) ?: [];
+ $path = explode('.', $name);
$current = $this->getDefaults();
foreach ($path as $field) {
@@ -293,15 +293,16 @@ class Blueprint extends BlueprintForm
/**
* Flatten data by using blueprints.
*
- * @param array $data
- * @param bool $includeAll
+ * @param array $data Data to be flattened.
+ * @param bool $includeAll True if undefined properties should also be included.
+ * @param string $name Property which will be flattened, useful for flattening repeating data.
* @return array
*/
- public function flattenData(array $data, bool $includeAll = false)
+ public function flattenData(array $data, bool $includeAll = false, string $name = '')
{
$this->initInternals();
- return $this->blueprintSchema->flattenData($data, $includeAll);
+ return $this->blueprintSchema->flattenData($data, $includeAll, $name);
}
diff --git a/system/src/Grav/Common/Data/BlueprintSchema.php b/system/src/Grav/Common/Data/BlueprintSchema.php
index db5e6af..8cc6303 100644
--- a/system/src/Grav/Common/Data/BlueprintSchema.php
+++ b/system/src/Grav/Common/Data/BlueprintSchema.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -115,23 +115,29 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
/**
* Flatten data by using blueprints.
*
- * @param array $data Data to be flattened.
- * @param bool $includeAll
+ * @param array $data Data to be flattened.
+ * @param bool $includeAll True if undefined properties should also be included.
+ * @param string $name Property which will be flattened, useful for flattening repeating data.
* @return array
*/
- public function flattenData(array $data, bool $includeAll = false)
+ public function flattenData(array $data, bool $includeAll = false, string $name = '')
{
+ $prefix = $name !== '' ? $name . '.' : '';
+
$list = [];
if ($includeAll) {
- foreach ($this->items as $key => $rules) {
+ $items = $name !== '' ? $this->getProperty($name)['fields'] ?? [] : $this->items;
+ foreach ($items as $key => $rules) {
$type = $rules['type'] ?? '';
if (!str_starts_with($type, '_') && !str_contains($key, '*')) {
- $list[$key] = null;
+ $list[$prefix . $key] = null;
}
}
}
- return array_replace($list, $this->flattenArray($data, $this->nested, ''));
+ $nested = $this->getNestedRules($name);
+
+ return array_replace($list, $this->flattenArray($data, $nested, $prefix));
}
/**
diff --git a/system/src/Grav/Common/Data/Blueprints.php b/system/src/Grav/Common/Data/Blueprints.php
index abe153f..dfdd46f 100644
--- a/system/src/Grav/Common/Data/Blueprints.php
+++ b/system/src/Grav/Common/Data/Blueprints.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Data/Data.php b/system/src/Grav/Common/Data/Data.php
index 4de437d..0f09b2d 100644
--- a/system/src/Grav/Common/Data/Data.php
+++ b/system/src/Grav/Common/Data/Data.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -335,6 +335,7 @@ class Data implements DataInterface, ArrayAccess, \Countable, JsonSerializable,
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->items;
diff --git a/system/src/Grav/Common/Data/DataInterface.php b/system/src/Grav/Common/Data/DataInterface.php
index b4452bb..a4bc214 100644
--- a/system/src/Grav/Common/Data/DataInterface.php
+++ b/system/src/Grav/Common/Data/DataInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php
index bfb4057..569ea51 100644
--- a/system/src/Grav/Common/Data/Validation.php
+++ b/system/src/Grav/Common/Data/Validation.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -816,7 +816,7 @@ class Validation
{
$value = static::filterArray($value, $params, $field);
- return Utils::arrayUnflattenDotNotation($value);
+ return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null;
}
/**
diff --git a/system/src/Grav/Common/Data/ValidationException.php b/system/src/Grav/Common/Data/ValidationException.php
index be6a674..9a3d900 100644
--- a/system/src/Grav/Common/Data/ValidationException.php
+++ b/system/src/Grav/Common/Data/ValidationException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Data
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php
index b8143f6..e7b1624 100644
--- a/system/src/Grav/Common/Debugger.php
+++ b/system/src/Grav/Common/Debugger.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -856,6 +856,10 @@ class Debugger
$scope = 'grav';
} elseif (strpos($errfile, '/twig/') !== false) {
$scope = 'twig';
+ // TODO: remove when upgrading to Twig 2+
+ if (str_contains($errstr, '#[\ReturnTypeWillChange]') || str_contains($errstr, 'Passing null to parameter')) {
+ return true;
+ }
} elseif (stripos($errfile, '/yaml/') !== false) {
$scope = 'yaml';
} elseif (strpos($errfile, '/vendor/') !== false) {
diff --git a/system/src/Grav/Common/Errors/BareHandler.php b/system/src/Grav/Common/Errors/BareHandler.php
index 206b57e..9093827 100644
--- a/system/src/Grav/Common/Errors/BareHandler.php
+++ b/system/src/Grav/Common/Errors/BareHandler.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Errors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php
index 3dc99c6..92f885b 100644
--- a/system/src/Grav/Common/Errors/Errors.php
+++ b/system/src/Grav/Common/Errors/Errors.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Errors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Errors/SimplePageHandler.php b/system/src/Grav/Common/Errors/SimplePageHandler.php
index 0118929..80c4f96 100644
--- a/system/src/Grav/Common/Errors/SimplePageHandler.php
+++ b/system/src/Grav/Common/Errors/SimplePageHandler.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Errors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Errors/SystemFacade.php b/system/src/Grav/Common/Errors/SystemFacade.php
index 8a7f1ce..edf2b53 100644
--- a/system/src/Grav/Common/Errors/SystemFacade.php
+++ b/system/src/Grav/Common/Errors/SystemFacade.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Errors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php
index 66fa620..2228422 100644
--- a/system/src/Grav/Common/File/CompiledFile.php
+++ b/system/src/Grav/Common/File/CompiledFile.php
@@ -3,13 +3,14 @@
/**
* @package Grav\Common\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\File;
use Exception;
+use Grav\Common\Utils;
use RocketTheme\Toolbox\File\PhpFile;
use RuntimeException;
use Throwable;
@@ -88,7 +89,7 @@ trait CompiledFile
$this->content = $cache['data'];
}
} catch (Exception $e) {
- throw new RuntimeException(sprintf('Failed to read %s: %s', basename($this->filename), $e->getMessage()), 500, $e);
+ throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($this->filename), $e->getMessage()), 500, $e);
}
return parent::content($var);
diff --git a/system/src/Grav/Common/File/CompiledJsonFile.php b/system/src/Grav/Common/File/CompiledJsonFile.php
index dae95ba..e8347bb 100644
--- a/system/src/Grav/Common/File/CompiledJsonFile.php
+++ b/system/src/Grav/Common/File/CompiledJsonFile.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/File/CompiledMarkdownFile.php b/system/src/Grav/Common/File/CompiledMarkdownFile.php
index 1107417..1083111 100644
--- a/system/src/Grav/Common/File/CompiledMarkdownFile.php
+++ b/system/src/Grav/Common/File/CompiledMarkdownFile.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/File/CompiledYamlFile.php b/system/src/Grav/Common/File/CompiledYamlFile.php
index 0fedeb7..0f0c64f 100644
--- a/system/src/Grav/Common/File/CompiledYamlFile.php
+++ b/system/src/Grav/Common/File/CompiledYamlFile.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Filesystem/Archiver.php b/system/src/Grav/Common/Filesystem/Archiver.php
index 090bc13..4c291a5 100644
--- a/system/src/Grav/Common/Filesystem/Archiver.php
+++ b/system/src/Grav/Common/Filesystem/Archiver.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php
index ecbc6ce..8dac2e5 100644
--- a/system/src/Grav/Common/Filesystem/Folder.php
+++ b/system/src/Grav/Common/Filesystem/Folder.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -513,7 +513,7 @@ abstract class Folder
}
$directories = glob($directory . '/*', GLOB_ONLYDIR);
- return count($directories);
+ return $directories ? count($directories) : false;
}
/**
@@ -530,7 +530,8 @@ abstract class Folder
}
// Go through all items in filesystem and recursively remove everything.
- $files = array_diff(scandir($folder, SCANDIR_SORT_NONE), array('.', '..'));
+ $files = scandir($folder, SCANDIR_SORT_NONE);
+ $files = $files ? array_diff($files, ['.', '..']) : [];
foreach ($files as $file) {
$path = "{$folder}/{$file}";
is_dir($path) ? self::doDelete($path) : @unlink($path);
diff --git a/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php
index 0dac81c..75c19bc 100644
--- a/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php
+++ b/system/src/Grav/Common/Filesystem/RecursiveDirectoryFilterIterator.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php
index ded0259..12d6c6b 100644
--- a/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php
+++ b/system/src/Grav/Common/Filesystem/RecursiveFolderFilterIterator.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Filesystem/ZipArchiver.php b/system/src/Grav/Common/Filesystem/ZipArchiver.php
index 6e53e70..4f2a9ee 100644
--- a/system/src/Grav/Common/Filesystem/ZipArchiver.php
+++ b/system/src/Grav/Common/Filesystem/ZipArchiver.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/FlexCollection.php b/system/src/Grav/Common/Flex/FlexCollection.php
index 6429c9e..704e21f 100644
--- a/system/src/Grav/Common/Flex/FlexCollection.php
+++ b/system/src/Grav/Common/Flex/FlexCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/FlexIndex.php b/system/src/Grav/Common/Flex/FlexIndex.php
index 44b6fdd..f903c88 100644
--- a/system/src/Grav/Common/Flex/FlexIndex.php
+++ b/system/src/Grav/Common/Flex/FlexIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/FlexObject.php b/system/src/Grav/Common/Flex/FlexObject.php
index b64aea1..887d7a3 100644
--- a/system/src/Grav/Common/Flex/FlexObject.php
+++ b/system/src/Grav/Common/Flex/FlexObject.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Traits/FlexCollectionTrait.php b/system/src/Grav/Common/Flex/Traits/FlexCollectionTrait.php
index 29b640e..b919b40 100644
--- a/system/src/Grav/Common/Flex/Traits/FlexCollectionTrait.php
+++ b/system/src/Grav/Common/Flex/Traits/FlexCollectionTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Traits/FlexCommonTrait.php b/system/src/Grav/Common/Flex/Traits/FlexCommonTrait.php
index 1077e00..9291a42 100644
--- a/system/src/Grav/Common/Flex/Traits/FlexCommonTrait.php
+++ b/system/src/Grav/Common/Flex/Traits/FlexCommonTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Traits/FlexGravTrait.php b/system/src/Grav/Common/Flex/Traits/FlexGravTrait.php
index 9d5c9e0..c34b89d 100644
--- a/system/src/Grav/Common/Flex/Traits/FlexGravTrait.php
+++ b/system/src/Grav/Common/Flex/Traits/FlexGravTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Traits/FlexIndexTrait.php b/system/src/Grav/Common/Flex/Traits/FlexIndexTrait.php
index 1d0ee5c..a71eb99 100644
--- a/system/src/Grav/Common/Flex/Traits/FlexIndexTrait.php
+++ b/system/src/Grav/Common/Flex/Traits/FlexIndexTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Traits/FlexObjectTrait.php b/system/src/Grav/Common/Flex/Traits/FlexObjectTrait.php
index 1175a3b..3c81f07 100644
--- a/system/src/Grav/Common/Flex/Traits/FlexObjectTrait.php
+++ b/system/src/Grav/Common/Flex/Traits/FlexObjectTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php b/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php
index 6b2fbc1..e4ec3d4 100644
--- a/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php
+++ b/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php b/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php
index 81dbf95..fdba503 100644
--- a/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php
+++ b/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Generic/GenericObject.php b/system/src/Grav/Common/Flex/Types/Generic/GenericObject.php
index 4a56752..eba642b 100644
--- a/system/src/Grav/Common/Flex/Types/Generic/GenericObject.php
+++ b/system/src/Grav/Common/Flex/Types/Generic/GenericObject.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php
index 7503653..b6c5230 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -34,7 +34,9 @@ use function is_string;
* Class GravPageCollection
* @package Grav\Plugin\FlexObjects\Types\GravPages
*
- * @extends FlexPageCollection
+ * @template T as PageObject
+ * @extends FlexPageCollection
+ * @implements PageCollectionInterface
*
* Incompatibilities with Grav\Common\Page\Collection:
* $page = $collection->key() will not work at all
@@ -46,10 +48,6 @@ use function is_string;
* $collection->prev() does not rewind the internal pointer
* AND most methods are immutable; they do not update the current collection, but return updated one
*
- * @method static shuffle()
- * @method static select(array $keys)
- * @method static unselect(array $keys)
- * @method static createFrom(array $elements, string $keyField = null)
* @method PageIndex getIndex()
*/
class PageCollection extends FlexPageCollection implements PageCollectionInterface
@@ -108,13 +106,11 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
}
/**
- * @return PageObject
+ * @return PageInterface
*/
public function getRoot()
{
- $index = $this->getIndex();
-
- return $index->getRoot();
+ return $this->getIndex()->getRoot();
}
/**
@@ -154,7 +150,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Add a single page to a collection
*
* @param PageInterface $page
- * @return static
+ * @return $this
*/
public function addPage(PageInterface $page)
{
@@ -174,6 +170,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param PageCollectionInterface $collection
* @return static
+ * @phpstan-return static
*/
public function merge(PageCollectionInterface $collection)
{
@@ -185,6 +182,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param PageCollectionInterface $collection
* @return static
+ * @phpstan-return static
*/
public function intersect(PageCollectionInterface $collection)
{
@@ -203,7 +201,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Return previous item.
*
* @return PageInterface|false
- * @phpstan-return PageObject|false
+ * @phpstan-return T|false
*/
public function prev()
{
@@ -218,7 +216,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Return nth item.
* @param int $key
* @return PageInterface|bool
- * @phpstan-return PageObject|false
+ * @phpstan-return T|false
*/
public function nth($key)
{
@@ -230,6 +228,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param int $num Specifies how many entries should be picked.
* @return static
+ * @phpstan-return static
*/
public function random($num = 1)
{
@@ -241,6 +240,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param array $items Items to be appended. Existing keys will be overridden with the new values.
* @return static
+ * @phpstan-return static
*/
public function append($items)
{
@@ -252,6 +252,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param int $size
* @return static[]
+ * @phpstan-return static[]
*/
public function batch($size): array
{
@@ -273,6 +274,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* @param array|null $manual
* @param int|null $sort_flags
* @return static
+ * @phpstan-return static
*/
public function order($by, $dir = 'asc', $manual = null, $sort_flags = null)
{
@@ -333,7 +335,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
$list[$key] = $child->slug();
break;
case 'basename':
- $list[$key] = basename($key);
+ $list[$key] = Utils::basename($key);
break;
case 'folder':
$list[$key] = $child->folder();
@@ -441,6 +443,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* @param string|null $endDate
* @param string|null $field
* @return static
+ * @phpstan-return static
* @throws Exception
*/
public function dateRange($startDate = null, $endDate = null, $field = null)
@@ -468,6 +471,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only visible pages
*
* @return static The collection with only visible pages
+ * @phpstan-return static
*/
public function visible()
{
@@ -485,6 +489,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only non-visible pages
*
* @return static The collection with only non-visible pages
+ * @phpstan-return static
*/
public function nonVisible()
{
@@ -502,6 +507,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only pages
*
* @return static The collection with only pages
+ * @phpstan-return static
*/
public function pages()
{
@@ -523,6 +529,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only modules
*
* @return static The collection with only modules
+ * @phpstan-return static
*/
public function modules()
{
@@ -544,6 +551,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Alias of modules()
*
* @return static
+ * @phpstan-return static
*/
public function modular()
{
@@ -554,6 +562,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Alias of pages()
*
* @return static
+ * @phpstan-return static
*/
public function nonModular()
{
@@ -564,6 +573,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only published pages
*
* @return static The collection with only published pages
+ * @phpstan-return static
*/
public function published()
{
@@ -581,6 +591,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only non-published pages
*
* @return static The collection with only non-published pages
+ * @phpstan-return static
*/
public function nonPublished()
{
@@ -598,6 +609,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only routable pages
*
* @return static The collection with only routable pages
+ * @phpstan-return static
*/
public function routable()
{
@@ -615,6 +627,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* Creates new collection with only non-routable pages
*
* @return static The collection with only non-routable pages
+ * @phpstan-return static
*/
public function nonRoutable()
{
@@ -633,6 +646,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param string $type
* @return static The collection
+ * @phpstan-return static
*/
public function ofType($type)
{
@@ -651,6 +665,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param string[] $types
* @return static The collection
+ * @phpstan-return static
*/
public function ofOneOfTheseTypes($types)
{
@@ -669,6 +684,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
*
* @param array $accessLevels
* @return static The collection
+ * @phpstan-return static
*/
public function ofOneOfTheseAccessLevels($accessLevels)
{
@@ -710,6 +726,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
/**
* @param bool $bool
* @return static
+ * @phpstan-return static
*/
public function withOrdered(bool $bool = true)
{
@@ -721,6 +738,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
/**
* @param bool $bool
* @return static
+ * @phpstan-return static
*/
public function withModules(bool $bool = true)
{
@@ -732,6 +750,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
/**
* @param bool $bool
* @return static
+ * @phpstan-return static
*/
public function withPages(bool $bool = true)
{
@@ -745,6 +764,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* @param string|null $languageCode
* @param bool|null $fallback
* @return static
+ * @phpstan-return static
*/
public function withTranslation(bool $bool = true, string $languageCode = null, bool $fallback = null)
{
@@ -778,6 +798,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
* @param array $filters
* @param bool $recursive
* @return static
+ * @phpstan-return static
*/
public function filterBy(array $filters, bool $recursive = false)
{
diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
index 5a7d773..f3978bc 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -39,7 +39,10 @@ use function is_string;
* Class GravPageObject
* @package Grav\Plugin\FlexObjects\Types\GravPages
*
- * @extends FlexPageIndex
+ * @template T of PageObject
+ * @template C of PageCollection
+ * @extends FlexPageIndex
+ * @implements PageCollectionInterface
*
* @method PageIndex withModules(bool $bool = true)
* @method PageIndex withPages(bool $bool = true)
@@ -101,6 +104,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
/**
* @param string $key
* @return PageObject|null
+ * @phpstan-return T|null
*/
public function get($key)
{
@@ -117,11 +121,13 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$element = $element->getTranslation(ltrim($params, '.'));
}
+ \assert(null === $element || $element instanceof PageObject);
+
return $element;
}
/**
- * @return PageObject
+ * @return PageInterface
*/
public function getRoot()
{
@@ -172,7 +178,8 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
/**
* @param string|null $languageCode
* @param bool|null $fallback
- * @return PageIndex
+ * @return static
+ * @phpstan-return static
*/
public function withTranslated(string $languageCode = null, bool $fallback = null)
{
@@ -276,6 +283,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* @param array $filters
* @param bool $recursive
* @return static
+ * @phpstan-return static
*/
public function filterBy(array $filters, bool $recursive = false)
{
@@ -332,6 +340,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
/**
* @param array $filters
* @return static
+ * @phpstan-return static
*/
protected function filterByParent(array $filters)
{
@@ -402,6 +411,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* @param array $entries
* @param string|null $keyField
* @return static
+ * @phpstan-return static
*/
protected function createFrom(array $entries, string $keyField = null)
{
@@ -596,8 +606,10 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
}
}
+ /** @var PageCollection|PageIndex $children */
+ $children = $page->children();
/** @var PageIndex $children */
- $children = $page->children()->getIndex();
+ $children = $children->getIndex();
$selectedChildren = $children->filterBy($filters, true);
/** @var Header $header */
@@ -627,7 +639,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$payload = [
'name' => $child->menu(),
'value' => $child->rawRoute(),
- 'item-key' => basename($child->rawRoute() ?? ''),
+ 'item-key' => Utils::basename($child->rawRoute() ?? ''),
'filename' => $child->folder(),
'extension' => $child->extension(),
'type' => 'dir',
@@ -676,13 +688,15 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$extras = array_filter($extras, static function ($v) {
return $v !== null;
});
+
+ /** @var PageIndex $tmp */
$tmp = $child->children()->getIndex();
$child_count = $tmp->count();
$count = $filters ? $tmp->filterBy($filters, true)->count() : null;
$route = $child->getRoute();
$route = $route ? ($route->toString(false) ?: '/') : '';
$payload = [
- 'item-key' => htmlspecialchars(basename($child->rawRoute() ?? $child->getKey())),
+ 'item-key' => htmlspecialchars(Utils::basename($child->rawRoute() ?? $child->getKey())),
'icon' => $icon,
'title' => htmlspecialchars($child->menu()),
'route' => [
@@ -787,6 +801,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageInterface $page
* @return PageCollection
+ * @phpstan-return C
*/
public function addPage(PageInterface $page)
{
@@ -798,6 +813,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Create a copy of this collection
*
* @return static
+ * @phpstan-return static
*/
public function copy()
{
@@ -810,6 +826,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageCollectionInterface $collection
* @return PageCollection
+ * @phpstan-return C
*/
public function merge(PageCollectionInterface $collection)
{
@@ -822,6 +839,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageCollectionInterface $collection
* @return PageCollection
+ * @phpstan-return C
*/
public function intersect(PageCollectionInterface $collection)
{
@@ -833,6 +851,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param int $size
* @return PageCollection[]
+ * @phpstan-return C[]
*/
public function batch($size)
{
@@ -844,6 +863,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string $key
* @return PageObject|null
+ * @phpstan-return T|null
* @throws InvalidArgumentException
*/
public function remove($key)
@@ -859,6 +879,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* @param array $manual
* @param string $sort_flags
* @return static
+ * @phpstan-return static
*/
public function order($by, $dir = 'asc', $manual = null, $sort_flags = null)
{
@@ -902,6 +923,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string $path
* @return PageObject|null The previous item.
+ * @phpstan-return T|null
*/
public function prevSibling($path)
{
@@ -916,6 +938,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string $path
* @return PageObject|null The next item.
+ * @phpstan-return T|null
*/
public function nextSibling($path)
{
@@ -931,6 +954,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* @param string $path
* @param int $direction either -1 or +1
* @return PageObject|false The sibling item.
+ * @phpstan-return T|false
*/
public function adjacentSibling($path, $direction = 1)
{
@@ -964,6 +988,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* @param string|null $endDate
* @param string|null $field
* @return static
+ * @phpstan-return static
* @throws Exception
*/
public function dateRange($startDate = null, $endDate = null, $field = null)
@@ -988,6 +1013,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only visible pages
*
* @return static The collection with only visible pages
+ * @phpstan-return static
*/
public function visible()
{
@@ -1000,6 +1026,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only non-visible pages
*
* @return static The collection with only non-visible pages
+ * @phpstan-return static
*/
public function nonVisible()
{
@@ -1012,6 +1039,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only non-modular pages
*
* @return static The collection with only non-modular pages
+ * @phpstan-return static
*/
public function pages()
{
@@ -1024,6 +1052,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only modular pages
*
* @return static The collection with only modular pages
+ * @phpstan-return static
*/
public function modules()
{
@@ -1036,6 +1065,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only modular pages
*
* @return static The collection with only modular pages
+ * @phpstan-return static
*/
public function modular()
{
@@ -1046,6 +1076,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only non-modular pages
*
* @return static The collection with only non-modular pages
+ * @phpstan-return static
*/
public function nonModular()
{
@@ -1056,6 +1087,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only published pages
*
* @return static The collection with only published pages
+ * @phpstan-return static
*/
public function published()
{
@@ -1068,6 +1100,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only non-published pages
*
* @return static The collection with only non-published pages
+ * @phpstan-return static
*/
public function nonPublished()
{
@@ -1080,6 +1113,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only routable pages
*
* @return static The collection with only routable pages
+ * @phpstan-return static
*/
public function routable()
{
@@ -1092,6 +1126,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Creates new collection with only non-routable pages
*
* @return static The collection with only non-routable pages
+ * @phpstan-return static
*/
public function nonRoutable()
{
@@ -1105,6 +1140,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string $type
* @return static The collection
+ * @phpstan-return static
*/
public function ofType($type)
{
@@ -1118,6 +1154,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string[] $types
* @return static The collection
+ * @phpstan-return static
*/
public function ofOneOfTheseTypes($types)
{
@@ -1131,6 +1168,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param array $accessLevels
* @return static The collection
+ * @phpstan-return static
*/
public function ofOneOfTheseAccessLevels($accessLevels)
{
diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php
index 4c83f95..a05f0eb 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -25,9 +25,9 @@ use Grav\Common\Page\Pages;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
-use Grav\Framework\Flex\FlexObject;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use Grav\Framework\Flex\Pages\FlexPageObject;
+use Grav\Framework\Object\ObjectCollection;
use Grav\Framework\Route\Route;
use Grav\Framework\Route\RouteFactory;
use Grav\Plugin\Admin\Admin;
@@ -93,11 +93,6 @@ class PageObject extends FlexPageObject
}
}
- public function translated(): bool
- {
- return $this->translatedLanguages(true) ? true : false;
- }
-
/**
* @param string|array $query
* @return Route|null
@@ -282,7 +277,7 @@ class PageObject extends FlexPageObject
/**
* @param array|bool $reorder
- * @return FlexObject|FlexObjectInterface
+ * @return static
*/
public function save($reorder = true)
{
@@ -317,7 +312,7 @@ class PageObject extends FlexPageObject
}
/**
- * @return PageObject
+ * @return static
*/
public function delete()
{
@@ -391,6 +386,7 @@ class PageObject extends FlexPageObject
/**
* @param array $ordering
* @return PageCollection|null
+ * @phpstan-return ObjectCollection|null
*/
protected function reorderSiblings(array $ordering)
{
@@ -466,7 +462,9 @@ class PageObject extends FlexPageObject
if ($isMoved && $this->order() !== false) {
$parentKey = $this->getProperty('parent_key');
if ($parentKey === '') {
- $newParent = $this->getFlexDirectory()->getIndex()->getRoot();
+ /** @var PageIndex $index */
+ $index = $this->getFlexDirectory()->getIndex();
+ $newParent = $index->getRoot();
} else {
$newParent = $this->getFlexDirectory()->getObject($parentKey, 'storage_key');
if (!$newParent instanceof PageInterface) {
@@ -627,7 +625,14 @@ class PageObject extends FlexPageObject
// If current filter does not match, we still may have match as a parent.
if ($matches === false) {
- return $recursive && $this->children()->getIndex()->filterBy($filters, true)->count() > 0;
+ if (!$recursive) {
+ return false;
+ }
+
+ /** @var PageIndex $index */
+ $index = $this->children()->getIndex();
+
+ return $index->filterBy($filters, true)->count() > 0;
}
}
diff --git a/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php b/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php
index ba7fa06..f590e36 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,13 +16,13 @@ use Grav\Common\Debugger;
use Grav\Common\Flex\Types\Pages\PageIndex;
use Grav\Common\Grav;
use Grav\Common\Language\Language;
+use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
use Grav\Framework\Flex\Storage\FolderStorage;
use RocketTheme\Toolbox\File\MarkdownFile;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use RuntimeException;
use SplFileInfo;
-use function assert;
use function in_array;
use function is_string;
@@ -277,7 +277,7 @@ class PageStorage extends FolderStorage
} else {
$params = $template = $language = '';
}
- $objectKey = basename($key);
+ $objectKey = Utils::basename($key);
if (preg_match('|^(\d+)\.(.+)$|', $objectKey, $matches)) {
[, $order, $folder] = $matches;
} else {
@@ -584,7 +584,7 @@ class PageStorage extends FolderStorage
$mark = $matches[2] ?? '';
$ext = $matches[1] ?? '';
$ext .= $this->dataExt;
- $markdown[$mark][basename($k, $ext)] = $timestamp;
+ $markdown[$mark][Utils::basename($k, $ext)] = $timestamp;
}
$modified = max($modified, $timestamp);
@@ -675,7 +675,7 @@ class PageStorage extends FolderStorage
/** @phpstan-var array{'storage_key': string, 'storage_timestamp': int, 'children': array} $parent */
$parent = &$list[$parentKey];
- $basename = basename($storage_key);
+ $basename = Utils::basename($storage_key);
if (isset($parent['children'][$basename])) {
$timestamp = $meta['storage_timestamp'];
diff --git a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageContentTrait.php b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageContentTrait.php
index 1bde7b0..9a2c7c3 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageContentTrait.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageContentTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageLegacyTrait.php b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageLegacyTrait.php
index 589ea88..98f3949 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageLegacyTrait.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageLegacyTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageRoutableTrait.php b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageRoutableTrait.php
index 3b490a5..ace74dc 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageRoutableTrait.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageRoutableTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageTranslateTrait.php b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageTranslateTrait.php
index dff42c9..a30ae1a 100644
--- a/system/src/Grav/Common/Flex/Types/Pages/Traits/PageTranslateTrait.php
+++ b/system/src/Grav/Common/Flex/Types/Pages/Traits/PageTranslateTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php
index 93abbf8..3a91d77 100644
--- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php
+++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -27,7 +27,7 @@ class UserGroupCollection extends FlexCollection
public static function getCachedMethods(): array
{
return [
- 'authorize' => 'session',
+ 'authorize' => false,
] + parent::getCachedMethods();
}
diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php
index 4bee5ac..66de52e 100644
--- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php
+++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php
index ea68fa1..4a59d52 100644
--- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php
+++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -37,7 +37,7 @@ class UserGroupObject extends FlexObject implements UserGroupInterface
public static function getCachedMethods(): array
{
return [
- 'authorize' => 'session',
+ 'authorize' => false,
] + parent::getCachedMethods();
}
diff --git a/system/src/Grav/Common/Flex/Types/Users/Storage/UserFileStorage.php b/system/src/Grav/Common/Flex/Types/Users/Storage/UserFileStorage.php
index f565c9f..664f24f 100644
--- a/system/src/Grav/Common/Flex/Types/Users/Storage/UserFileStorage.php
+++ b/system/src/Grav/Common/Flex/Types/Users/Storage/UserFileStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Users/Storage/UserFolderStorage.php b/system/src/Grav/Common/Flex/Types/Users/Storage/UserFolderStorage.php
index 7d9924e..a037f0e 100644
--- a/system/src/Grav/Common/Flex/Types/Users/Storage/UserFolderStorage.php
+++ b/system/src/Grav/Common/Flex/Types/Users/Storage/UserFolderStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Users/Traits/UserObjectLegacyTrait.php b/system/src/Grav/Common/Flex/Types/Users/Traits/UserObjectLegacyTrait.php
index b0fc0c4..07acf66 100644
--- a/system/src/Grav/Common/Flex/Types/Users/Traits/UserObjectLegacyTrait.php
+++ b/system/src/Grav/Common/Flex/Types/Users/Traits/UserObjectLegacyTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -84,6 +84,7 @@ trait UserObjectLegacyTrait
* @return int
* @deprecated 1.6 Method makes no sense for user account.
*/
+ #[\ReturnTypeWillChange]
public function count()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6', E_USER_DEPRECATED);
diff --git a/system/src/Grav/Common/Flex/Types/Users/UserCollection.php b/system/src/Grav/Common/Flex/Types/Users/UserCollection.php
index 9b6490a..f5641e7 100644
--- a/system/src/Grav/Common/Flex/Types/Users/UserCollection.php
+++ b/system/src/Grav/Common/Flex/Types/Users/UserCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php
index 6e0bc65..4a33b73 100644
--- a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php
+++ b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -164,7 +164,7 @@ class UserIndex extends FlexIndex implements UserCollectionInterface
*/
protected static function filterUsername(string $key, FlexStorageInterface $storage): string
{
- return $storage->normalizeKey($key);
+ return method_exists($storage, 'normalizeKey') ? $storage->normalizeKey($key) : $key;
}
/**
diff --git a/system/src/Grav/Common/Flex/Types/Users/UserObject.php b/system/src/Grav/Common/Flex/Types/Users/UserObject.php
index 424e5eb..9dec972 100644
--- a/system/src/Grav/Common/Flex/Types/Users/UserObject.php
+++ b/system/src/Grav/Common/Flex/Types/Users/UserObject.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -30,6 +30,7 @@ use Grav\Common\Flex\Types\UserGroups\UserGroupCollection;
use Grav\Common\Flex\Types\UserGroups\UserGroupIndex;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\User\Traits\UserTrait;
+use Grav\Common\Utils;
use Grav\Framework\File\Formatter\JsonFormatter;
use Grav\Framework\File\Formatter\YamlFormatter;
use Grav\Framework\Filesystem\Filesystem;
@@ -79,6 +80,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
/** @var Closure|null */
static public $authorizeCallable;
+ /** @var Closure|null */
+ static public $isAuthorizedCallable;
/** @var array|null */
protected $_uploads_original;
@@ -123,7 +126,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
// Define username if it's not set.
if (!isset($elements['username'])) {
$storageKey = $elements['__META']['storage_key'] ?? null;
- if (null !== $storageKey && $key === $directory->getStorage()->normalizeKey($storageKey)) {
+ $storage = $directory->getStorage();
+ if (null !== $storageKey && method_exists($storage, 'normalizeKey') && $key === $storage->normalizeKey($storageKey)) {
$elements['username'] = $storageKey;
} else {
$elements['username'] = $key;
@@ -138,6 +142,14 @@ class UserObject extends FlexObject implements UserInterface, Countable
parent::__construct($elements, $key, $directory, $validate);
}
+ public function __clone()
+ {
+ $this->_access = null;
+ $this->_groups = null;
+
+ parent::__clone();
+ }
+
/**
* @return void
*/
@@ -231,13 +243,19 @@ class UserObject extends FlexObject implements UserInterface, Countable
}
/**
+ * @param UserInterface|null $user
* @return bool
*/
- public function isMyself(): bool
+ public function isMyself(?UserInterface $user = null): bool
{
- $me = $this->getActiveUser();
+ if (null === $user) {
+ $user = $this->getActiveUser();
+ if ($user && !$user->authenticated) {
+ $user = null;
+ }
+ }
- return $me && $me->authenticated && $this->username === $me->username;
+ return $user && $this->username === $user->username;
}
/**
@@ -277,8 +295,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
// Check custom application access.
$authorizeCallable = static::$authorizeCallable;
if ($authorizeCallable instanceof Closure) {
- $authorizeCallable->bindTo($this);
- $authorized = $authorizeCallable($action, $scope);
+ $callable = $authorizeCallable->bindTo($this, $this);
+ $authorized = $callable($action, $scope);
if (is_bool($authorized)) {
return $authorized;
}
@@ -628,7 +646,7 @@ class UserObject extends FlexObject implements UserInterface, Countable
$medium = MediumFactory::fromFile($path);
if ($medium) {
$media->add($path, $medium);
- $name = basename($path);
+ $name = Utils::basename($path);
if ($name !== $path) {
$media->add($name, $medium);
}
@@ -648,7 +666,7 @@ class UserObject extends FlexObject implements UserInterface, Countable
// Check for shared media
if (!$folder && !$this->getFlexDirectory()->getMediaFolder()) {
$this->_loadMedia = false;
- $folder = $this->getBlueprint()->fields()['avatar']['destination'] ?? 'user://accounts/avatars';
+ $folder = $this->getBlueprint()->fields()['avatar']['destination'] ?? 'account://avatars';
}
return $folder;
@@ -683,6 +701,16 @@ class UserObject extends FlexObject implements UserInterface, Countable
*/
protected function isAuthorizedOverride(UserInterface $user, string $action, string $scope, bool $isMe = false): ?bool
{
+ // Check custom application access.
+ $isAuthorizedCallable = static::$isAuthorizedCallable;
+ if ($isAuthorizedCallable instanceof Closure) {
+ $callable = $isAuthorizedCallable->bindTo($this, $this);
+ $authorized = $callable($user, $action, $scope, $isMe);
+ if (is_bool($authorized)) {
+ return $authorized;
+ }
+ }
+
if ($user instanceof self && $user->getStorageKey() === $this->getStorageKey()) {
// User cannot delete his own account, otherwise he has full access.
return $action !== 'delete';
@@ -787,7 +815,7 @@ class UserObject extends FlexObject implements UserInterface, Countable
}
// Calculate path without the retina scaling factor.
- $realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', basename($filepath));
+ $realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', Utils::basename($filepath));
$list[$filename] = [$file, $settings];
@@ -898,7 +926,9 @@ class UserObject extends FlexObject implements UserInterface, Countable
protected function getGroups()
{
if (null === $this->_groups) {
- $this->_groups = $this->getUserGroups()->select((array)$this->getProperty('groups'));
+ /** @var UserGroupIndex $groups */
+ $groups = $this->getUserGroups()->select((array)$this->getProperty('groups'));
+ $this->_groups = $groups;
}
return $this->_groups;
@@ -910,7 +940,7 @@ class UserObject extends FlexObject implements UserInterface, Countable
protected function getAccess(): Access
{
if (null === $this->_access) {
- $this->getProperty('access');
+ $this->_access = new Access($this->getProperty('access'));
}
return $this->_access;
@@ -926,8 +956,6 @@ class UserObject extends FlexObject implements UserInterface, Countable
$value = new Access($value);
}
- $this->_access = $value;
-
return $value->jsonSerialize();
}
diff --git a/system/src/Grav/Common/Form/FormFlash.php b/system/src/Grav/Common/Form/FormFlash.php
index 430f15e..7acaf7f 100644
--- a/system/src/Grav/Common/Form/FormFlash.php
+++ b/system/src/Grav/Common/Form/FormFlash.php
@@ -3,13 +3,14 @@
/**
* @package Grav\Common\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Form;
use Grav\Common\Filesystem\Folder;
+use Grav\Common\Utils;
use Grav\Framework\Form\FormFlash as FrameworkFormFlash;
use function is_array;
@@ -58,7 +59,7 @@ class FormFlash extends FrameworkFormFlash
Folder::create($tmp_dir);
$tmp_file = $upload['file']['tmp_name'];
- $basename = basename($tmp_file);
+ $basename = Utils::basename($tmp_file);
if (!move_uploaded_file($tmp_file, $tmp_dir . '/' . $basename)) {
return false;
@@ -90,7 +91,7 @@ class FormFlash extends FrameworkFormFlash
Folder::create($tmp_dir);
$tmp_file = $upload['file']['tmp_name'];
- $basename = basename($tmp_file);
+ $basename = Utils::basename($tmp_file);
if (!move_uploaded_file($tmp_file, $tmp_dir . '/' . $basename)) {
return false;
diff --git a/system/src/Grav/Common/GPM/AbstractCollection.php b/system/src/Grav/Common/GPM/AbstractCollection.php
index b5b867e..91fa69e 100644
--- a/system/src/Grav/Common/GPM/AbstractCollection.php
+++ b/system/src/Grav/Common/GPM/AbstractCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Common/AbstractPackageCollection.php b/system/src/Grav/Common/GPM/Common/AbstractPackageCollection.php
index 5d6ad9f..7b918e0 100644
--- a/system/src/Grav/Common/GPM/Common/AbstractPackageCollection.php
+++ b/system/src/Grav/Common/GPM/Common/AbstractPackageCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Common/CachedCollection.php b/system/src/Grav/Common/GPM/Common/CachedCollection.php
index 172ba93..c3b62e5 100644
--- a/system/src/Grav/Common/GPM/Common/CachedCollection.php
+++ b/system/src/Grav/Common/GPM/Common/CachedCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Common/Package.php b/system/src/Grav/Common/GPM/Common/Package.php
index e06ebb6..5d96011 100644
--- a/system/src/Grav/Common/GPM/Common/Package.php
+++ b/system/src/Grav/Common/GPM/Common/Package.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -45,6 +45,7 @@ class Package
* @param string $key
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __get($key)
{
return $this->data->get($key);
@@ -55,6 +56,7 @@ class Package
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($key, $value)
{
$this->data->set($key, $value);
@@ -64,6 +66,7 @@ class Package
* @param string $key
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($key)
{
return isset($this->data->{$key});
@@ -72,6 +75,7 @@ class Package
/**
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->toJson();
diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php
index 4505696..7031945 100644
--- a/system/src/Grav/Common/GPM/GPM.php
+++ b/system/src/Grav/Common/GPM/GPM.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -74,6 +74,7 @@ class GPM extends Iterator
* @param string $offset Asset name value
* @return mixed Asset value
*/
+ #[\ReturnTypeWillChange]
public function __get($offset)
{
switch ($offset) {
@@ -90,6 +91,7 @@ class GPM extends Iterator
* @param string $offset Asset name value
* @return bool True if the value is set
*/
+ #[\ReturnTypeWillChange]
public function __isset($offset)
{
switch ($offset) {
@@ -629,7 +631,7 @@ class GPM extends Iterator
throw new \RuntimeException("Malformed GPM URL: {$package_file}");
}
- $filename = basename($package['path'] ?? '');
+ $filename = Utils::basename($package['path'] ?? '');
if (Grav::instance()['config']->get('system.gpm.official_gpm_only') && ($package['host'] ?? null) !== 'getgrav.org') {
throw new RuntimeException('Only official GPM URLs are allowed. You can modify this behavior in the System configuration.');
@@ -658,7 +660,7 @@ class GPM extends Iterator
$package_file = realpath($package_file);
if ($package_file && file_exists($package_file)) {
- $filename = basename($package_file);
+ $filename = Utils::basename($package_file);
Folder::create($tmp);
copy($package_file, $tmp . DS . $filename);
return $tmp . DS . $filename;
@@ -690,7 +692,7 @@ class GPM extends Iterator
}
// either theme or plugin
- $name = basename($source);
+ $name = Utils::basename($source);
if (Utils::contains($name, 'theme')) {
return 'theme';
}
@@ -728,7 +730,7 @@ class GPM extends Iterator
$glob = glob($source . '*.yaml') ?: [];
foreach ($glob as $filename) {
- $name = strtolower(basename($filename, '.yaml'));
+ $name = strtolower(Utils::basename($filename, '.yaml'));
if (in_array($name, $ignore_yaml_files)) {
continue;
}
diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php
index 639240b..8a1a530 100644
--- a/system/src/Grav/Common/GPM/Installer.php
+++ b/system/src/Grav/Common/GPM/Installer.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -12,6 +12,7 @@ namespace Grav\Common\GPM;
use DirectoryIterator;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
+use Grav\Common\Utils;
use RuntimeException;
use ZipArchive;
use function count;
@@ -192,7 +193,7 @@ class Installer
$package_folder_name = $zip->getNameIndex(0);
if ($package_folder_name === false) {
- throw new \RuntimeException('Bad package file: ' . basename($zip_file));
+ throw new \RuntimeException('Bad package file: ' . Utils::basename($zip_file));
}
$package_folder_name = preg_replace('#\./$#', '', $package_folder_name);
$zip->close();
diff --git a/system/src/Grav/Common/GPM/Licenses.php b/system/src/Grav/Common/GPM/Licenses.php
index 825343d..e932bd4 100644
--- a/system/src/Grav/Common/GPM/Licenses.php
+++ b/system/src/Grav/Common/GPM/Licenses.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Local/AbstractPackageCollection.php b/system/src/Grav/Common/GPM/Local/AbstractPackageCollection.php
index d1f3e46..bc7ceab 100644
--- a/system/src/Grav/Common/GPM/Local/AbstractPackageCollection.php
+++ b/system/src/Grav/Common/GPM/Local/AbstractPackageCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Local/Package.php b/system/src/Grav/Common/GPM/Local/Package.php
index ffe2c63..08444a7 100644
--- a/system/src/Grav/Common/GPM/Local/Package.php
+++ b/system/src/Grav/Common/GPM/Local/Package.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Local/Packages.php b/system/src/Grav/Common/GPM/Local/Packages.php
index 0290296..b63b93b 100644
--- a/system/src/Grav/Common/GPM/Local/Packages.php
+++ b/system/src/Grav/Common/GPM/Local/Packages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Local/Plugins.php b/system/src/Grav/Common/GPM/Local/Plugins.php
index 8a6574b..a1626f8 100644
--- a/system/src/Grav/Common/GPM/Local/Plugins.php
+++ b/system/src/Grav/Common/GPM/Local/Plugins.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Local/Themes.php b/system/src/Grav/Common/GPM/Local/Themes.php
index 73253cc..d153794 100644
--- a/system/src/Grav/Common/GPM/Local/Themes.php
+++ b/system/src/Grav/Common/GPM/Local/Themes.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Remote/AbstractPackageCollection.php b/system/src/Grav/Common/GPM/Remote/AbstractPackageCollection.php
index 9e68d66..02e98e7 100644
--- a/system/src/Grav/Common/GPM/Remote/AbstractPackageCollection.php
+++ b/system/src/Grav/Common/GPM/Remote/AbstractPackageCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Remote/GravCore.php b/system/src/Grav/Common/GPM/Remote/GravCore.php
index f93209e..2998975 100644
--- a/system/src/Grav/Common/GPM/Remote/GravCore.php
+++ b/system/src/Grav/Common/GPM/Remote/GravCore.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Remote/Package.php b/system/src/Grav/Common/GPM/Remote/Package.php
index c37d6a0..5193255 100644
--- a/system/src/Grav/Common/GPM/Remote/Package.php
+++ b/system/src/Grav/Common/GPM/Remote/Package.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -32,6 +32,7 @@ class Package extends BasePackage implements \JsonSerializable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->data->toArray();
diff --git a/system/src/Grav/Common/GPM/Remote/Packages.php b/system/src/Grav/Common/GPM/Remote/Packages.php
index f55c12d..0ac2ef9 100644
--- a/system/src/Grav/Common/GPM/Remote/Packages.php
+++ b/system/src/Grav/Common/GPM/Remote/Packages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Remote/Plugins.php b/system/src/Grav/Common/GPM/Remote/Plugins.php
index a134a10..8383cd7 100644
--- a/system/src/Grav/Common/GPM/Remote/Plugins.php
+++ b/system/src/Grav/Common/GPM/Remote/Plugins.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Remote/Themes.php b/system/src/Grav/Common/GPM/Remote/Themes.php
index 160ac97..a8ee9fa 100644
--- a/system/src/Grav/Common/GPM/Remote/Themes.php
+++ b/system/src/Grav/Common/GPM/Remote/Themes.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/GPM/Upgrader.php b/system/src/Grav/Common/GPM/Upgrader.php
index dfa6eb1..b3e6869 100644
--- a/system/src/Grav/Common/GPM/Upgrader.php
+++ b/system/src/Grav/Common/GPM/Upgrader.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\GPM
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Getters.php b/system/src/Grav/Common/Getters.php
index 916d524..ed03499 100644
--- a/system/src/Grav/Common/Getters.php
+++ b/system/src/Grav/Common/Getters.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,6 +28,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset Medium name value
* @param mixed $value Medium value
*/
+ #[\ReturnTypeWillChange]
public function __set($offset, $value)
{
$this->offsetSet($offset, $value);
@@ -39,6 +40,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset Medium name value
* @return mixed Medium value
*/
+ #[\ReturnTypeWillChange]
public function __get($offset)
{
return $this->offsetGet($offset);
@@ -50,6 +52,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset Medium name value
* @return boolean True if the value is set
*/
+ #[\ReturnTypeWillChange]
public function __isset($offset)
{
return $this->offsetExists($offset);
@@ -60,6 +63,7 @@ abstract class Getters implements ArrayAccess, Countable
*
* @param int|string $offset The name value to unset
*/
+ #[\ReturnTypeWillChange]
public function __unset($offset)
{
$this->offsetUnset($offset);
@@ -129,6 +133,7 @@ abstract class Getters implements ArrayAccess, Countable
/**
* @return int
*/
+ #[\ReturnTypeWillChange]
public function count()
{
if ($this->gettersVariable) {
diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php
index 2398c11..b9b44a4 100644
--- a/system/src/Grav/Common/Grav.php
+++ b/system/src/Grav/Common/Grav.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -49,7 +49,9 @@ use Grav\Common\Twig\Twig;
use Grav\Framework\DI\Container;
use Grav\Framework\Psr7\Response;
use Grav\Framework\RequestHandler\RequestHandler;
+use Grav\Framework\Route\Route;
use Grav\Framework\Session\Messages;
+use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use RocketTheme\Toolbox\Event\Event;
@@ -60,8 +62,10 @@ use function call_user_func_array;
use function function_exists;
use function get_class;
use function in_array;
+use function is_array;
use function is_callable;
use function is_int;
+use function is_string;
use function strlen;
/**
@@ -343,7 +347,7 @@ class Grav extends Container
* Please use this method instead of calling `die();` or `exit();`. Note that you need to create a response object.
*
* @param ResponseInterface $response
- * @return void
+ * @return never-return
*/
public function close(ResponseInterface $response): void
{
@@ -395,7 +399,7 @@ class Grav extends Container
/**
* @param ResponseInterface $response
- * @return void
+ * @return never-return
* @deprecated 1.7 Do not use
*/
public function exit(ResponseInterface $response): void
@@ -408,9 +412,9 @@ class Grav extends Container
*
* Please use this method instead of calling `header("Location: {$url}", true, 302); exit();`.
*
- * @param string $route Internal route.
+ * @param Route|string $route Internal route.
* @param int|null $code Redirection code (30x)
- * @return void
+ * @return never-return
*/
public function redirect($route, $code = null): void
{
@@ -422,7 +426,7 @@ class Grav extends Container
/**
* Returns redirect response object from Grav.
*
- * @param string $route Internal route.
+ * @param Route|string $route Internal route.
* @param int|null $code Redirection code (30x)
* @return ResponseInterface
*/
@@ -431,39 +435,45 @@ class Grav extends Container
/** @var Uri $uri */
$uri = $this['uri'];
- // Clean route for redirect
- $route = preg_replace("#^\/[\\\/]+\/#", '/', $route);
+ if (is_string($route)) {
+ // Clean route for redirect
+ $route = preg_replace("#^\/[\\\/]+\/#", '/', $route);
+
+ if (null === $code) {
+ // Check for redirect code in the route: e.g. /new/[301], /new[301]/route or /new[301].html
+ $regex = '/.*(\[(30[1-7])\])(.\w+|\/.*?)?$/';
+ preg_match($regex, $route, $matches);
+ if ($matches) {
+ $route = str_replace($matches[1], '', $matches[0]);
+ $code = $matches[2];
+ }
+ }
+
+ if ($uri::isExternal($route)) {
+ $url = $route;
+ } else {
+ $url = rtrim($uri->rootUrl(), '/') . '/';
+
+ if ($this['config']->get('system.pages.redirect_trailing_slash', true)) {
+ $url .= trim($route, '/'); // Remove trailing slash
+ } else {
+ $url .= ltrim($route, '/'); // Support trailing slash default routes
+ }
+ }
+ } elseif ($route instanceof Route) {
+ $url = $route->toString(true);
+ } else {
+ throw new InvalidArgumentException('Bad $route');
+ }
if ($code < 300 || $code > 399) {
$code = null;
}
- if (null === $code) {
- // Check for redirect code in the route: e.g. /new/[301], /new[301]/route or /new[301].html
- $regex = '/.*(\[(30[1-7])\])(.\w+|\/.*?)?$/';
- preg_match($regex, $route, $matches);
- if ($matches) {
- $route = str_replace($matches[1], '', $matches[0]);
- $code = $matches[2];
- }
- }
-
if ($code === null) {
$code = $this['config']->get('system.pages.redirect_default_code', 302);
}
- if ($uri::isExternal($route)) {
- $url = $route;
- } else {
- $url = rtrim($uri->rootUrl(), '/') . '/';
-
- if ($this['config']->get('system.pages.redirect_trailing_slash', true)) {
- $url .= trim($route, '/'); // Remove trailing slash
- } else {
- $url .= ltrim($route, '/'); // Support trailing slash default routes
- }
- }
-
if ($uri->extension() === 'json') {
return new Response(200, ['Content-Type' => 'application/json'], json_encode(['code' => $code, 'redirect' => $url], JSON_THROW_ON_ERROR));
}
@@ -643,6 +653,7 @@ class Grav extends Container
* @param array $args
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
$closure = $this->{$method} ?? null;
@@ -719,7 +730,10 @@ class Grav extends Container
*/
public function fallbackUrl($path)
{
- $this->fireEvent('onPageFallBackUrl');
+ $path_parts = Utils::pathinfo($path);
+ if (!is_array($path_parts)) {
+ return false;
+ }
/** @var Uri $uri */
$uri = $this['uri'];
@@ -727,10 +741,28 @@ class Grav extends Container
/** @var Config $config */
$config = $this['config'];
- $uri_extension = strtolower($uri->extension());
- $fallback_types = $config->get('system.media.allowed_fallback_types', null);
+ /** @var Pages $pages */
+ $pages = $this['pages'];
+ $page = $pages->find($path_parts['dirname'], true);
+
+ $uri_extension = strtolower($uri->extension() ?? '');
+ $fallback_types = $config->get('system.media.allowed_fallback_types');
$supported_types = $config->get('media.types');
+ $parsed_url = parse_url(rawurldecode($uri->basename()));
+ $media_file = $parsed_url['path'];
+
+ $event = new Event([
+ 'uri' => $uri,
+ 'page' => &$page,
+ 'filename' => &$media_file,
+ 'extension' => $uri_extension,
+ 'allowed_fallback_types' => &$fallback_types,
+ 'media_types' => &$supported_types
+ ]);
+
+ $this->fireEvent('onPageFallBackUrl', $event);
+
// Check whitelist first, then ensure extension is a valid media type
if (!empty($fallback_types) && !in_array($uri_extension, $fallback_types, true)) {
return false;
@@ -739,16 +771,8 @@ class Grav extends Container
return false;
}
- $path_parts = pathinfo($path);
-
- /** @var Pages $pages */
- $pages = $this['pages'];
- $page = $pages->find($path_parts['dirname'], true);
-
if ($page) {
$media = $page->media()->all();
- $parsed_url = parse_url(rawurldecode($uri->basename()));
- $media_file = $parsed_url['path'];
// if this is a media object, try actions first
if (isset($media[$media_file])) {
diff --git a/system/src/Grav/Common/GravTrait.php b/system/src/Grav/Common/GravTrait.php
index 4638905..5416286 100644
--- a/system/src/Grav/Common/GravTrait.php
+++ b/system/src/Grav/Common/GravTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/HTTP/Client.php b/system/src/Grav/Common/HTTP/Client.php
index cd4f8db..c85d6b2 100644
--- a/system/src/Grav/Common/HTTP/Client.php
+++ b/system/src/Grav/Common/HTTP/Client.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\HTTP
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/HTTP/Response.php b/system/src/Grav/Common/HTTP/Response.php
index 4a05136..4a5bc8b 100644
--- a/system/src/Grav/Common/HTTP/Response.php
+++ b/system/src/Grav/Common/HTTP/Response.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\HTTP
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Helpers/Base32.php b/system/src/Grav/Common/Helpers/Base32.php
index 825c1ec..0d1c21a 100644
--- a/system/src/Grav/Common/Helpers/Base32.php
+++ b/system/src/Grav/Common/Helpers/Base32.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Helpers/Excerpts.php b/system/src/Grav/Common/Helpers/Excerpts.php
index 173850a..a62c7e5 100644
--- a/system/src/Grav/Common/Helpers/Excerpts.php
+++ b/system/src/Grav/Common/Helpers/Excerpts.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Helpers/Exif.php b/system/src/Grav/Common/Helpers/Exif.php
index 36e391f..a7dc973 100644
--- a/system/src/Grav/Common/Helpers/Exif.php
+++ b/system/src/Grav/Common/Helpers/Exif.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Helpers/LogViewer.php b/system/src/Grav/Common/Helpers/LogViewer.php
index 187828a..cf5ffe9 100644
--- a/system/src/Grav/Common/Helpers/LogViewer.php
+++ b/system/src/Grav/Common/Helpers/LogViewer.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -145,7 +145,7 @@ class LogViewer
'logger' => $data['logger'],
'level' => $data['level'],
'message' => $data['message'],
- 'trace' => isset($data['trace']) ? $this->parseTrace($data['trace']) : null,
+ 'trace' => isset($data['trace']) ? self::parseTrace($data['trace']) : null,
'context' => json_decode($data['context'], true),
'extra' => json_decode($data['extra'], true)
];
diff --git a/system/src/Grav/Common/Helpers/Truncator.php b/system/src/Grav/Common/Helpers/Truncator.php
index 0a701b6..03c3eea 100644
--- a/system/src/Grav/Common/Helpers/Truncator.php
+++ b/system/src/Grav/Common/Helpers/Truncator.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Helpers/YamlLinter.php b/system/src/Grav/Common/Helpers/YamlLinter.php
index 45b5144..b31180f 100644
--- a/system/src/Grav/Common/Helpers/YamlLinter.php
+++ b/system/src/Grav/Common/Helpers/YamlLinter.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Helpers
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -11,6 +11,7 @@ namespace Grav\Common\Helpers;
use Exception;
use Grav\Common\Grav;
+use Grav\Common\Utils;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
@@ -108,7 +109,7 @@ class YamlLinter
*/
protected static function extractYaml($path)
{
- $extension = pathinfo($path, PATHINFO_EXTENSION);
+ $extension = Utils::pathinfo($path, PATHINFO_EXTENSION);
if ($extension === 'md') {
$file = MarkdownFile::instance($path);
$contents = $file->frontmatter();
diff --git a/system/src/Grav/Common/Inflector.php b/system/src/Grav/Common/Inflector.php
index 50c218f..216b733 100644
--- a/system/src/Grav/Common/Inflector.php
+++ b/system/src/Grav/Common/Inflector.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Iterator.php b/system/src/Grav/Common/Iterator.php
index 6e80b94..5db7bd0 100644
--- a/system/src/Grav/Common/Iterator.php
+++ b/system/src/Grav/Common/Iterator.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -38,6 +38,7 @@ class Iterator implements \ArrayAccess, \Iterator, \Countable, \Serializable
* @param mixed $args
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __call($key, $args)
{
return $this->items[$key] ?? null;
@@ -46,6 +47,7 @@ class Iterator implements \ArrayAccess, \Iterator, \Countable, \Serializable
/**
* Clone the iterator.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
foreach ($this as $key => $value) {
@@ -60,6 +62,7 @@ class Iterator implements \ArrayAccess, \Iterator, \Countable, \Serializable
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return implode(',', $this->items);
diff --git a/system/src/Grav/Common/Language/Language.php b/system/src/Grav/Common/Language/Language.php
index 6709754..fe006ed 100644
--- a/system/src/Grav/Common/Language/Language.php
+++ b/system/src/Grav/Common/Language/Language.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Language
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -636,6 +636,7 @@ class Language
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
$vars = get_object_vars($this);
diff --git a/system/src/Grav/Common/Language/LanguageCodes.php b/system/src/Grav/Common/Language/LanguageCodes.php
index e637bdd..3fa4948 100644
--- a/system/src/Grav/Common/Language/LanguageCodes.php
+++ b/system/src/Grav/Common/Language/LanguageCodes.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Language
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -93,7 +93,7 @@ class LanguageCodes
'la' => [ 'name' => 'Latin', 'nativeName' => 'Latina' ],
'lb' => [ 'name' => 'Luxembourgish', 'nativeName' => 'Lëtzebuergesch' ],
'lg' => [ 'name' => 'Luganda', 'nativeName' => 'Luganda' ],
- 'lo' => [ 'name' => 'Lao', 'nativeName' => 'Lao' ],
+ 'lo' => [ 'name' => 'Lao', 'nativeName' => 'Lao' ],
'lt' => [ 'name' => 'Lithuanian', 'nativeName' => 'Lietuvių' ],
'lv' => [ 'name' => 'Latvian', 'nativeName' => 'Latviešu' ],
'mai' => [ 'name' => 'Maithili', 'nativeName' => 'मैथिली মৈথিলী' ],
@@ -103,7 +103,7 @@ class LanguageCodes
'ml' => [ 'name' => 'Malayalam', 'nativeName' => 'മലയാളം' ],
'mn' => [ 'name' => 'Mongolian', 'nativeName' => 'Монгол' ],
'mr' => [ 'name' => 'Marathi', 'nativeName' => 'मराठी' ],
- 'my' => [ 'name' => 'Myanmar (Burmese)', 'nativeName' => 'ဗမာी' ],
+ 'my' => [ 'name' => 'Myanmar (Burmese)', 'nativeName' => 'ဗမာी' ],
'no' => [ 'name' => 'Norwegian', 'nativeName' => 'Norsk' ],
'nb' => [ 'name' => 'Norwegian', 'nativeName' => 'Norsk' ],
'nb-NO' => [ 'name' => 'Norwegian (Bokmål)', 'nativeName' => 'Norsk bokmål' ],
diff --git a/system/src/Grav/Common/Markdown/Parsedown.php b/system/src/Grav/Common/Markdown/Parsedown.php
index bdc5bdc..f0d8a48 100644
--- a/system/src/Grav/Common/Markdown/Parsedown.php
+++ b/system/src/Grav/Common/Markdown/Parsedown.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Markdown
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Markdown/ParsedownExtra.php b/system/src/Grav/Common/Markdown/ParsedownExtra.php
index b8e760e..ef450fe 100644
--- a/system/src/Grav/Common/Markdown/ParsedownExtra.php
+++ b/system/src/Grav/Common/Markdown/ParsedownExtra.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Markdown
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
index 7c2b0d6..a593dd7 100644
--- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
+++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Markdown
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -289,6 +289,7 @@ trait ParsedownGravTrait
* @param array $args
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
if (isset($this->{$method}) === true) {
diff --git a/system/src/Grav/Common/Media/Interfaces/AudioMediaInterface.php b/system/src/Grav/Common/Media/Interfaces/AudioMediaInterface.php
index d9c69d2..6465d6b 100644
--- a/system/src/Grav/Common/Media/Interfaces/AudioMediaInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/AudioMediaInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/ImageManipulateInterface.php b/system/src/Grav/Common/Media/Interfaces/ImageManipulateInterface.php
index 702cfda..eb38ea8 100644
--- a/system/src/Grav/Common/Media/Interfaces/ImageManipulateInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/ImageManipulateInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/ImageMediaInterface.php b/system/src/Grav/Common/Media/Interfaces/ImageMediaInterface.php
index 377258c..cbf8f1d 100644
--- a/system/src/Grav/Common/Media/Interfaces/ImageMediaInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/ImageMediaInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php
index ad9fe96..62c531c 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaFileInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaFileInterface.php
index 07a5c26..c20e4de 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaFileInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaFileInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaInterface.php
index 436fe16..273556a 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaLinkInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaLinkInterface.php
index 4f229c2..41747be 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaLinkInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaLinkInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php
index 6438881..9334759 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,6 +16,8 @@ use Grav\Common\Data\Data;
* Class implements media object interface.
*
* @property string $type
+ * @property string $filename
+ * @property string $filepath
*/
interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, ArrayAccess
{
@@ -63,6 +65,14 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
*/
public function addAlternative($ratio, MediaObjectInterface $alternative);
+ /**
+ * Get list of image alternatives. Includes the current media image as well.
+ *
+ * @param bool $withDerived If true, include generated images as well. If false, only return existing files.
+ * @return array
+ */
+ public function getAlternatives(bool $withDerived = true): array;
+
/**
* Return string representation of the object (html).
*
@@ -208,6 +218,7 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
* @param mixed $args
* @return $this
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args);
/**
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaPlayerInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaPlayerInterface.php
index 9307915..fbe6f65 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaPlayerInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaPlayerInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/MediaUploadInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaUploadInterface.php
index 8bfef84..7362599 100644
--- a/system/src/Grav/Common/Media/Interfaces/MediaUploadInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/MediaUploadInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Interfaces/VideoMediaInterface.php b/system/src/Grav/Common/Media/Interfaces/VideoMediaInterface.php
index ff0655a..6d42fef 100644
--- a/system/src/Grav/Common/Media/Interfaces/VideoMediaInterface.php
+++ b/system/src/Grav/Common/Media/Interfaces/VideoMediaInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/AudioMediaTrait.php b/system/src/Grav/Common/Media/Traits/AudioMediaTrait.php
index 160837d..a083472 100644
--- a/system/src/Grav/Common/Media/Traits/AudioMediaTrait.php
+++ b/system/src/Grav/Common/Media/Traits/AudioMediaTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/ImageLoadingTrait.php b/system/src/Grav/Common/Media/Traits/ImageLoadingTrait.php
index c023763..75e23ca 100644
--- a/system/src/Grav/Common/Media/Traits/ImageLoadingTrait.php
+++ b/system/src/Grav/Common/Media/Traits/ImageLoadingTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php b/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php
index f6e2222..c1c46dc 100644
--- a/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php
+++ b/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/MediaFileTrait.php b/system/src/Grav/Common/Media/Traits/MediaFileTrait.php
index 7198133..63906fc 100644
--- a/system/src/Grav/Common/Media/Traits/MediaFileTrait.php
+++ b/system/src/Grav/Common/Media/Traits/MediaFileTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/MediaObjectTrait.php b/system/src/Grav/Common/Media/Traits/MediaObjectTrait.php
index 3c2a38b..85ed6d2 100644
--- a/system/src/Grav/Common/Media/Traits/MediaObjectTrait.php
+++ b/system/src/Grav/Common/Media/Traits/MediaObjectTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -128,16 +128,35 @@ trait MediaObjectTrait
}
$alternative->set('ratio', $ratio);
- $width = $alternative->get('width');
+ $width = $alternative->get('width', 0);
$this->alternatives[$width] = $alternative;
}
+ /**
+ * @param bool $withDerived
+ * @return array
+ */
+ public function getAlternatives(bool $withDerived = true): array
+ {
+ $alternatives = [];
+ foreach ($this->alternatives + [$this->get('width', 0) => $this] as $size => $alternative) {
+ if ($withDerived || $alternative->filename === Utils::basename($alternative->filepath)) {
+ $alternatives[$size] = $alternative;
+ }
+ }
+
+ ksort($alternatives, SORT_NUMERIC);
+
+ return $alternatives;
+ }
+
/**
* Return string representation of the object (html).
*
* @return string
*/
+ #[\ReturnTypeWillChange]
abstract public function __toString();
/**
@@ -478,6 +497,7 @@ trait MediaObjectTrait
* @param array $args
* @return $this
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
$count = count($args);
@@ -554,11 +574,12 @@ trait MediaObjectTrait
foreach ($types as $type) {
$thumb = $this->get("thumbnails.{$type}", false);
-
if ($thumb) {
- $thumb = $thumb instanceof ThumbnailImageMedium ? $thumb : $this->createThumbnail($thumb);
- $thumb->parent = $this;
- $this->_thumbnail = $thumb;
+ $image = $thumb instanceof ThumbnailImageMedium ? $thumb : $this->createThumbnail($thumb);
+ if($image) {
+ $image->parent = $this;
+ $this->_thumbnail = $image;
+ }
break;
}
}
diff --git a/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php b/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php
index 66e9f47..7e59d64 100644
--- a/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php
+++ b/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -25,7 +25,7 @@ trait MediaPlayerTrait
public function controls($status = true)
{
if ($status) {
- $this->attributes['controls'] = true;
+ $this->attributes['controls'] = 'controls';
} else {
unset($this->attributes['controls']);
}
@@ -42,7 +42,7 @@ trait MediaPlayerTrait
public function loop($status = false)
{
if ($status) {
- $this->attributes['loop'] = true;
+ $this->attributes['loop'] = 'loop';
} else {
unset($this->attributes['loop']);
}
@@ -59,7 +59,7 @@ trait MediaPlayerTrait
public function autoplay($status = false)
{
if ($status) {
- $this->attributes['autoplay'] = true;
+ $this->attributes['autoplay'] = 'autoplay';
} else {
unset($this->attributes['autoplay']);
}
@@ -76,7 +76,7 @@ trait MediaPlayerTrait
public function muted($status = false)
{
if ($status) {
- $this->attributes['muted'] = true;
+ $this->attributes['muted'] = 'muted';
} else {
unset($this->attributes['muted']);
}
@@ -108,6 +108,6 @@ trait MediaPlayerTrait
*/
public function resetPlayer()
{
- $this->attributes['controls'] = true;
+ $this->attributes['controls'] = 'controls';
}
}
diff --git a/system/src/Grav/Common/Media/Traits/MediaTrait.php b/system/src/Grav/Common/Media/Traits/MediaTrait.php
index 5faba82..14bfa90 100644
--- a/system/src/Grav/Common/Media/Traits/MediaTrait.php
+++ b/system/src/Grav/Common/Media/Traits/MediaTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php b/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php
index 7a1f55d..88591f6 100644
--- a/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php
+++ b/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -100,6 +100,10 @@ trait MediaUploadTrait
'size' => $uploadedFile->getSize(),
];
+ if ($uploadedFile instanceof FormFlashFile) {
+ $uploadedFile->checkXss();
+ }
+
return $this->checkFileMetadata($metadata, $filename, $settings);
}
@@ -132,9 +136,9 @@ trait MediaUploadTrait
if ($folder === '.') {
$folder = '';
}
- $filename = basename($filename);
+ $filename = Utils::basename($filename);
}
- $extension = pathinfo($filename, PATHINFO_EXTENSION);
+ $extension = Utils::pathinfo($filename, PATHINFO_EXTENSION);
// Decide which filename to use.
if ($settings['random_name']) {
@@ -573,6 +577,8 @@ trait MediaUploadTrait
}
}
}
+
+ $this->hide($filename);
}
/**
diff --git a/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php b/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php
index 49d75be..d8a4b08 100644
--- a/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php
+++ b/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/ThumbnailMediaTrait.php b/system/src/Grav/Common/Media/Traits/ThumbnailMediaTrait.php
index eab7320..100b532 100644
--- a/system/src/Grav/Common/Media/Traits/ThumbnailMediaTrait.php
+++ b/system/src/Grav/Common/Media/Traits/ThumbnailMediaTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php b/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php
index e03fbbd..07f0c3f 100644
--- a/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php
+++ b/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -40,7 +40,7 @@ trait VideoMediaTrait
public function playsinline($status = false)
{
if ($status) {
- $this->attributes['playsinline'] = true;
+ $this->attributes['playsinline'] = 'playsinline';
} else {
unset($this->attributes['playsinline']);
}
diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php
index 930aeda..987b8d9 100644
--- a/system/src/Grav/Common/Page/Collection.php
+++ b/system/src/Grav/Common/Page/Collection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -27,6 +27,7 @@ use function is_string;
/**
* Class Collection
* @package Grav\Common\Page
+ * @implements PageCollectionInterface
*/
class Collection extends Iterator implements PageCollectionInterface
{
@@ -162,6 +163,7 @@ class Collection extends Iterator implements PageCollectionInterface
*
* @return PageInterface
*/
+ #[\ReturnTypeWillChange]
public function current()
{
$current = parent::key();
@@ -174,6 +176,7 @@ class Collection extends Iterator implements PageCollectionInterface
*
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function key()
{
$current = parent::current();
diff --git a/system/src/Grav/Common/Page/Header.php b/system/src/Grav/Common/Page/Header.php
index 71c7b16..c18b58d 100644
--- a/system/src/Grav/Common/Page/Header.php
+++ b/system/src/Grav/Common/Page/Header.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -30,6 +30,7 @@ class Header implements ArrayAccess, ExportInterface, JsonSerializable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
diff --git a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php
index 5002911..493ab43 100644
--- a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php
+++ b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -19,6 +19,11 @@ use Traversable;
/**
* Interface PageCollectionInterface
* @package Grav\Common\Page\Interfaces
+ *
+ * @template TKey of array-key
+ * @template T
+ * @extends Traversable
+ * @extends ArrayAccess
*/
interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, Serializable
{
@@ -68,6 +73,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param PageCollectionInterface $collection
* @return PageCollectionInterface
+ * @phpstan-return PageCollectionInterface
*/
public function merge(PageCollectionInterface $collection);
@@ -76,6 +82,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param PageCollectionInterface $collection
* @return PageCollectionInterface
+ * @phpstan-return PageCollectionInterface
*/
public function intersect(PageCollectionInterface $collection);
@@ -84,6 +91,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param int $size
* @return PageCollectionInterface[]
+ * @phpstan-return array>
*/
public function batch($size);
@@ -92,6 +100,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param PageInterface|string|null $key
* @return PageCollectionInterface
+ * @phpstan-return PageCollectionInterface
* @throws InvalidArgumentException
*/
//public function remove($key = null);
@@ -104,6 +113,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* @param array|null $manual
* @param string|null $sort_flags
* @return PageCollectionInterface
+ * @phpstan-return PageCollectionInterface
*/
public function order($by, $dir = 'asc', $manual = null, $sort_flags = null);
@@ -128,6 +138,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param string $path
* @return PageInterface The previous item.
+ * @phpstan-return T
*/
public function prevSibling($path);
@@ -136,6 +147,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param string $path
* @return PageInterface The next item.
+ * @phpstan-return T
*/
public function nextSibling($path);
@@ -145,6 +157,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* @param string $path
* @param int $direction either -1 or +1
* @return PageInterface|PageCollectionInterface|false The sibling item.
+ * @phpstan-return T|false
*/
public function adjacentSibling($path, $direction = 1);
@@ -166,6 +179,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* @param string|null $endDate
* @param string|null $field
* @return PageCollectionInterface
+ * @phpstan-return PageCollectionInterface
* @throws Exception
*/
public function dateRange($startDate = null, $endDate = null, $field = null);
@@ -174,6 +188,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only visible pages
*
* @return PageCollectionInterface The collection with only visible pages
+ * @phpstan-return PageCollectionInterface
*/
public function visible();
@@ -181,6 +196,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only non-visible pages
*
* @return PageCollectionInterface The collection with only non-visible pages
+ * @phpstan-return PageCollectionInterface
*/
public function nonVisible();
@@ -188,6 +204,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only pages
*
* @return PageCollectionInterface The collection with only pages
+ * @phpstan-return PageCollectionInterface
*/
public function pages();
@@ -195,6 +212,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only modules
*
* @return PageCollectionInterface The collection with only modules
+ * @phpstan-return PageCollectionInterface
*/
public function modules();
@@ -202,6 +220,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only modules
*
* @return PageCollectionInterface The collection with only modules
+ * @phpstan-return PageCollectionInterface
* @deprecated 1.7 Use $this->modules() instead
*/
public function modular();
@@ -210,6 +229,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only non-module pages
*
* @return PageCollectionInterface The collection with only non-module pages
+ * @phpstan-return PageCollectionInterface
* @deprecated 1.7 Use $this->pages() instead
*/
public function nonModular();
@@ -218,6 +238,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only published pages
*
* @return PageCollectionInterface The collection with only published pages
+ * @phpstan-return PageCollectionInterface
*/
public function published();
@@ -225,6 +246,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only non-published pages
*
* @return PageCollectionInterface The collection with only non-published pages
+ * @phpstan-return PageCollectionInterface
*/
public function nonPublished();
@@ -232,6 +254,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only routable pages
*
* @return PageCollectionInterface The collection with only routable pages
+ * @phpstan-return PageCollectionInterface
*/
public function routable();
@@ -239,6 +262,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
* Creates new collection with only non-routable pages
*
* @return PageCollectionInterface The collection with only non-routable pages
+ * @phpstan-return PageCollectionInterface
*/
public function nonRoutable();
@@ -247,6 +271,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param string $type
* @return PageCollectionInterface The collection
+ * @phpstan-return PageCollectionInterface
*/
public function ofType($type);
@@ -255,6 +280,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param string[] $types
* @return PageCollectionInterface The collection
+ * @phpstan-return PageCollectionInterface
*/
public function ofOneOfTheseTypes($types);
@@ -263,6 +289,7 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S
*
* @param array $accessLevels
* @return PageCollectionInterface The collection
+ * @phpstan-return PageCollectionInterface
*/
public function ofOneOfTheseAccessLevels($accessLevels);
diff --git a/system/src/Grav/Common/Page/Interfaces/PageContentInterface.php b/system/src/Grav/Common/Page/Interfaces/PageContentInterface.php
index d9d3105..a80972b 100644
--- a/system/src/Grav/Common/Page/Interfaces/PageContentInterface.php
+++ b/system/src/Grav/Common/Page/Interfaces/PageContentInterface.php
@@ -3,13 +3,15 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Page\Interfaces;
+use Grav\Common\Data\Blueprint;
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
+use Grav\Common\Page\Header;
/**
* Methods currently implemented in Flex Page emulation layer.
@@ -20,7 +22,7 @@ interface PageContentInterface
* Gets and Sets the header based on the YAML configuration at the top of the .md file
*
* @param object|array|null $var a YAML object representing the configuration for the file
- * @return object the current YAML configuration
+ * @return \stdClass|Header The current YAML configuration
*/
public function header($var = null);
@@ -254,4 +256,12 @@ interface PageContentInterface
* @return bool
*/
public function exists();
+
+ /**
+ * Returns the blueprint from the page.
+ *
+ * @param string $name Name of the Blueprint form. Used by flex only.
+ * @return Blueprint Returns a Blueprint.
+ */
+ public function getBlueprint(string $name = '');
}
diff --git a/system/src/Grav/Common/Page/Interfaces/PageInterface.php b/system/src/Grav/Common/Page/Interfaces/PageInterface.php
index e5ea20c..56fc891 100644
--- a/system/src/Grav/Common/Page/Interfaces/PageInterface.php
+++ b/system/src/Grav/Common/Page/Interfaces/PageInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Interfaces/PageTranslateInterface.php b/system/src/Grav/Common/Page/Interfaces/PageTranslateInterface.php
index be7ba15..5fba751 100644
--- a/system/src/Grav/Common/Page/Interfaces/PageTranslateInterface.php
+++ b/system/src/Grav/Common/Page/Interfaces/PageTranslateInterface.php
@@ -7,6 +7,11 @@ namespace Grav\Common\Page\Interfaces;
*/
interface PageTranslateInterface
{
+ /**
+ * @return bool
+ */
+ public function translated(): bool;
+
/**
* Return an array with the routes of other translated languages
*
diff --git a/system/src/Grav/Common/Page/Interfaces/PagesSourceInterface.php b/system/src/Grav/Common/Page/Interfaces/PagesSourceInterface.php
index ef5cfba..ff4ebda 100644
--- a/system/src/Grav/Common/Page/Interfaces/PagesSourceInterface.php
+++ b/system/src/Grav/Common/Page/Interfaces/PagesSourceInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Markdown/Excerpts.php b/system/src/Grav/Common/Page/Markdown/Excerpts.php
index 9b0b996..17f9cbf 100644
--- a/system/src/Grav/Common/Page/Markdown/Excerpts.php
+++ b/system/src/Grav/Common/Page/Markdown/Excerpts.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -206,7 +206,7 @@ class Excerpts
&& (empty($url_parts['host']) || $url_parts['host'] === $grav['uri']->host());
if ($local_file) {
- $filename = basename($url_parts['path']);
+ $filename = Utils::basename($url_parts['path']);
$folder = dirname($url_parts['path']);
// Get the local path to page media if possible.
diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php
index e182014..6c0a6c3 100644
--- a/system/src/Grav/Common/Page/Media.php
+++ b/system/src/Grav/Common/Page/Media.php
@@ -3,13 +3,14 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Page;
use FilesystemIterator;
+use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Media\Interfaces\MediaObjectInterface;
use Grav\Common\Yaml;
@@ -59,6 +60,46 @@ class Media extends AbstractMedia
}
}
+ /**
+ * Return raw route to the page.
+ *
+ * @return string|null Route to the page or null if media isn't for a page.
+ */
+ public function getRawRoute(): ?string
+ {
+ $path = $this->getPath();
+ if ($path) {
+ /** @var Pages $pages */
+ $pages = $this->getGrav()['pages'];
+ $page = $pages->get($path);
+ if ($page) {
+ return $page->rawRoute();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Return page route.
+ *
+ * @return string|null Route to the page or null if media isn't for a page.
+ */
+ public function getRoute(): ?string
+ {
+ $path = $this->getPath();
+ if ($path) {
+ /** @var Pages $pages */
+ $pages = $this->getGrav()['pages'];
+ $page = $pages->get($path);
+ if ($page) {
+ return $page->route();
+ }
+ }
+
+ return null;
+ }
+
/**
* @param string $offset
* @return bool
@@ -86,11 +127,6 @@ class Media extends AbstractMedia
*/
protected function init()
{
- /** @var UniformResourceLocator $locator */
- $locator = Grav::instance()['locator'];
- $config = Grav::instance()['config'];
- $exif_reader = isset(Grav::instance()['exif']) ? Grav::instance()['exif']->getReader() : false;
- $media_types = array_keys(Grav::instance()['config']->get('media.types'));
$path = $this->getPath();
// Handle special cases where page doesn't exist in filesystem.
@@ -98,6 +134,17 @@ class Media extends AbstractMedia
return;
}
+ $grav = Grav::instance();
+
+ /** @var UniformResourceLocator $locator */
+ $locator = $grav['locator'];
+
+ /** @var Config $config */
+ $config = $grav['config'];
+
+ $exif_reader = isset($grav['exif']) ? $grav['exif']->getReader() : null;
+ $media_types = array_keys($config->get('media.types', []));
+
$iterator = new FilesystemIterator($path, FilesystemIterator::UNIX_PATHS | FilesystemIterator::SKIP_DOTS);
$media = [];
diff --git a/system/src/Grav/Common/Page/Medium/AbstractMedia.php b/system/src/Grav/Common/Page/Medium/AbstractMedia.php
index db81ddd..9b3650b 100644
--- a/system/src/Grav/Common/Page/Medium/AbstractMedia.php
+++ b/system/src/Grav/Common/Page/Medium/AbstractMedia.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -90,6 +90,7 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac
* @param string $filename
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __invoke($filename)
{
return $this->offsetGet($filename);
diff --git a/system/src/Grav/Common/Page/Medium/AudioMedium.php b/system/src/Grav/Common/Page/Medium/AudioMedium.php
index f34f0a9..cc53f81 100644
--- a/system/src/Grav/Common/Page/Medium/AudioMedium.php
+++ b/system/src/Grav/Common/Page/Medium/AudioMedium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Medium/GlobalMedia.php b/system/src/Grav/Common/Page/Medium/GlobalMedia.php
index 50d69c7..20f63ad 100644
--- a/system/src/Grav/Common/Page/Medium/GlobalMedia.php
+++ b/system/src/Grav/Common/Page/Medium/GlobalMedia.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -11,6 +11,7 @@ namespace Grav\Common\Page\Medium;
use Grav\Common\Grav;
use Grav\Common\Media\Interfaces\MediaObjectInterface;
+use Grav\Common\Utils;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use function dirname;
@@ -89,7 +90,7 @@ class GlobalMedia extends AbstractMedia
}
$path = dirname($filename);
- [$basename, $ext,, $extra] = $this->getFileParts(basename($filename));
+ [$basename, $ext,, $extra] = $this->getFileParts(Utils::basename($filename));
$medium = MediumFactory::fromFile($filename);
if (null === $medium) {
diff --git a/system/src/Grav/Common/Page/Medium/ImageFile.php b/system/src/Grav/Common/Page/Medium/ImageFile.php
index bd853bf..1aae7ee 100644
--- a/system/src/Grav/Common/Page/Medium/ImageFile.php
+++ b/system/src/Grav/Common/Page/Medium/ImageFile.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -34,6 +34,7 @@ class ImageFile extends Image
/**
* Destruct also image object.
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
$adapter = $this->adapter;
diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php
index 46c832e..42d8f0e 100644
--- a/system/src/Grav/Common/Page/Medium/ImageMedium.php
+++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -89,6 +89,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
/**
* Also unset the image on destruct.
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
unset($this->image);
@@ -97,6 +98,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
/**
* Also clone image.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
if ($this->image) {
@@ -247,12 +249,12 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
if ($this->saved_image_path && $this->auto_sizes) {
if (!array_key_exists('height', $this->attributes) && !array_key_exists('width', $this->attributes)) {
$info = getimagesize($this->saved_image_path);
- $width = intval($info[0]);
- $height = intval($info[1]);
+ $width = (int)$info[0];
+ $height = (int)$info[1];
$scaling_factor = $this->retina_scale > 0 ? $this->retina_scale : 1;
- $attributes['width'] = intval($width / $scaling_factor);
- $attributes['height'] = intval($height / $scaling_factor);
+ $attributes['width'] = (int)($width / $scaling_factor);
+ $attributes['height'] = (int)($height / $scaling_factor);
if ($this->aspect_ratio) {
$style = ($attributes['style'] ?? ' ') . "--aspect-ratio: $width/$height;";
@@ -303,29 +305,45 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
return parent::lightbox($width, $height, $reset);
}
+ /**
+ * @param string $enabled
+ * @return $this
+ */
public function autoSizes($enabled = 'true')
{
- $enabled = $enabled === 'true' ?: false;
- $this->auto_sizes = $enabled;
+ $this->auto_sizes = $enabled === 'true' ?: false;
return $this;
}
+ /**
+ * @param string $enabled
+ * @return $this
+ */
public function aspectRatio($enabled = 'true')
{
- $enabled = $enabled === 'true' ?: false;
- $this->aspect_ratio = $enabled;
+ $this->aspect_ratio = $enabled === 'true' ?: false;
return $this;
}
+ /**
+ * @param int $scale
+ * @return $this
+ */
public function retinaScale($scale = 1)
{
- $this->retina_scale = intval($scale);
+ $this->retina_scale = (int)$scale;
return $this;
}
+ /**
+ * @param string|null $image
+ * @param string|null $position
+ * @param int|float|null $scale
+ * @return $this
+ */
public function watermark($image = null, $position = null, $scale = null)
{
$grav = $this->getGrav();
@@ -406,7 +424,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
*/
public function addFrame(int $border = 10, string $color = '0x000000')
{
- if(is_int(intval($border)) && $border>0 && preg_match('/^0x[a-f0-9]{6}$/i', $color)) { // $border must be an integer and bigger than 0; $color must be formatted as an HEX value (0x??????).
+ if($border > 0 && preg_match('/^0x[a-f0-9]{6}$/i', $color)) { // $border must be an integer and bigger than 0; $color must be formatted as an HEX value (0x??????).
$image = ImageFile::open($this->path());
}
else {
@@ -437,7 +455,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
* @param mixed $args
* @return $this|mixed
*/
-
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
if (!in_array($method, static::$magic_actions, true)) {
diff --git a/system/src/Grav/Common/Page/Medium/Link.php b/system/src/Grav/Common/Page/Medium/Link.php
index d576875..c76d8c1 100644
--- a/system/src/Grav/Common/Page/Medium/Link.php
+++ b/system/src/Grav/Common/Page/Medium/Link.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,7 +28,7 @@ class Link implements RenderableInterface, MediaLinkInterface
/** @var array */
protected $attributes = [];
- /** @var MediaObjectInterface */
+ /** @var MediaObjectInterface|MediaLinkInterface */
protected $source;
/**
@@ -79,6 +79,7 @@ class Link implements RenderableInterface, MediaLinkInterface
* @param mixed $args
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
$object = $this->source;
diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php
index 87009ac..0891c0c 100644
--- a/system/src/Grav/Common/Page/Medium/Medium.php
+++ b/system/src/Grav/Common/Page/Medium/Medium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,7 +22,14 @@ use Grav\Common\Media\Traits\MediaObjectTrait;
* Class Medium
* @package Grav\Common\Page\Medium
*
+ * @property string $filepath
+ * @property string $filename
+ * @property string $basename
* @property string $mime
+ * @property int $size
+ * @property int $modified
+ * @property array $metadata
+ * @property int|string $timestamp
*/
class Medium extends Data implements RenderableInterface, MediaFileInterface
{
@@ -57,6 +64,7 @@ class Medium extends Data implements RenderableInterface, MediaFileInterface
/**
* Clone medium.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
// Allows future compatibility as parent::__clone() works.
@@ -90,6 +98,7 @@ class Medium extends Data implements RenderableInterface, MediaFileInterface
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->html();
@@ -97,6 +106,7 @@ class Medium extends Data implements RenderableInterface, MediaFileInterface
/**
* @param string $thumb
+ * @return Medium|null
*/
protected function createThumbnail($thumb)
{
diff --git a/system/src/Grav/Common/Page/Medium/MediumFactory.php b/system/src/Grav/Common/Page/Medium/MediumFactory.php
index 7dee4ea..913f198 100644
--- a/system/src/Grav/Common/Page/Medium/MediumFactory.php
+++ b/system/src/Grav/Common/Page/Medium/MediumFactory.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -13,6 +13,7 @@ use Grav\Common\Grav;
use Grav\Common\Data\Blueprint;
use Grav\Common\Media\Interfaces\ImageMediaInterface;
use Grav\Common\Media\Interfaces\MediaObjectInterface;
+use Grav\Common\Utils;
use Grav\Framework\Form\FormFlashFile;
use Psr\Http\Message\UploadedFileInterface;
use function dirname;
@@ -37,7 +38,7 @@ class MediumFactory
return null;
}
- $parts = pathinfo($file);
+ $parts = Utils::pathinfo($file);
$path = $parts['dirname'];
$filename = $parts['basename'];
$ext = $parts['extension'] ?? '';
@@ -101,7 +102,7 @@ class MediumFactory
return null;
}
- $parts = pathinfo($clientName);
+ $parts = Utils::pathinfo($clientName);
$filename = $parts['basename'];
$ext = $parts['extension'] ?? '';
$basename = $parts['filename'];
@@ -158,8 +159,9 @@ class MediumFactory
return new ImageMedium($items, $blueprint);
case 'thumbnail':
return new ThumbnailImageMedium($items, $blueprint);
- case 'animated':
case 'vector':
+ return new VectorImageMedium($items, $blueprint);
+ case 'animated':
return new StaticImageMedium($items, $blueprint);
case 'video':
return new VideoMedium($items, $blueprint);
@@ -193,7 +195,7 @@ class MediumFactory
$height = $medium->get('height') * $ratio;
$prev_basename = $medium->get('basename');
- $basename = str_replace('@'.$from.'x', '@'.$to.'x', $prev_basename);
+ $basename = str_replace('@' . $from . 'x', $to !== 1 ? '@' . $to . 'x' : '', $prev_basename);
$debug = $medium->get('debug');
$medium->set('debug', false);
@@ -208,6 +210,8 @@ class MediumFactory
$medium = self::fromFile($file);
if ($medium) {
+ $medium->set('basename', $basename);
+ $medium->set('filename', $basename . '.' . $medium->extension);
$medium->set('size', $size);
}
diff --git a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php
index 44ab952..4ab2fb5 100644
--- a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php
+++ b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Medium/RenderableInterface.php b/system/src/Grav/Common/Page/Medium/RenderableInterface.php
index ac72447..1ee6a96 100644
--- a/system/src/Grav/Common/Page/Medium/RenderableInterface.php
+++ b/system/src/Grav/Common/Page/Medium/RenderableInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Medium/StaticImageMedium.php b/system/src/Grav/Common/Page/Medium/StaticImageMedium.php
index ba92fa1..9780100 100644
--- a/system/src/Grav/Common/Page/Medium/StaticImageMedium.php
+++ b/system/src/Grav/Common/Page/Medium/StaticImageMedium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -37,4 +37,12 @@ class StaticImageMedium extends Medium implements ImageMediaInterface
return ['name' => 'img', 'attributes' => $attributes];
}
+
+ /**
+ * @return $this
+ */
+ public function higherQualityAlternative()
+ {
+ return $this;
+ }
}
diff --git a/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php b/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php
index d95b2d6..caaa7e2 100644
--- a/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php
+++ b/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php
index a56a20d..1e4d862 100644
--- a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php
+++ b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php
new file mode 100644
index 0000000..c44f35a
--- /dev/null
+++ b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php
@@ -0,0 +1,68 @@
+get('width');
+ $height = $this->get('height');
+ if ($width && $height) {
+ return;
+ }
+
+ // Make sure that getting image size is supported.
+ if ($this->mime !== 'image/svg+xml' || !\extension_loaded('simplexml')) {
+ return;
+ }
+
+ // Make sure that the image exists.
+ $path = $this->get('filepath');
+ if (!$path || !file_exists($path) || !filesize($path)) {
+ return;
+ }
+
+ $xml = simplexml_load_string(file_get_contents($path));
+ $attr = $xml ? $xml->attributes() : null;
+ if (!$attr instanceof \SimpleXMLElement) {
+ return;
+ }
+
+ // Get the size from svg image.
+ if ($attr->width && $attr->height) {
+ $width = (string)$attr->width;
+ $height = (string)$attr->height;
+ } elseif ($attr->viewBox && \count($size = explode(' ', (string)$attr->viewBox)) === 4) {
+ [,$width,$height,] = $size;
+ }
+
+ if ($width && $height) {
+ $this->def('width', (int)$width);
+ $this->def('height', (int)$height);
+ }
+ }
+}
diff --git a/system/src/Grav/Common/Page/Medium/VideoMedium.php b/system/src/Grav/Common/Page/Medium/VideoMedium.php
index bfcf550..0e629dc 100644
--- a/system/src/Grav/Common/Page/Medium/VideoMedium.php
+++ b/system/src/Grav/Common/Page/Medium/VideoMedium.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php
index 9e68a44..25f8ff6 100644
--- a/system/src/Grav/Common/Page/Page.php
+++ b/system/src/Grav/Common/Page/Page.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -84,7 +84,7 @@ class Page implements PageInterface
protected $unpublish_date;
/** @var string */
protected $slug;
- /** @var string */
+ /** @var string|null */
protected $route;
/** @var string|null */
protected $raw_route;
@@ -196,7 +196,7 @@ class Page implements PageInterface
}
// extract page language from page extension
- $language = trim(basename($this->extension(), 'md'), '.') ?: null;
+ $language = trim(Utils::basename($this->extension(), 'md'), '.') ?: null;
$this->language($language);
$this->hide_home_route = $config->get('system.home.hide_in_urls', false);
@@ -218,6 +218,7 @@ class Page implements PageInterface
return $this;
}
+ #[\ReturnTypeWillChange]
public function __clone()
{
$this->initialized = false;
@@ -387,7 +388,7 @@ class Page implements PageInterface
* Gets and Sets the header based on the YAML configuration at the top of the .md file
*
* @param object|array|null $var a YAML object representing the configuration for the file
- * @return object the current YAML configuration
+ * @return \stdClass the current YAML configuration
*/
public function header($var = null)
{
@@ -1246,6 +1247,17 @@ class Page implements PageInterface
return $blueprint;
}
+ /**
+ * Returns the blueprint from the page.
+ *
+ * @param string $name Not used.
+ * @return Blueprint Returns a Blueprint.
+ */
+ public function getBlueprint(string $name = '')
+ {
+ return $this->blueprints();
+ }
+
/**
* Get the blueprint name for this page. Use the blueprint form field if set
*
@@ -1453,7 +1465,7 @@ class Page implements PageInterface
$this->extension = $var;
}
if (empty($this->extension)) {
- $this->extension = '.' . pathinfo($this->name(), PATHINFO_EXTENSION);
+ $this->extension = '.' . Utils::pathinfo($this->name(), PATHINFO_EXTENSION);
}
return $this->extension;
@@ -2097,9 +2109,9 @@ class Page implements PageInterface
{
if ($var !== null) {
// Filename of the page.
- $this->name = basename($var);
+ $this->name = Utils::basename($var);
// Folder of the page.
- $this->folder = basename(dirname($var));
+ $this->folder = Utils::basename(dirname($var));
// Path to the page.
$this->path = dirname($var, 2);
}
@@ -2138,7 +2150,7 @@ class Page implements PageInterface
{
if ($var !== null) {
// Folder of the page.
- $this->folder = basename($var);
+ $this->folder = Utils::basename($var);
// Path to the page.
$this->path = dirname($var);
}
diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php
index 9e5d47d..ec48b51 100644
--- a/system/src/Grav/Common/Page/Pages.php
+++ b/system/src/Grav/Common/Page/Pages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -736,7 +736,13 @@ class Pages
break;
case 'siblings':
$parent = $page->parent();
- $collection = $parent ? $parent->children()->remove($page->path()) : new Collection();
+ if ($parent) {
+ /** @var Collection $collection */
+ $collection = $parent->children();
+ $collection = $collection->remove($page->path());
+ } else {
+ $collection = new Collection();
+ }
break;
case 'descendants':
$collection = $this->all($page)->remove($page->path())->pages();
@@ -1041,9 +1047,14 @@ class Pages
$this->grav->redirectLangSafe($page->redirect());
}
- if (!$routable && ($child = $page->children()->visible()->routable()->published()->first()) !== null) {
- // Redirect to the first visible child as current page isn't routable.
- $this->grav->redirectLangSafe($child->route());
+ if (!$routable) {
+ /** @var Collection $children */
+ $children = $page->children()->visible()->routable()->published();
+ $child = $children->first();
+ if ($child !== null) {
+ // Redirect to the first visible child as current page isn't routable.
+ $this->grav->redirectLangSafe($child->route());
+ }
}
}
@@ -2065,7 +2076,7 @@ class Pages
$list[$key] = $child->slug();
break;
case 'basename':
- $list[$key] = basename($key);
+ $list[$key] = Utils::basename($key);
break;
case 'folder':
$list[$key] = $child->folder();
diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php
index c718368..420c588 100644
--- a/system/src/Grav/Common/Page/Types.php
+++ b/system/src/Grav/Common/Page/Types.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Page
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -12,6 +12,7 @@ namespace Grav\Common\Page;
use Grav\Common\Data\Blueprint;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
+use Grav\Common\Utils;
use InvalidArgumentException;
use RocketTheme\Toolbox\ArrayTraits\ArrayAccess;
use RocketTheme\Toolbox\ArrayTraits\Constructor;
@@ -144,7 +145,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable
if (strpos($name, 'modular/') !== 0) {
continue;
}
- $list[$name] = ucfirst(trim(str_replace('_', ' ', basename($name))));
+ $list[$name] = ucfirst(trim(str_replace('_', ' ', Utils::basename($name))));
}
ksort($list);
diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php
index 3b0d3fb..30e5344 100644
--- a/system/src/Grav/Common/Plugin.php
+++ b/system/src/Grav/Common/Plugin.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -118,7 +118,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
*/
public function config()
{
- return null !== $this->config ? $this->config["plugins.{$this->name}"] : [];
+ return $this->config["plugins.{$this->name}"] ?? [];
}
/**
@@ -414,6 +414,30 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
return true;
}
+ public static function inheritedConfigOption(string $plugin, string $var, PageInterface $page = null, $default = null)
+ {
+ if (Utils::isAdminPlugin()) {
+ $page = Grav::instance()['admin']->page() ?? null;
+ } else {
+ $page = $page ?? Grav::instance()['page'] ?? null;
+ }
+
+ // Try to find var in the page headers
+ if ($page instanceof PageInterface && $page->exists()) {
+ // Loop over pages and look for header vars
+ while ($page && !$page->root()) {
+ $header = new Data((array)$page->header());
+ $value = $header->get("$plugin.$var");
+ if (isset($value)) {
+ return $value;
+ }
+ $page = $page->parent();
+ }
+ }
+
+ return Grav::instance()['config']->get("plugins.$plugin.$var", $default);
+ }
+
/**
* Simpler getter for the plugin blueprint
*
diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php
index 88b5e52..42b1593 100644
--- a/system/src/Grav/Common/Plugins.php
+++ b/system/src/Grav/Common/Plugins.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/AssetsProcessor.php b/system/src/Grav/Common/Processors/AssetsProcessor.php
index 66bb5e3..e460fb0 100644
--- a/system/src/Grav/Common/Processors/AssetsProcessor.php
+++ b/system/src/Grav/Common/Processors/AssetsProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/BackupsProcessor.php b/system/src/Grav/Common/Processors/BackupsProcessor.php
index 6e960b4..83e8a0c 100644
--- a/system/src/Grav/Common/Processors/BackupsProcessor.php
+++ b/system/src/Grav/Common/Processors/BackupsProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php b/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php
index de7cafc..a3d5a51 100644
--- a/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php
+++ b/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php b/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php
index 32908ba..30f6195 100644
--- a/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php
+++ b/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/InitializeProcessor.php b/system/src/Grav/Common/Processors/InitializeProcessor.php
index b31530e..04e06ed 100644
--- a/system/src/Grav/Common/Processors/InitializeProcessor.php
+++ b/system/src/Grav/Common/Processors/InitializeProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/PagesProcessor.php b/system/src/Grav/Common/Processors/PagesProcessor.php
index 36f6718..3338e0c 100644
--- a/system/src/Grav/Common/Processors/PagesProcessor.php
+++ b/system/src/Grav/Common/Processors/PagesProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/PluginsProcessor.php b/system/src/Grav/Common/Processors/PluginsProcessor.php
index 485578e..ae87901 100644
--- a/system/src/Grav/Common/Processors/PluginsProcessor.php
+++ b/system/src/Grav/Common/Processors/PluginsProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/ProcessorBase.php b/system/src/Grav/Common/Processors/ProcessorBase.php
index a3506f5..9353391 100644
--- a/system/src/Grav/Common/Processors/ProcessorBase.php
+++ b/system/src/Grav/Common/Processors/ProcessorBase.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/ProcessorInterface.php b/system/src/Grav/Common/Processors/ProcessorInterface.php
index 8a6edbe..0aed195 100644
--- a/system/src/Grav/Common/Processors/ProcessorInterface.php
+++ b/system/src/Grav/Common/Processors/ProcessorInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/RenderProcessor.php b/system/src/Grav/Common/Processors/RenderProcessor.php
index 329da22..e12cc45 100644
--- a/system/src/Grav/Common/Processors/RenderProcessor.php
+++ b/system/src/Grav/Common/Processors/RenderProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/RequestProcessor.php b/system/src/Grav/Common/Processors/RequestProcessor.php
index 971fb67..bad410c 100644
--- a/system/src/Grav/Common/Processors/RequestProcessor.php
+++ b/system/src/Grav/Common/Processors/RequestProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -11,6 +11,7 @@ namespace Grav\Common\Processors;
use Grav\Common\Processors\Events\RequestHandlerEvent;
use Grav\Common\Uri;
+use Grav\Common\Utils;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
@@ -42,7 +43,7 @@ class RequestProcessor extends ProcessorBase
}
$uri = $request->getUri();
- $ext = mb_strtolower(pathinfo($uri->getPath(), PATHINFO_EXTENSION));
+ $ext = mb_strtolower(Utils::pathinfo($uri->getPath(), PATHINFO_EXTENSION));
$request = $request
->withAttribute('grav', $this->container)
diff --git a/system/src/Grav/Common/Processors/SchedulerProcessor.php b/system/src/Grav/Common/Processors/SchedulerProcessor.php
index 69cc163..722bfcc 100644
--- a/system/src/Grav/Common/Processors/SchedulerProcessor.php
+++ b/system/src/Grav/Common/Processors/SchedulerProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/TasksProcessor.php b/system/src/Grav/Common/Processors/TasksProcessor.php
index 07e0934..29f3458 100644
--- a/system/src/Grav/Common/Processors/TasksProcessor.php
+++ b/system/src/Grav/Common/Processors/TasksProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/ThemesProcessor.php b/system/src/Grav/Common/Processors/ThemesProcessor.php
index 951dc79..60d089e 100644
--- a/system/src/Grav/Common/Processors/ThemesProcessor.php
+++ b/system/src/Grav/Common/Processors/ThemesProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Processors/TwigProcessor.php b/system/src/Grav/Common/Processors/TwigProcessor.php
index 6604b5c..ffc1032 100644
--- a/system/src/Grav/Common/Processors/TwigProcessor.php
+++ b/system/src/Grav/Common/Processors/TwigProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Processors
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Scheduler/Cron.php b/system/src/Grav/Common/Scheduler/Cron.php
index 5127a99..0103839 100644
--- a/system/src/Grav/Common/Scheduler/Cron.php
+++ b/system/src/Grav/Common/Scheduler/Cron.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Scheduler
* @author Originally based on jqCron by Arnaud Buathier modified for Grav integration
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Scheduler/IntervalTrait.php b/system/src/Grav/Common/Scheduler/IntervalTrait.php
index cc5c165..5f7406b 100644
--- a/system/src/Grav/Common/Scheduler/IntervalTrait.php
+++ b/system/src/Grav/Common/Scheduler/IntervalTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Scheduler
* @author Originally based on peppeocchi/php-cron-scheduler modified for Grav integration
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Scheduler/Job.php b/system/src/Grav/Common/Scheduler/Job.php
index 13059a5..4156119 100644
--- a/system/src/Grav/Common/Scheduler/Job.php
+++ b/system/src/Grav/Common/Scheduler/Job.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Scheduler
* @author Originally based on peppeocchi/php-cron-scheduler modified for Grav integration
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Scheduler/Scheduler.php b/system/src/Grav/Common/Scheduler/Scheduler.php
index 73a0712..19eb9ea 100644
--- a/system/src/Grav/Common/Scheduler/Scheduler.php
+++ b/system/src/Grav/Common/Scheduler/Scheduler.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Scheduler
* @author Originally based on peppeocchi/php-cron-scheduler modified for Grav integration
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Security.php b/system/src/Grav/Common/Security.php
index fe259d8..779e619 100644
--- a/system/src/Grav/Common/Security.php
+++ b/system/src/Grav/Common/Security.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -25,6 +25,22 @@ use function is_string;
*/
class Security
{
+ /**
+ * @param string $filepath
+ * @param array|null $options
+ * @return string|null
+ */
+ public static function detectXssFromSvgFile(string $filepath, array $options = null): ?string
+ {
+ if (file_exists($filepath) && Grav::instance()['config']->get('security.sanitize_svg')) {
+ $content = file_get_contents($filepath);
+
+ return static::detectXss($content, $options);
+ }
+
+ return null;
+ }
+
/**
* Sanitize SVG string for XSS code
*
@@ -61,7 +77,7 @@ class Security
if ($clean_svg !== false ) {
file_put_contents($file, $clean_svg);
} else {
- $quarantine_file = basename($file);
+ $quarantine_file = Utils::basename($file);
$quarantine_dir = 'log://quarantine';
Folder::mkdir($quarantine_dir);
file_put_contents("$quarantine_dir/$quarantine_file", $original_svg);
@@ -200,7 +216,7 @@ class Security
}, $string);
// Clean up entities
- $string = preg_replace('!(+[0-9]+)!u', '$1;', $string);
+ $string = preg_replace('!([0-9]+);?!u', '$1;', $string);
// Decode entities
$string = html_entity_decode($string, ENT_NOQUOTES | ENT_HTML5, 'UTF-8');
@@ -214,7 +230,7 @@ class Security
'on_events' => '#(<[^>]+[[a-z\x00-\x20\"\'\/])([\s\/]on|\sxmlns)[a-z].*=>?#iUu',
// Match javascript:, livescript:, vbscript:, mocha:, feed: and data: protocols
- 'invalid_protocols' => '#(' . implode('|', array_map('preg_quote', $invalid_protocols, ['#'])) . '):\S.*?#iUu',
+ 'invalid_protocols' => '#(' . implode('|', array_map('preg_quote', $invalid_protocols, ['#'])) . ')(:|\&\#58)\S.*?#iUu',
// Match -moz-bindings
'moz_binding' => '#-moz-binding[a-z\x00-\x20]*:#u',
diff --git a/system/src/Grav/Common/Service/AccountsServiceProvider.php b/system/src/Grav/Common/Service/AccountsServiceProvider.php
index 8b158c9..60f26e5 100644
--- a/system/src/Grav/Common/Service/AccountsServiceProvider.php
+++ b/system/src/Grav/Common/Service/AccountsServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/AssetsServiceProvider.php b/system/src/Grav/Common/Service/AssetsServiceProvider.php
index 1e4e647..54a44a1 100644
--- a/system/src/Grav/Common/Service/AssetsServiceProvider.php
+++ b/system/src/Grav/Common/Service/AssetsServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/BackupsServiceProvider.php b/system/src/Grav/Common/Service/BackupsServiceProvider.php
index 00fa963..58f5021 100644
--- a/system/src/Grav/Common/Service/BackupsServiceProvider.php
+++ b/system/src/Grav/Common/Service/BackupsServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/ConfigServiceProvider.php b/system/src/Grav/Common/Service/ConfigServiceProvider.php
index 3a5c2e2..e65e228 100644
--- a/system/src/Grav/Common/Service/ConfigServiceProvider.php
+++ b/system/src/Grav/Common/Service/ConfigServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/ErrorServiceProvider.php b/system/src/Grav/Common/Service/ErrorServiceProvider.php
index 3227365..02d38c9 100644
--- a/system/src/Grav/Common/Service/ErrorServiceProvider.php
+++ b/system/src/Grav/Common/Service/ErrorServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/FilesystemServiceProvider.php b/system/src/Grav/Common/Service/FilesystemServiceProvider.php
index 62dad5d..1dde5b3 100644
--- a/system/src/Grav/Common/Service/FilesystemServiceProvider.php
+++ b/system/src/Grav/Common/Service/FilesystemServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/FlexServiceProvider.php b/system/src/Grav/Common/Service/FlexServiceProvider.php
index 9c8cd49..e7b283a 100644
--- a/system/src/Grav/Common/Service/FlexServiceProvider.php
+++ b/system/src/Grav/Common/Service/FlexServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/InflectorServiceProvider.php b/system/src/Grav/Common/Service/InflectorServiceProvider.php
index 861a69e..f43a446 100644
--- a/system/src/Grav/Common/Service/InflectorServiceProvider.php
+++ b/system/src/Grav/Common/Service/InflectorServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/LoggerServiceProvider.php b/system/src/Grav/Common/Service/LoggerServiceProvider.php
index 5043cfb..43a67ca 100644
--- a/system/src/Grav/Common/Service/LoggerServiceProvider.php
+++ b/system/src/Grav/Common/Service/LoggerServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/OutputServiceProvider.php b/system/src/Grav/Common/Service/OutputServiceProvider.php
index 9a49185..2dbd343 100644
--- a/system/src/Grav/Common/Service/OutputServiceProvider.php
+++ b/system/src/Grav/Common/Service/OutputServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/PagesServiceProvider.php b/system/src/Grav/Common/Service/PagesServiceProvider.php
index 55f6a45..fa6631e 100644
--- a/system/src/Grav/Common/Service/PagesServiceProvider.php
+++ b/system/src/Grav/Common/Service/PagesServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -99,7 +99,8 @@ class PagesServiceProvider implements ServiceProviderInterface
/** @var Language $language */
$language = $grav['language'];
- $redirectCode = (int)$config->get('system.pages.redirect_default_route', 0);
+ $redirect_default_route = $page->header()->redirect_default_route ?? $config->get('system.pages.redirect_default_route', 0);
+ $redirectCode = (int) $redirect_default_route;
// Language-specific redirection scenarios
if ($language->enabled() && ($language->isLanguageInUrl() xor $language->isIncludeDefaultLanguage())) {
diff --git a/system/src/Grav/Common/Service/RequestServiceProvider.php b/system/src/Grav/Common/Service/RequestServiceProvider.php
index 17b3149..a44c735 100644
--- a/system/src/Grav/Common/Service/RequestServiceProvider.php
+++ b/system/src/Grav/Common/Service/RequestServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/SchedulerServiceProvider.php b/system/src/Grav/Common/Service/SchedulerServiceProvider.php
index a952725..13918fb 100644
--- a/system/src/Grav/Common/Service/SchedulerServiceProvider.php
+++ b/system/src/Grav/Common/Service/SchedulerServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/SessionServiceProvider.php b/system/src/Grav/Common/Service/SessionServiceProvider.php
index 88c833f..80e24b4 100644
--- a/system/src/Grav/Common/Service/SessionServiceProvider.php
+++ b/system/src/Grav/Common/Service/SessionServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -40,7 +40,8 @@ class SessionServiceProvider implements ServiceProviderInterface
// Get session options.
$enabled = (bool)$config->get('system.session.enabled', false);
- $cookie_secure = (bool)$config->get('system.session.secure', false);
+ $cookie_secure = $config->get('system.session.secure', false)
+ || ($config->get('system.session.secure_https', true) && $uri->scheme(true) === 'https');
$cookie_httponly = (bool)$config->get('system.session.httponly', true);
$cookie_lifetime = (int)$config->get('system.session.timeout', 1800);
$cookie_domain = $config->get('system.session.domain');
diff --git a/system/src/Grav/Common/Service/StreamsServiceProvider.php b/system/src/Grav/Common/Service/StreamsServiceProvider.php
index edde09a..f501b49 100644
--- a/system/src/Grav/Common/Service/StreamsServiceProvider.php
+++ b/system/src/Grav/Common/Service/StreamsServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Service/TaskServiceProvider.php b/system/src/Grav/Common/Service/TaskServiceProvider.php
index 49ce147..2989e9d 100644
--- a/system/src/Grav/Common/Service/TaskServiceProvider.php
+++ b/system/src/Grav/Common/Service/TaskServiceProvider.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Service
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php
index 3221627..513143e 100644
--- a/system/src/Grav/Common/Session.php
+++ b/system/src/Grav/Common/Session.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Taxonomy.php b/system/src/Grav/Common/Taxonomy.php
index 0d0a450..5079a25 100644
--- a/system/src/Grav/Common/Taxonomy.php
+++ b/system/src/Grav/Common/Taxonomy.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Theme.php b/system/src/Grav/Common/Theme.php
index a5006a2..6013129 100644
--- a/system/src/Grav/Common/Theme.php
+++ b/system/src/Grav/Common/Theme.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Themes.php b/system/src/Grav/Common/Themes.php
index 6126841..3567cca 100644
--- a/system/src/Grav/Common/Themes.php
+++ b/system/src/Grav/Common/Themes.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Exception/TwigException.php b/system/src/Grav/Common/Twig/Exception/TwigException.php
index 8f543dc..7605de4 100644
--- a/system/src/Grav/Common/Twig/Exception/TwigException.php
+++ b/system/src/Grav/Common/Twig/Exception/TwigException.php
@@ -3,17 +3,19 @@
/**
* @package Grav\Common\Twig\Exception
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Twig\Exception;
+use RuntimeException;
+
/**
* TwigException gets thrown when you use {% throw code message %} in twig.
*
* This allows Grav to catch 401, 403 and 404 exceptions and display proper error page.
*/
-class TwigException extends \RuntimeException
+class TwigException extends RuntimeException
{
}
diff --git a/system/src/Grav/Common/Twig/Extension/FilesystemExtension.php b/system/src/Grav/Common/Twig/Extension/FilesystemExtension.php
index dfd5fdd..0ae793e 100644
--- a/system/src/Grav/Common/Twig/Extension/FilesystemExtension.php
+++ b/system/src/Grav/Common/Twig/Extension/FilesystemExtension.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -266,24 +266,24 @@ class FilesystemExtension extends AbstractExtension
}
/**
- * @param string $file
+ * @param string $filename
* @param string|null $required_sections
* @param bool $as_arrays
* @param bool $read_thumbnail
* @return array|false
*/
- public function exif_read_data($file, ?string $required_sections, bool $as_arrays = false, bool $read_thumbnail = false)
+ public function exif_read_data($filename, ?string $required_sections, bool $as_arrays = false, bool $read_thumbnail = false)
{
- if (!Utils::functionExists('exif_read_data') || !$this->checkFilename($file)) {
+ if (!Utils::functionExists('exif_read_data') || !$this->checkFilename($filename)) {
return false;
}
- return exif_read_data($file, $required_sections, $as_arrays, $read_thumbnail);
+ return exif_read_data($filename, $required_sections, $as_arrays, $read_thumbnail);
}
/**
* @param string $filename
- * @return string|false
+ * @return int|false
*/
public function exif_imagetype($filename)
{
@@ -311,18 +311,18 @@ class FilesystemExtension extends AbstractExtension
/**
* @param string $algo
- * @param string $data
+ * @param string $filename
* @param string $key
* @param bool $binary
* @return string|false
*/
- public function hash_hmac_file(string $algo, string $data, string $key, bool $binary = false)
+ public function hash_hmac_file(string $algo, string $filename, string $key, bool $binary = false)
{
- if (!$this->checkFilename($data)) {
+ if (!$this->checkFilename($filename)) {
return false;
}
- return hash_hmac_file($algo, $data, $key, $binary);
+ return hash_hmac_file($algo, $filename, $key, $binary);
}
/**
@@ -373,11 +373,7 @@ class FilesystemExtension extends AbstractExtension
*/
public function pathinfo($path, $flags = null)
{
- if (null !== $flags) {
- return pathinfo($path, (int)$flags);
- }
-
- return pathinfo($path);
+ return Utils::pathinfo($path, $flags);
}
/**
diff --git a/system/src/Grav/Common/Twig/Extension/GravExtension.php b/system/src/Grav/Common/Twig/Extension/GravExtension.php
index 4c0d9fe..52e2a18 100644
--- a/system/src/Grav/Common/Twig/Extension/GravExtension.php
+++ b/system/src/Grav/Common/Twig/Extension/GravExtension.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,6 +22,7 @@ use Grav\Common\Page\Media;
use Grav\Common\Scheduler\Cron;
use Grav\Common\Security;
use Grav\Common\Twig\TokenParser\TwigTokenParserCache;
+use Grav\Common\Twig\TokenParser\TwigTokenParserLink;
use Grav\Common\Twig\TokenParser\TwigTokenParserRender;
use Grav\Common\Twig\TokenParser\TwigTokenParserScript;
use Grav\Common\Twig\TokenParser\TwigTokenParserStyle;
@@ -115,6 +116,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
new TwigFilter('defined', [$this, 'definedDefaultFilter']),
new TwigFilter('ends_with', [$this, 'endsWithFilter']),
new TwigFilter('fieldName', [$this, 'fieldNameFilter']),
+ new TwigFilter('parent_field', [$this, 'fieldParentFilter']),
new TwigFilter('ksort', [$this, 'ksortFilter']),
new TwigFilter('ltrim', [$this, 'ltrimFilter']),
new TwigFilter('markdown', [$this, 'markdownFunction'], ['needs_context' => true, 'is_safe' => ['html']]),
@@ -252,12 +254,17 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
new TwigTokenParserTryCatch(),
new TwigTokenParserScript(),
new TwigTokenParserStyle(),
+ new TwigTokenParserLink(),
new TwigTokenParserMarkdown(),
new TwigTokenParserSwitch(),
new TwigTokenParserCache(),
];
}
+ /**
+ * @param mixed $var
+ * @return string
+ */
public function print_r($var)
{
return print_r($var, true);
@@ -276,6 +283,20 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
return array_shift($path) . ($path ? '[' . implode('][', $path) . ']' : '');
}
+ /**
+ * Filters field name by changing dot notation into array notation.
+ *
+ * @param string $str
+ * @return string
+ */
+ public function fieldParentFilter($str)
+ {
+ $path = explode('.', rtrim($str, '.'));
+ array_pop($path);
+
+ return implode('.', $path);
+ }
+
/**
* Protects email address.
*
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeCache.php b/system/src/Grav/Common/Twig/Node/TwigNodeCache.php
index 0ed1fff..e05e372 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeCache.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeLink.php b/system/src/Grav/Common/Twig/Node/TwigNodeLink.php
new file mode 100644
index 0000000..a468633
--- /dev/null
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeLink.php
@@ -0,0 +1,114 @@
+ $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes];
+ $nodes = array_filter($nodes);
+
+ parent::__construct($nodes, ['rel' => $rel], $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Compiler $compiler A Twig Compiler instance
+ * @return void
+ * @throws LogicException
+ */
+ public function compile(Compiler $compiler): void
+ {
+ $compiler->addDebugInfo($this);
+ if (!$this->hasNode('file')) {
+ return;
+ }
+
+ $compiler->write('$attributes = [\'rel\' => \'' . $this->getAttribute('rel') . '\'];' . "\n");
+ if ($this->hasNode('attributes')) {
+ $compiler
+ ->write('$attributes += ')
+ ->subcompile($this->getNode('attributes'))
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_array($attributes)) {' . PHP_EOL)
+ ->indent()
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} with x %}: x is not an array');" . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
+ }
+
+ if ($this->hasNode('group')) {
+ $compiler
+ ->write('$group = ')
+ ->subcompile($this->getNode('group'))
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_string($group)) {' . PHP_EOL)
+ ->indent()
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} in x %}: x is not a string');" . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
+ } else {
+ $compiler->write('$group = \'head\';' . PHP_EOL);
+ }
+
+ if ($this->hasNode('priority')) {
+ $compiler
+ ->write('$priority = (int)(')
+ ->subcompile($this->getNode('priority'))
+ ->raw(');' . PHP_EOL);
+ } else {
+ $compiler->write('$priority = 10;' . PHP_EOL);
+ }
+
+ $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];" . PHP_EOL);
+ $compiler->write("\$block = \$context['block'] ?? null;" . PHP_EOL);
+
+ $compiler
+ ->write('$file = (string)(')
+ ->subcompile($this->getNode('file'))
+ ->raw(');' . PHP_EOL);
+
+ // Assets support.
+ $compiler->write('$assets->addLink($file, [\'group\' => $group, \'priority\' => $priority] + $attributes);' . PHP_EOL);
+
+ // HtmlBlock support.
+ $compiler
+ ->write('if ($block instanceof \Grav\Framework\ContentBlock\HtmlBlock) {' . PHP_EOL)
+ ->indent()
+ ->write('$block->addLink([\'href\'=> $file] + $attributes, $priority, $group);' . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
+ }
+}
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeMarkdown.php b/system/src/Grav/Common/Twig/Node/TwigNodeMarkdown.php
index 81cecae..4637db7 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeMarkdown.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeMarkdown.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeRender.php b/system/src/Grav/Common/Twig/Node/TwigNodeRender.php
index 798c6ba..dbce3c6 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeRender.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeRender.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -75,6 +75,7 @@ class TwigNodeRender extends Node implements NodeCaptureInterface
->outdent()
->write('} else {' . PHP_EOL)
->indent()
+ ->write('\Grav\Common\Assets\BlockAssets::registerAssets($html);' . PHP_EOL)
->write('echo (string)$html;' . PHP_EOL)
->outdent()
->write('}' . PHP_EOL)
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeScript.php b/system/src/Grav/Common/Twig/Node/TwigNodeScript.php
index 46a0870..03554bd 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeScript.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeScript.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -27,6 +27,7 @@ class TwigNodeScript extends Node implements NodeCaptureInterface
/**
* TwigNodeScript constructor.
* @param Node|null $body
+ * @param string|null $type
* @param AbstractExpression|null $file
* @param AbstractExpression|null $group
* @param AbstractExpression|null $priority
@@ -34,12 +35,12 @@ class TwigNodeScript extends Node implements NodeCaptureInterface
* @param int $lineno
* @param string|null $tag
*/
- public function __construct(?Node $body, ?AbstractExpression $file, ?AbstractExpression $group, ?AbstractExpression $priority, ?AbstractExpression $attributes, $lineno = 0, $tag = null)
+ public function __construct(?Node $body, ?string $type, ?AbstractExpression $file, ?AbstractExpression $group, ?AbstractExpression $priority, ?AbstractExpression $attributes, $lineno = 0, $tag = null)
{
$nodes = ['body' => $body, 'file' => $file, 'group' => $group, 'priority' => $priority, 'attributes' => $attributes];
$nodes = array_filter($nodes);
- parent::__construct($nodes, [], $lineno, $tag);
+ parent::__construct($nodes, ['type' => $type], $lineno, $tag);
}
/**
@@ -53,52 +54,89 @@ class TwigNodeScript extends Node implements NodeCaptureInterface
{
$compiler->addDebugInfo($this);
- $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];\n");
-
if ($this->hasNode('attributes')) {
$compiler
->write('$attributes = ')
->subcompile($this->getNode('attributes'))
- ->raw(";\n")
- ->write("if (!is_array(\$attributes)) {\n")
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_array($attributes)) {' . PHP_EOL)
->indent()
- ->write("throw new UnexpectedValueException('{% {$this->tagName} with x %}: x is not an array');\n")
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} with x %}: x is not an array');" . PHP_EOL)
->outdent()
- ->write("}\n");
+ ->write('}' . PHP_EOL);
} else {
- $compiler->write('$attributes = [];' . "\n");
+ $compiler->write('$attributes = [];' . PHP_EOL);
}
if ($this->hasNode('group')) {
$compiler
- ->write("\$attributes['group'] = ")
+ ->write('$group = ')
->subcompile($this->getNode('group'))
- ->raw(";\n")
- ->write("if (!is_string(\$attributes['group'])) {\n")
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_string($group)) {' . PHP_EOL)
->indent()
- ->write("throw new UnexpectedValueException('{% {$this->tagName} in x %}: x is not a string');\n")
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} in x %}: x is not a string');" . PHP_EOL)
->outdent()
- ->write("}\n");
+ ->write('}' . PHP_EOL);
+ } else {
+ $compiler->write('$group = \'head\';' . PHP_EOL);
}
if ($this->hasNode('priority')) {
$compiler
- ->write("\$attributes['priority'] = (int)(")
+ ->write('$priority = (int)(')
->subcompile($this->getNode('priority'))
- ->raw(");\n");
+ ->raw(');' . PHP_EOL);
+ } else {
+ $compiler->write('$priority = 10;' . PHP_EOL);
}
+ $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];" . PHP_EOL);
+ $compiler->write("\$block = \$context['block'] ?? null;" . PHP_EOL);
+
if ($this->hasNode('file')) {
+ // JS file.
$compiler
- ->write('$assets->addJs(')
+ ->write('$file = (string)(')
->subcompile($this->getNode('file'))
- ->raw(", \$attributes);\n");
- } else {
+ ->raw(');' . PHP_EOL);
+
+ $method = $this->getAttribute('type') === 'module' ? 'addJsModule' : 'addJs';
+
+ // Assets support.
+ $compiler->write('$assets->' . $method . '($file, [\'group\' => $group, \'priority\' => $priority] + $attributes);' . PHP_EOL);
+
+ $method = $this->getAttribute('type') === 'module' ? 'addModule' : 'addScript';
+
+ // HtmlBlock support.
$compiler
- ->write("ob_start();\n")
+ ->write('if ($block instanceof \Grav\Framework\ContentBlock\HtmlBlock) {' . PHP_EOL)
+ ->indent()
+ ->write('$block->' . $method . '([\'src\'=> $file] + $attributes, $priority, $group);' . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
+
+ } else {
+ // Inline script.
+ $compiler
+ ->write('ob_start();' . PHP_EOL)
->subcompile($this->getNode('body'))
- ->write('$content = ob_get_clean();' . "\n")
- ->write("\$assets->addInlineJs(\$content, \$attributes);\n");
+ ->write('$content = ob_get_clean();' . PHP_EOL);
+
+ $method = $this->getAttribute('type') === 'module' ? 'addInlineJsModule' : 'addInlineJs';
+
+ // Assets support.
+ $compiler->write('$assets->' . $method . '($content, [\'group\' => $group, \'priority\' => $priority] + $attributes);' . PHP_EOL);
+
+ $method = $this->getAttribute('type') === 'module' ? 'addInlineModule' : 'addInlineScript';
+
+ // HtmlBlock support.
+ $compiler
+ ->write('if ($block instanceof \Grav\Framework\ContentBlock\HtmlBlock) {' . PHP_EOL)
+ ->indent()
+ ->write('$block->' . $method . '([\'content\'=> $content] + $attributes, $priority, $group);' . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
}
}
}
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php b/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php
index 05355f9..1c3568c 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeStyle.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -41,6 +41,7 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface
parent::__construct($nodes, [], $lineno, $tag);
}
+
/**
* Compiles the node to PHP.
*
@@ -52,52 +53,81 @@ class TwigNodeStyle extends Node implements NodeCaptureInterface
{
$compiler->addDebugInfo($this);
- $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];\n");
-
if ($this->hasNode('attributes')) {
$compiler
->write('$attributes = ')
->subcompile($this->getNode('attributes'))
- ->raw(";\n")
- ->write("if (!is_array(\$attributes)) {\n")
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_array($attributes)) {' . PHP_EOL)
->indent()
- ->write("throw new UnexpectedValueException('{% {$this->tagName} with x %}: x is not an array');\n")
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} with x %}: x is not an array');" . PHP_EOL)
->outdent()
- ->write("}\n");
+ ->write('}' . PHP_EOL);
} else {
- $compiler->write('$attributes = [];' . "\n");
+ $compiler->write('$attributes = [];' . PHP_EOL);
}
if ($this->hasNode('group')) {
$compiler
- ->write("\$attributes['group'] = ")
+ ->write('$group = ')
->subcompile($this->getNode('group'))
- ->raw(";\n")
- ->write("if (!is_string(\$attributes['group'])) {\n")
+ ->raw(';' . PHP_EOL)
+ ->write('if (!is_string($group)) {' . PHP_EOL)
->indent()
- ->write("throw new UnexpectedValueException('{% {$this->tagName} in x %}: x is not a string');\n")
+ ->write("throw new UnexpectedValueException('{% {$this->tagName} in x %}: x is not a string');" . PHP_EOL)
->outdent()
- ->write("}\n");
+ ->write('}' . PHP_EOL);
+ } else {
+ $compiler->write('$group = \'head\';' . PHP_EOL);
}
if ($this->hasNode('priority')) {
$compiler
- ->write("\$attributes['priority'] = (int)(")
+ ->write('$priority = (int)(')
->subcompile($this->getNode('priority'))
- ->raw(");\n");
+ ->raw(');' . PHP_EOL);
+ } else {
+ $compiler->write('$priority = 10;' . PHP_EOL);
}
+ $compiler->write("\$assets = \\Grav\\Common\\Grav::instance()['assets'];" . PHP_EOL);
+ $compiler->write("\$block = \$context['block'] ?? null;" . PHP_EOL);
+
if ($this->hasNode('file')) {
+ // CSS file.
$compiler
- ->write('$assets->addCss(')
+ ->write('$file = (string)(')
->subcompile($this->getNode('file'))
- ->raw(", \$attributes);\n");
- } else {
+ ->raw(');' . PHP_EOL);
+
+ // Assets support.
+ $compiler->write('$assets->addCss($file, [\'group\' => $group, \'priority\' => $priority] + $attributes);' . PHP_EOL);
+
+ // HtmlBlock support.
$compiler
- ->write("ob_start();\n")
+ ->write('if ($block instanceof \Grav\Framework\ContentBlock\HtmlBlock) {' . PHP_EOL)
+ ->indent()
+ ->write('$block->addStyle([\'href\'=> $file] + $attributes, $priority, $group);' . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
+
+ } else {
+ // Inline style.
+ $compiler
+ ->write('ob_start();' . PHP_EOL)
->subcompile($this->getNode('body'))
- ->write('$content = ob_get_clean();' . "\n")
- ->write("\$assets->addInlineCss(\$content, \$attributes);\n");
+ ->write('$content = ob_get_clean();' . PHP_EOL);
+
+ // Assets support.
+ $compiler->write('$assets->addInlineCss($content, [\'group\' => $group, \'priority\' => $priority] + $attributes);' . PHP_EOL);
+
+ // HtmlBlock support.
+ $compiler
+ ->write('if ($block instanceof \Grav\Framework\ContentBlock\HtmlBlock) {' . PHP_EOL)
+ ->indent()
+ ->write('$block->addInlineStyle([\'content\'=> $content] + $attributes, $priority, $group);' . PHP_EOL)
+ ->outdent()
+ ->write('}' . PHP_EOL);
}
}
}
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php b/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php
index 43ae56f..7bd368e 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeSwitch.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeThrow.php b/system/src/Grav/Common/Twig/Node/TwigNodeThrow.php
index 3bfe612..41ca15d 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeThrow.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeThrow.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php
index 40e9240..1213b7c 100644
--- a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php
+++ b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserCache.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserCache.php
index 371e89a..1cf2191 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserCache.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserLink.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserLink.php
new file mode 100644
index 0000000..2cb0208
--- /dev/null
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserLink.php
@@ -0,0 +1,109 @@
+getLine();
+
+ [$rel, $file, $group, $priority, $attributes] = $this->parseArguments($token);
+
+ return new TwigNodeLink($rel, $file, $group, $priority, $attributes, $lineno, $this->getTag());
+ }
+
+ /**
+ * @param Token $token
+ * @return array
+ */
+ protected function parseArguments(Token $token): array
+ {
+ $stream = $this->parser->getStream();
+
+
+ $rel = null;
+ if ($stream->test(Token::NAME_TYPE, $this->rel)) {
+ $rel = $stream->getCurrent()->getValue();
+ $stream->next();
+ }
+
+ $file = null;
+ if (!$stream->test(Token::NAME_TYPE) && !$stream->test(Token::BLOCK_END_TYPE)) {
+ $file = $this->parser->getExpressionParser()->parseExpression();
+ }
+
+ $group = null;
+ if ($stream->nextIf(Token::NAME_TYPE, 'at')) {
+ $group = $this->parser->getExpressionParser()->parseExpression();
+ }
+
+ $priority = null;
+ if ($stream->nextIf(Token::NAME_TYPE, 'priority')) {
+ $stream->expect(Token::PUNCTUATION_TYPE, ':');
+ $priority = $this->parser->getExpressionParser()->parseExpression();
+ }
+
+ $attributes = null;
+ if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
+ $attributes = $this->parser->getExpressionParser()->parseExpression();
+ }
+
+ $stream->expect(Token::BLOCK_END_TYPE);
+
+ return [$rel, $file, $group, $priority, $attributes];
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag(): string
+ {
+ return 'link';
+ }
+}
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserMarkdown.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserMarkdown.php
index 9dab4ae..49e34e6 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserMarkdown.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserMarkdown.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserRender.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserRender.php
index ab2bdde..de16266 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserRender.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserRender.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserScript.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserScript.php
index b860631..b943a25 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserScript.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserScript.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -15,14 +15,20 @@ use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
/**
- * Adds a script to head/bottom/custom location in the document.
+ * Adds a script to head/bottom/custom group location in the document.
*
- * {% script 'theme://js/something.js' at 'bottom' priority: 20 with { defer: true, async: true } %}
+ * {% script 'theme://js/something.js' at 'bottom' priority: 20 with { position: 'pipeline', loading: 'async defer' } %}
+ * {% script module 'theme://js/module.mjs' at 'head' %}
*
+ * {% script 'theme://js/something.js' at 'bottom' priority: 20 with { loading: 'inline' } %}
* {% script at 'bottom' priority: 20 %}
- * alert('Warning!');
+ * alert('Warning!');
+ * {% endscript %}
+ *
+ * {% script module 'theme://js/module.mjs' at 'bottom' with { loading: 'inline' } %}
+ * {% script module at 'bottom' %}
+ * ...
* {% endscript %}
-
*/
class TwigTokenParserScript extends AbstractTokenParser
{
@@ -38,7 +44,7 @@ class TwigTokenParserScript extends AbstractTokenParser
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- [$file, $group, $priority, $attributes] = $this->parseArguments($token);
+ [$type, $file, $group, $priority, $attributes] = $this->parseArguments($token);
$content = null;
if ($file === null) {
@@ -46,7 +52,7 @@ class TwigTokenParserScript extends AbstractTokenParser
$stream->expect(Token::BLOCK_END_TYPE);
}
- return new TwigNodeScript($content, $file, $group, $priority, $attributes, $lineno, $this->getTag());
+ return new TwigNodeScript($content, $type, $file, $group, $priority, $attributes, $lineno, $this->getTag());
}
/**
@@ -73,6 +79,12 @@ class TwigTokenParserScript extends AbstractTokenParser
} while (true);
}
+ $type = null;
+ if ($stream->test(Token::NAME_TYPE, 'module')) {
+ $type = $stream->getCurrent()->getValue();
+ $stream->next();
+ }
+
$file = null;
if (!$stream->test(Token::NAME_TYPE) && !$stream->test(Token::OPERATOR_TYPE, 'in') && !$stream->test(Token::BLOCK_END_TYPE)) {
$file = $this->parser->getExpressionParser()->parseExpression();
@@ -96,7 +108,7 @@ class TwigTokenParserScript extends AbstractTokenParser
$stream->expect(Token::BLOCK_END_TYPE);
- return [$file, $group, $priority, $attributes];
+ return [$type, $file, $group, $priority, $attributes];
}
/**
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserStyle.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserStyle.php
index c8d9544..0687395 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserStyle.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserStyle.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php
index 4540bbf..c63fe95 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
* @origin https://gist.github.com/maxgalbu/9409182
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserThrow.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserThrow.php
index bd4adab..41f415d 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserThrow.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserThrow.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserTryCatch.php b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserTryCatch.php
index 46af176..9930632 100644
--- a/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserTryCatch.php
+++ b/system/src/Grav/Common/Twig/TokenParser/TwigTokenParserTryCatch.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php
index 19bad01..39ae3c6 100644
--- a/system/src/Grav/Common/Twig/Twig.php
+++ b/system/src/Grav/Common/Twig/Twig.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -33,6 +33,7 @@ use Twig\Extension\DebugExtension;
use Twig\Extension\StringLoaderExtension;
use Twig\Loader\ArrayLoader;
use Twig\Loader\ChainLoader;
+use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\FilesystemLoader;
use Twig\Profiler\Profile;
use Twig\TwigFilter;
@@ -160,7 +161,7 @@ class Twig
$this->twig = new TwigEnvironment($loader_chain, $params);
- $this->twig->registerUndefinedFunctionCallback(function ($name) use ($config) {
+ $this->twig->registerUndefinedFunctionCallback(function (string $name) use ($config) {
$allowed = $config->get('system.twig.safe_functions');
if (is_array($allowed) && in_array($name, $allowed, true) && function_exists($name)) {
return new TwigFunction($name, $name);
@@ -184,7 +185,7 @@ class Twig
return false;
});
- $this->twig->registerUndefinedFilterCallback(function ($name) use ($config) {
+ $this->twig->registerUndefinedFilterCallback(function (string $name) use ($config) {
$allowed = $config->get('system.twig.safe_filters');
if (is_array($allowed) && in_array($name, $allowed, true) && function_exists($name)) {
return new TwigFilter($name, $name);
@@ -514,6 +515,8 @@ class Twig
$twig_extension = $extension ? '.'. $extension .TWIG_EXT : TEMPLATE_EXT;
$template_file = $this->template($page->template() . $twig_extension);
+ // TODO: no longer needed in Twig 3.
+ /** @var ExistsLoaderInterface $loader */
$loader = $this->twig->getLoader();
if ($loader->exists($template_file)) {
// template.xxx.twig
diff --git a/system/src/Grav/Common/Twig/TwigClockworkDataSource.php b/system/src/Grav/Common/Twig/TwigClockworkDataSource.php
index 11127b8..407a05e 100644
--- a/system/src/Grav/Common/Twig/TwigClockworkDataSource.php
+++ b/system/src/Grav/Common/Twig/TwigClockworkDataSource.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TwigClockworkDumper.php b/system/src/Grav/Common/Twig/TwigClockworkDumper.php
index 2c1f4be..c960cf2 100644
--- a/system/src/Grav/Common/Twig/TwigClockworkDumper.php
+++ b/system/src/Grav/Common/Twig/TwigClockworkDumper.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/TwigEnvironment.php b/system/src/Grav/Common/Twig/TwigEnvironment.php
index bebbdf1..dba8846 100644
--- a/system/src/Grav/Common/Twig/TwigEnvironment.php
+++ b/system/src/Grav/Common/Twig/TwigEnvironment.php
@@ -3,13 +3,18 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\Twig;
use Twig\Environment;
+use Twig\Error\LoaderError;
+use Twig\Loader\ExistsLoaderInterface;
+use Twig\Loader\LoaderInterface;
+use Twig\Template;
+use Twig\TemplateWrapper;
/**
* Class TwigEnvironment
@@ -18,4 +23,38 @@ use Twig\Environment;
class TwigEnvironment extends Environment
{
use WriteCacheFileTrait;
+
+ /**
+ * @inheritDoc
+ */
+ public function resolveTemplate($names)
+ {
+ if (!\is_array($names)) {
+ $names = [$names];
+ }
+
+ $count = \count($names);
+ foreach ($names as $name) {
+ if ($name instanceof Template) {
+ return $name;
+ }
+ if ($name instanceof TemplateWrapper) {
+ return $name;
+ }
+
+ // Optimization: Avoid throwing an exception when it would be ignored anyway.
+ if (1 !== $count) {
+ /** @var LoaderInterface|ExistsLoaderInterface $loader */
+ $loader = $this->getLoader();
+ if (!$loader->exists($name)) {
+ continue;
+ }
+ }
+
+ // Throws LoaderError: Unable to find template "%s".
+ return $this->loadTemplate($name);
+ }
+
+ throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
+ }
}
diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php
index 698858b..07c442e 100644
--- a/system/src/Grav/Common/Twig/TwigExtension.php
+++ b/system/src/Grav/Common/Twig/TwigExtension.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Twig/WriteCacheFileTrait.php b/system/src/Grav/Common/Twig/WriteCacheFileTrait.php
index edab8e5..575a281 100644
--- a/system/src/Grav/Common/Twig/WriteCacheFileTrait.php
+++ b/system/src/Grav/Common/Twig/WriteCacheFileTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Twig
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php
index 7bef097..76d9a99 100644
--- a/system/src/Grav/Common/Uri.php
+++ b/system/src/Grav/Common/Uri.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -165,7 +165,7 @@ class Uri
}
// Handle custom base
- $custom_base = rtrim($grav['config']->get('system.custom_base_url'), '/');
+ $custom_base = rtrim($grav['config']->get('system.custom_base_url', ''), '/');
if ($custom_base) {
$custom_parts = parse_url($custom_base);
if ($custom_parts === false) {
@@ -217,7 +217,7 @@ class Uri
$path = $bits['path'] ?? '/';
// remove the extension if there is one set
- $parts = pathinfo($path);
+ $parts = Utils::pathinfo($path);
// set the original basename
$this->basename = $parts['basename'];
@@ -337,9 +337,9 @@ class Uri
/**
* Get URI parameter.
*
- * @param string|null $id
- * @param string|bool|null $default
- * @return bool|string
+ * @param string $id
+ * @param string|false|null $default
+ * @return string|false|null
*/
public function param($id, $default = false)
{
@@ -623,6 +623,7 @@ class Uri
/**
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return static::buildUrl($this->toArray());
@@ -853,7 +854,7 @@ class Uri
}
if ($full_path) {
- $path_info = pathinfo($full_path);
+ $path_info = Utils::pathinfo($full_path);
$page_path = $path_info['dirname'];
$filename = '';
@@ -898,7 +899,7 @@ class Uri
$routes = $pages->routes();
// if this is an image, get the proper path
- $url_bits = pathinfo($url_path);
+ $url_bits = Utils::pathinfo($url_path);
if (isset($url_bits['extension'])) {
$target_path = $url_bits['dirname'];
} else {
@@ -1045,7 +1046,7 @@ class Uri
$base_url = rtrim($base . $grav['pages']->base(), '/') . $language_append;
// if absolute and starts with a base_url move on
- if (pathinfo($markdown_url, PATHINFO_DIRNAME) === '.' && $page->url() === '/') {
+ if (Utils::pathinfo($markdown_url, PATHINFO_DIRNAME) === '.' && $page->url() === '/') {
return '/' . $markdown_url;
}
// no path to convert
@@ -1084,7 +1085,7 @@ class Uri
return $normalized_url;
}
- $path_info = pathinfo($full_path);
+ $path_info = Utils::pathinfo($full_path);
$page_path = $path_info['dirname'];
$filename = '';
@@ -1272,9 +1273,9 @@ class Uri
$this->path = rawurldecode(parse_url('http://example.com' . $request_uri, PHP_URL_PATH));
// Build query string.
- $this->query = $env['QUERY_STRING'] ?? '';
+ $this->query = $env['QUERY_STRING'] ?? '';
if ($this->query === '') {
- $this->query = parse_url('http://example.com' . $request_uri, PHP_URL_QUERY);
+ $this->query = parse_url('http://example.com' . $request_uri, PHP_URL_QUERY) ?? '';
}
// Support ngnix routes.
diff --git a/system/src/Grav/Common/User/Access.php b/system/src/Grav/Common/User/Access.php
index 6503c89..96f4d96 100644
--- a/system/src/Grav/Common/User/Access.php
+++ b/system/src/Grav/Common/User/Access.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Authentication.php b/system/src/Grav/Common/User/Authentication.php
index 6ff95e7..c32fd62 100644
--- a/system/src/Grav/Common/User/Authentication.php
+++ b/system/src/Grav/Common/User/Authentication.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/DataUser/User.php b/system/src/Grav/Common/User/DataUser/User.php
index 8fcdbbb..9cd3904 100644
--- a/system/src/Grav/Common/User/DataUser/User.php
+++ b/system/src/Grav/Common/User/DataUser/User.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -21,6 +21,7 @@ use Grav\Common\Page\Medium\MediumFactory;
use Grav\Common\User\Authentication;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\User\Traits\UserTrait;
+use Grav\Common\Utils;
use Grav\Framework\Flex\Flex;
use function is_array;
@@ -177,7 +178,7 @@ class User extends Data implements UserInterface
if ($path && is_file($path)) {
$medium = MediumFactory::fromFile($path);
if ($medium) {
- $media->add(basename($path), $medium);
+ $media->add(Utils::basename($path), $medium);
}
}
@@ -192,7 +193,7 @@ class User extends Data implements UserInterface
*/
public function getMediaFolder()
{
- return $this->blueprints()->fields()['avatar']['destination'] ?? 'user://accounts/avatars';
+ return $this->blueprints()->fields()['avatar']['destination'] ?? 'account://avatars';
}
/**
@@ -295,6 +296,7 @@ class User extends Data implements UserInterface
* @return int
* @deprecated 1.6 Method makes no sense for user account.
*/
+ #[\ReturnTypeWillChange]
public function count()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6', E_USER_DEPRECATED);
diff --git a/system/src/Grav/Common/User/DataUser/UserCollection.php b/system/src/Grav/Common/User/DataUser/UserCollection.php
index 3da7e2d..d0ada09 100644
--- a/system/src/Grav/Common/User/DataUser/UserCollection.php
+++ b/system/src/Grav/Common/User/DataUser/UserCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -114,7 +114,7 @@ class UserCollection implements UserCollectionInterface
if (!$user->exists()) {
foreach ($files as $file) {
if (Utils::endsWith($file, YAML_EXT)) {
- $find_user = $this->load(trim(pathinfo($file, PATHINFO_FILENAME)));
+ $find_user = $this->load(trim(Utils::pathinfo($file, PATHINFO_FILENAME)));
foreach ($fields as $field) {
if (isset($find_user[$field]) && $find_user[$field] === $query) {
return $find_user;
diff --git a/system/src/Grav/Common/User/Group.php b/system/src/Grav/Common/User/Group.php
index 7dd6d65..9be619a 100644
--- a/system/src/Grav/Common/User/Group.php
+++ b/system/src/Grav/Common/User/Group.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php b/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php
index 3ad8d2c..1aeb004 100644
--- a/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php
+++ b/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php b/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php
index d892e82..5bcfbc0 100644
--- a/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php
+++ b/system/src/Grav/Common/User/Interfaces/UserCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Interfaces/UserGroupInterface.php b/system/src/Grav/Common/User/Interfaces/UserGroupInterface.php
index c345c4b..c18388c 100644
--- a/system/src/Grav/Common/User/Interfaces/UserGroupInterface.php
+++ b/system/src/Grav/Common/User/Interfaces/UserGroupInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Interfaces/UserInterface.php b/system/src/Grav/Common/User/Interfaces/UserInterface.php
index 02827e3..dcd014c 100644
--- a/system/src/Grav/Common/User/Interfaces/UserInterface.php
+++ b/system/src/Grav/Common/User/Interfaces/UserInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/User/Traits/UserTrait.php b/system/src/Grav/Common/User/Traits/UserTrait.php
index 5a6b749..91c41aa 100644
--- a/system/src/Grav/Common/User/Traits/UserTrait.php
+++ b/system/src/Grav/Common/User/Traits/UserTrait.php
@@ -3,18 +3,21 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common\User\Traits;
+use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
use Grav\Common\Page\Medium\ImageMedium;
use Grav\Common\Page\Medium\Medium;
use Grav\Common\Page\Medium\StaticImageMedium;
use Grav\Common\User\Authentication;
use Grav\Common\Utils;
+use Multiavatar;
+use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use function is_array;
use function is_string;
@@ -175,9 +178,52 @@ trait UserTrait
}
$email = $this->get('email');
+ $avatar_generator = Grav::instance()['config']->get('system.accounts.avatar', 'multiavatar');
+ if ($avatar_generator === 'gravatar') {
+ if (!$email) {
+ return '';
+ }
+
+ $hash = md5(strtolower(trim($email)));
+
+ return 'https://www.gravatar.com/avatar/' . $hash;
+ }
+
+ $hash = $this->get('avatar_hash');
+ if (!$hash) {
+ $username = $this->get('username');
+ $hash = md5(strtolower(trim($email ?? $username)));
+ }
+
+ return $this->generateMultiavatar($hash);
+ }
+
+ /**
+ * @param string $hash
+ * @return string
+ */
+ protected function generateMultiavatar(string $hash): string
+ {
+ /** @var UniformResourceLocator $locator */
+ $locator = Grav::instance()['locator'];
+
+ $storage = $locator->findResource('image://multiavatar', true, true);
+ $avatar_file = "{$storage}/{$hash}.svg";
+
+ if (!file_exists($storage)) {
+ Folder::create($storage);
+ }
+
+ if (!file_exists($avatar_file)) {
+ $mavatar = new Multiavatar();
+
+ file_put_contents($avatar_file, $mavatar->generate($hash, null, null));
+ }
+
+ $avatar_url = $locator->findResource("image://multiavatar/{$hash}.svg", false, true);
+
+ return Utils::url($avatar_url);
- // By default fall back to gravatar image.
- return $email ? 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) : '';
}
abstract public function get($name, $default = null, $separator = null);
diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php
index 4b2319f..b38c72e 100644
--- a/system/src/Grav/Common/User/User.php
+++ b/system/src/Grav/Common/User/User.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\User
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php
index 5295a64..145a893 100644
--- a/system/src/Grav/Common/Utils.php
+++ b/system/src/Grav/Common/Utils.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -134,14 +134,13 @@ abstract class Utils
$resource = $locator->findResource($input, false);
}
} else {
- $root = $uri->rootUrl();
-
- if (static::startsWith($input, $root)) {
- $input = static::replaceFirstOccurrence($root, '', $input);
+ $root = preg_quote($uri->rootUrl(), '#');
+ $pattern = '#(' . $root . '$|' . $root . '/)#';
+ if (!empty($root) && preg_match($pattern, $input, $matches)) {
+ $input = static::replaceFirstOccurrence($matches[0], '', $input);
}
$input = ltrim($input, '/');
-
$resource = $input;
}
@@ -653,16 +652,17 @@ abstract class Utils
* @param bool $force_download as opposed to letting browser choose if to download or render
* @param int $sec Throttling, try 0.1 for some speed throttling of downloads
* @param int $bytes Size of chunks to send in bytes. Default is 1024
+ * @param array $options Extra options: [mime, download_name, expires]
* @throws Exception
*/
- public static function download($file, $force_download = true, $sec = 0, $bytes = 1024)
+ public static function download($file, $force_download = true, $sec = 0, $bytes = 1024, array $options = [])
{
if (file_exists($file)) {
// fire download event
- Grav::instance()->fireEvent('onBeforeDownload', new Event(['file' => $file]));
+ Grav::instance()->fireEvent('onBeforeDownload', new Event(['file' => $file, 'options' => &$options]));
- $file_parts = pathinfo($file);
- $mimetype = static::getMimeByExtension($file_parts['extension']);
+ $file_parts = static::pathinfo($file);
+ $mimetype = $options['mime'] ?? static::getMimeByExtension($file_parts['extension']);
$size = filesize($file); // File size
// clean all buffers
@@ -680,7 +680,7 @@ abstract class Utils
if ($force_download) {
// output the regular HTTP headers
- header('Content-Disposition: attachment; filename="' . $file_parts['basename'] . '"');
+ header('Content-Disposition: attachment; filename="' . ($options['download_name'] ?? $file_parts['basename']) . '"');
}
// multipart-download and download resuming support
@@ -704,7 +704,7 @@ abstract class Utils
header('Content-Length: ' . $size);
if (Grav::instance()['config']->get('system.cache.enabled')) {
- $expires = Grav::instance()['config']->get('system.pages.expires');
+ $expires = $options['expires'] ?? Grav::instance()['config']->get('system.pages.expires');
if ($expires > 0) {
$expires_date = gmdate('D, d M Y H:i:s T', time() + $expires);
header('Cache-Control: max-age=' . $expires);
@@ -830,6 +830,31 @@ abstract class Utils
return $mimetypes;
}
+ /**
+ * Return all extensions for given mimetype. The first extension is the default one.
+ *
+ * @param string $mime Mime type (eg 'image/jpeg')
+ * @return string[] List of extensions eg. ['jpg', 'jpe', 'jpeg']
+ */
+ public static function getExtensionsByMime($mime)
+ {
+ $mime = strtolower($mime);
+
+ $media_types = (array)Grav::instance()['config']->get('media.types');
+
+ $list = [];
+ foreach ($media_types as $extension => $type) {
+ if ($extension === '' || $extension === 'defaults') {
+ continue;
+ }
+
+ if (isset($type['mime']) && $type['mime'] === $mime) {
+ $list[] = $extension;
+ }
+ }
+
+ return $list;
+ }
/**
* Return the mimetype based on filename extension
@@ -900,7 +925,7 @@ abstract class Utils
*/
public static function getMimeByFilename($filename, $default = 'application/octet-stream')
{
- return static::getMimeByExtension(pathinfo($filename, PATHINFO_EXTENSION), $default);
+ return static::getMimeByExtension(static::pathinfo($filename, PATHINFO_EXTENSION), $default);
}
/**
@@ -945,7 +970,7 @@ abstract class Utils
public static function checkFilename($filename)
{
$dangerous_extensions = Grav::instance()['config']->get('security.uploads_dangerous_extensions', []);
- $extension = pathinfo($filename, PATHINFO_EXTENSION);
+ $extension = static::pathinfo($filename, PATHINFO_EXTENSION);
return !(
// Empty filenames are not allowed.
@@ -959,6 +984,46 @@ abstract class Utils
);
}
+ /**
+ * Unicode-safe version of PHP’s pathinfo() function.
+ *
+ * @link https://www.php.net/manual/en/function.pathinfo.php
+ *
+ * @param string $path
+ * @param int|null $flags
+ * @return array|string
+ */
+ public static function pathinfo($path, int $flags = null)
+ {
+ $path = str_replace(['%2F', '%5C'], ['/', '\\'], rawurlencode($path));
+
+ if (null === $flags) {
+ $info = pathinfo($path);
+ } else {
+ $info = pathinfo($path, $flags);
+ }
+
+ if (is_array($info)) {
+ return array_map('rawurldecode', $info);
+ }
+
+ return rawurldecode($info);
+ }
+
+ /**
+ * Unicode-safe version of the PHP basename() function.
+ *
+ * @link https://www.php.net/manual/en/function.basename.php
+ *
+ * @param string $path
+ * @param string $suffix
+ * @return string
+ */
+ public static function basename($path, string $suffix = ''): string
+ {
+ return rawurldecode(basename(str_replace(['%2F', '%5C'], '/', rawurlencode($path)), $suffix));
+ }
+
/**
* Normalize path by processing relative `.` and `..` syntax and merging path
*
@@ -1594,8 +1659,8 @@ abstract class Utils
$route = '/' . $matches[2];
// Exclude filename from the page lookup.
- if (pathinfo($route, PATHINFO_EXTENSION)) {
- $basename = '/' . basename($route);
+ if (static::pathinfo($route, PATHINFO_EXTENSION)) {
+ $basename = '/' . static::basename($route);
$route = \dirname($route);
} else {
$basename = '';
diff --git a/system/src/Grav/Common/Yaml.php b/system/src/Grav/Common/Yaml.php
index 330b6c3..0758599 100644
--- a/system/src/Grav/Common/Yaml.php
+++ b/system/src/Grav/Common/Yaml.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Application/Application.php b/system/src/Grav/Console/Application/Application.php
index 21cea87..873b94e 100644
--- a/system/src/Grav/Console/Application/Application.php
+++ b/system/src/Grav/Console/Application/Application.php
@@ -3,18 +3,21 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Console\Application;
use Grav\Common\Grav;
+use Symfony\Component\Console\ConsoleEvents;
+use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\EventDispatcher\EventDispatcher;
/**
* Class GpmApplication
@@ -29,19 +32,48 @@ class Application extends \Symfony\Component\Console\Application
/** @var bool */
protected $initialized = false;
+ /**
+ * PluginApplication constructor.
+ * @param string $name
+ * @param string $version
+ */
+ public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
+ {
+ parent::__construct($name, $version);
+
+ // Add listener to prepare environment.
+ $dispatcher = new EventDispatcher();
+ $dispatcher->addListener(ConsoleEvents::COMMAND, [$this, 'prepareEnvironment']);
+
+ $this->setDispatcher($dispatcher);
+ }
+
/**
* @param InputInterface $input
* @return string|null
*/
public function getCommandName(InputInterface $input): ?string
{
- $this->environment = $input->getOption('env');
- $this->language = $input->getOption('lang') ?? $this->language;
+ if ($input->hasParameterOption('--env', true)) {
+ $this->environment = $input->getParameterOption('--env');
+ }
+ if ($input->hasParameterOption('--lang', true)) {
+ $this->language = $input->getParameterOption('--lang');
+ }
+
$this->init();
return parent::getCommandName($input);
}
+ /**
+ * @param ConsoleCommandEvent $event
+ * @return void
+ */
+ public function prepareEnvironment(ConsoleCommandEvent $event): void
+ {
+ }
+
/**
* @return void
*/
@@ -58,7 +90,7 @@ class Application extends \Symfony\Component\Console\Application
}
/**
- * Add global a --env option.
+ * Add global --env and --lang options.
*
* @return InputDefinition
*/
@@ -67,16 +99,16 @@ class Application extends \Symfony\Component\Console\Application
$inputDefinition = parent::getDefaultInputDefinition();
$inputDefinition->addOption(
new InputOption(
- 'env',
- null,
+ '--env',
+ '',
InputOption::VALUE_OPTIONAL,
'Use environment configuration (defaults to localhost)'
)
);
$inputDefinition->addOption(
new InputOption(
- 'lang',
- null,
+ '--lang',
+ '',
InputOption::VALUE_OPTIONAL,
'Language to be used (defaults to en)'
)
diff --git a/system/src/Grav/Console/Application/CommandLoader/PluginCommandLoader.php b/system/src/Grav/Console/Application/CommandLoader/PluginCommandLoader.php
index 9b7b568..adf6447 100644
--- a/system/src/Grav/Console/Application/CommandLoader/PluginCommandLoader.php
+++ b/system/src/Grav/Console/Application/CommandLoader/PluginCommandLoader.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Application/GpmApplication.php b/system/src/Grav/Console/Application/GpmApplication.php
index df383f2..f9e6b61 100644
--- a/system/src/Grav/Console/Application/GpmApplication.php
+++ b/system/src/Grav/Console/Application/GpmApplication.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Application/GravApplication.php b/system/src/Grav/Console/Application/GravApplication.php
index 739ca39..f06dae6 100644
--- a/system/src/Grav/Console/Application/GravApplication.php
+++ b/system/src/Grav/Console/Application/GravApplication.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Application/PluginApplication.php b/system/src/Grav/Console/Application/PluginApplication.php
index 75e9eb7..e365b1e 100644
--- a/system/src/Grav/Console/Application/PluginApplication.php
+++ b/system/src/Grav/Console/Application/PluginApplication.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/BackupCommand.php b/system/src/Grav/Console/Cli/BackupCommand.php
index a8a025d..1fe84ea 100644
--- a/system/src/Grav/Console/Cli/BackupCommand.php
+++ b/system/src/Grav/Console/Cli/BackupCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/CleanCommand.php b/system/src/Grav/Console/Cli/CleanCommand.php
index 84b46d6..e6b8f98 100644
--- a/system/src/Grav/Console/Cli/CleanCommand.php
+++ b/system/src/Grav/Console/Cli/CleanCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/ClearCacheCommand.php b/system/src/Grav/Console/Cli/ClearCacheCommand.php
index daed2a5..7550dd9 100644
--- a/system/src/Grav/Console/Cli/ClearCacheCommand.php
+++ b/system/src/Grav/Console/Cli/ClearCacheCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/ComposerCommand.php b/system/src/Grav/Console/Cli/ComposerCommand.php
index 5075d1d..0dc9bcd 100644
--- a/system/src/Grav/Console/Cli/ComposerCommand.php
+++ b/system/src/Grav/Console/Cli/ComposerCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php
index 22258be..33198cb 100644
--- a/system/src/Grav/Console/Cli/InstallCommand.php
+++ b/system/src/Grav/Console/Cli/InstallCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/LogViewerCommand.php b/system/src/Grav/Console/Cli/LogViewerCommand.php
index d3924f8..d7e127e 100644
--- a/system/src/Grav/Console/Cli/LogViewerCommand.php
+++ b/system/src/Grav/Console/Cli/LogViewerCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/NewProjectCommand.php b/system/src/Grav/Console/Cli/NewProjectCommand.php
index d67cb1c..7abbc4e 100644
--- a/system/src/Grav/Console/Cli/NewProjectCommand.php
+++ b/system/src/Grav/Console/Cli/NewProjectCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php
index 4d234d7..3a69600 100644
--- a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php
+++ b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php
index d865b4a..0ba2850 100644
--- a/system/src/Grav/Console/Cli/SandboxCommand.php
+++ b/system/src/Grav/Console/Cli/SandboxCommand.php
@@ -3,13 +3,14 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Console\Cli;
use Grav\Common\Filesystem\Folder;
+use Grav\Common\Utils;
use Grav\Console\GravCommand;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
@@ -200,6 +201,10 @@ class SandboxCommand extends GravCommand
$io->newLine();
$io->writeln('Resetting Symbolic Links');
+ // Symlink also tests if using git.
+ if (is_dir($this->source . '/tests')) {
+ $this->mappings['/tests'] = '/tests';
+ }
foreach ($this->mappings as $source => $target) {
if ((string)(int)$source === (string)$source) {
@@ -297,7 +302,7 @@ class SandboxCommand extends GravCommand
foreach ($binaries as $bin) {
chmod($bin, $dir_perms);
- $io->writeln(' bin/' . basename($bin) . ' permissions reset to ' . decoct($dir_perms));
+ $io->writeln(' bin/' . Utils::basename($bin) . ' permissions reset to ' . decoct($dir_perms));
}
$io->newLine();
diff --git a/system/src/Grav/Console/Cli/SchedulerCommand.php b/system/src/Grav/Console/Cli/SchedulerCommand.php
index c5385aa..91fc57d 100644
--- a/system/src/Grav/Console/Cli/SchedulerCommand.php
+++ b/system/src/Grav/Console/Cli/SchedulerCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -77,8 +77,6 @@ class SchedulerCommand extends GravCommand
$scheduler = $grav['scheduler'];
$grav->fireEvent('onSchedulerInitialized', new Event(['scheduler' => $scheduler]));
- $this->setHelp('foo');
-
$input = $this->getInput();
$io = $this->getIO();
$error = 0;
diff --git a/system/src/Grav/Console/Cli/SecurityCommand.php b/system/src/Grav/Console/Cli/SecurityCommand.php
index 7f728b6..b6cb662 100644
--- a/system/src/Grav/Console/Cli/SecurityCommand.php
+++ b/system/src/Grav/Console/Cli/SecurityCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/ServerCommand.php b/system/src/Grav/Console/Cli/ServerCommand.php
index 77bce8b..29b423e 100644
--- a/system/src/Grav/Console/Cli/ServerCommand.php
+++ b/system/src/Grav/Console/Cli/ServerCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Cli/YamlLinterCommand.php b/system/src/Grav/Console/Cli/YamlLinterCommand.php
index a9628cd..75a7559 100644
--- a/system/src/Grav/Console/Cli/YamlLinterCommand.php
+++ b/system/src/Grav/Console/Cli/YamlLinterCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Cli
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/ConsoleCommand.php b/system/src/Grav/Console/ConsoleCommand.php
index 044f1b0..c522c88 100644
--- a/system/src/Grav/Console/ConsoleCommand.php
+++ b/system/src/Grav/Console/ConsoleCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php
index feb10d3..0af4075 100644
--- a/system/src/Grav/Console/ConsoleTrait.php
+++ b/system/src/Grav/Console/ConsoleTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/DirectInstallCommand.php b/system/src/Grav/Console/Gpm/DirectInstallCommand.php
index e5c662b..fbb0220 100644
--- a/system/src/Grav/Console/Gpm/DirectInstallCommand.php
+++ b/system/src/Grav/Console/Gpm/DirectInstallCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/IndexCommand.php b/system/src/Grav/Console/Gpm/IndexCommand.php
index ecc91fe..367322b 100644
--- a/system/src/Grav/Console/Gpm/IndexCommand.php
+++ b/system/src/Grav/Console/Gpm/IndexCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/InfoCommand.php b/system/src/Grav/Console/Gpm/InfoCommand.php
index 5dddd32..c6f8552 100644
--- a/system/src/Grav/Console/Gpm/InfoCommand.php
+++ b/system/src/Grav/Console/Gpm/InfoCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php
index 92c8e07..d25ebe3 100644
--- a/system/src/Grav/Console/Gpm/InstallCommand.php
+++ b/system/src/Grav/Console/Gpm/InstallCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -579,7 +579,7 @@ class InstallCommand extends GpmCommand
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
$this->tmp = $tmp_dir . '/Grav-' . uniqid();
- $filename = $package->slug . basename($package->zipball_url);
+ $filename = $package->slug . Utils::basename($package->zipball_url);
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename);
$query = '';
diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
index b840016..a3d53ff 100644
--- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
+++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php
index cb14c65..a3db657 100644
--- a/system/src/Grav/Console/Gpm/UninstallCommand.php
+++ b/system/src/Grav/Console/Gpm/UninstallCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php
index 300fe61..73c5c9e 100644
--- a/system/src/Grav/Console/Gpm/UpdateCommand.php
+++ b/system/src/Grav/Console/Gpm/UpdateCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Gpm/VersionCommand.php b/system/src/Grav/Console/Gpm/VersionCommand.php
index 124aad3..8629196 100644
--- a/system/src/Grav/Console/Gpm/VersionCommand.php
+++ b/system/src/Grav/Console/Gpm/VersionCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Gpm
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/GpmCommand.php b/system/src/Grav/Console/GpmCommand.php
index 816e872..a14eb47 100644
--- a/system/src/Grav/Console/GpmCommand.php
+++ b/system/src/Grav/Console/GpmCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/GravCommand.php b/system/src/Grav/Console/GravCommand.php
index 0249f14..7db18e2 100644
--- a/system/src/Grav/Console/GravCommand.php
+++ b/system/src/Grav/Console/GravCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/Plugin/PluginListCommand.php b/system/src/Grav/Console/Plugin/PluginListCommand.php
index 81041c0..0226614 100644
--- a/system/src/Grav/Console/Plugin/PluginListCommand.php
+++ b/system/src/Grav/Console/Plugin/PluginListCommand.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\Plugin
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Console/TerminalObjects/Table.php b/system/src/Grav/Console/TerminalObjects/Table.php
index a71d7c0..153993d 100644
--- a/system/src/Grav/Console/TerminalObjects/Table.php
+++ b/system/src/Grav/Console/TerminalObjects/Table.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Console\TerminalObjects
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Events/FlexRegisterEvent.php b/system/src/Grav/Events/FlexRegisterEvent.php
index 13aebf3..b02ed1d 100644
--- a/system/src/Grav/Events/FlexRegisterEvent.php
+++ b/system/src/Grav/Events/FlexRegisterEvent.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Events
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Events/PermissionsRegisterEvent.php b/system/src/Grav/Events/PermissionsRegisterEvent.php
index 5e63c85..434dcfa 100644
--- a/system/src/Grav/Events/PermissionsRegisterEvent.php
+++ b/system/src/Grav/Events/PermissionsRegisterEvent.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Events
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Events/PluginsLoadedEvent.php b/system/src/Grav/Events/PluginsLoadedEvent.php
index 9dfd18b..13e2226 100644
--- a/system/src/Grav/Events/PluginsLoadedEvent.php
+++ b/system/src/Grav/Events/PluginsLoadedEvent.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Events
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Events/SessionStartEvent.php b/system/src/Grav/Events/SessionStartEvent.php
index e724a09..fc4f364 100644
--- a/system/src/Grav/Events/SessionStartEvent.php
+++ b/system/src/Grav/Events/SessionStartEvent.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Events
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Acl/Access.php b/system/src/Grav/Framework/Acl/Access.php
index ccc22cf..45cf2bf 100644
--- a/system/src/Grav/Framework/Acl/Access.php
+++ b/system/src/Grav/Framework/Acl/Access.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Acl
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -14,7 +14,6 @@ use Countable;
use Grav\Common\Utils;
use IteratorAggregate;
use JsonSerializable;
-use RuntimeException;
use Traversable;
use function count;
use function is_array;
@@ -25,6 +24,7 @@ use function strlen;
/**
* Class Access
* @package Grav\Framework\Acl
+ * @implements IteratorAggregate
*/
class Access implements JsonSerializable, IteratorAggregate, Countable
{
@@ -34,7 +34,7 @@ class Access implements JsonSerializable, IteratorAggregate, Countable
private $rules;
/** @var array */
private $ops;
- /** @var array */
+ /** @var array */
private $acl = [];
/** @var array */
private $inherited = [];
@@ -78,12 +78,7 @@ class Access implements JsonSerializable, IteratorAggregate, Countable
$inherited = array_diff_key($parent->getAllActions(), $acl);
$this->inherited += $parent->inherited + array_fill_keys(array_keys($inherited), $name ?? $parent->getName());
- $acl = array_replace($acl, $inherited);
- if (null === $acl) {
- throw new RuntimeException('Internal error');
- }
-
- $this->acl = $acl;
+ $this->acl = array_replace($acl, $inherited);
}
/**
diff --git a/system/src/Grav/Framework/Acl/Action.php b/system/src/Grav/Framework/Acl/Action.php
index 1f883a0..6251c3c 100644
--- a/system/src/Grav/Framework/Acl/Action.php
+++ b/system/src/Grav/Framework/Acl/Action.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Acl
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,11 +16,11 @@ use IteratorAggregate;
use RuntimeException;
use Traversable;
use function count;
-use function strlen;
/**
* Class Action
* @package Grav\Framework\Acl
+ * @implements IteratorAggregate
*/
class Action implements IteratorAggregate, Countable
{
@@ -37,7 +37,7 @@ class Action implements IteratorAggregate, Countable
/** @var Action|null */
protected $parent;
- /** @var Action[] */
+ /** @var array */
protected $children = [];
/**
@@ -48,8 +48,8 @@ class Action implements IteratorAggregate, Countable
{
$label = $action['label'] ?? null;
if (!$label) {
- if ($pos = strrpos($name, '.')) {
- $label = substr($name, $pos + 1);
+ if ($pos = mb_strrpos($name, '.')) {
+ $label = mb_substr($name, $pos + 1);
} else {
$label = $name;
}
@@ -114,9 +114,9 @@ class Action implements IteratorAggregate, Countable
*/
public function getScope(): string
{
- $pos = strpos($this->name, '.');
+ $pos = mb_strpos($this->name, '.');
if ($pos) {
- return substr($this->name, 0, $pos);
+ return mb_substr($this->name, 0, $pos);
}
return $this->name;
@@ -127,7 +127,7 @@ class Action implements IteratorAggregate, Countable
*/
public function getLevels(): int
{
- return substr_count($this->name, '.');
+ return mb_substr_count($this->name, '.');
}
/**
@@ -161,12 +161,12 @@ class Action implements IteratorAggregate, Countable
*/
public function addChild(Action $child): void
{
- if (strpos($child->name, "{$this->name}.") !== 0) {
+ if (mb_strpos($child->name, "{$this->name}.") !== 0) {
throw new RuntimeException('Bad child');
}
$child->setParent($this);
- $name = substr($child->name, strlen($this->name) + 1);
+ $name = mb_substr($child->name, mb_strlen($this->name) + 1);
$this->children[$name] = $child;
}
@@ -190,6 +190,7 @@ class Action implements IteratorAggregate, Countable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
diff --git a/system/src/Grav/Framework/Acl/Permissions.php b/system/src/Grav/Framework/Acl/Permissions.php
index 0375716..e54590a 100644
--- a/system/src/Grav/Framework/Acl/Permissions.php
+++ b/system/src/Grav/Framework/Acl/Permissions.php
@@ -3,26 +3,32 @@
/**
* @package Grav\Framework\Acl
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Acl;
+use ArrayAccess;
use ArrayIterator;
+use Countable;
+use IteratorAggregate;
use RecursiveIteratorIterator;
use RuntimeException;
use Traversable;
+use function count;
/**
* Class Permissions
* @package Grav\Framework\Acl
+ * @implements ArrayAccess
+ * @implements IteratorAggregate
*/
-class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
+class Permissions implements ArrayAccess, Countable, IteratorAggregate
{
- /** @var Action[] */
+ /** @var array */
protected $instances = [];
- /** @var Action[] */
+ /** @var array */
protected $actions = [];
/** @var array */
protected $nested = [];
@@ -142,9 +148,6 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
public function addTypes(array $types): void
{
$types = array_replace($this->types, $types);
- if (null === $types) {
- throw new RuntimeException('Internal error');
- }
$this->types = $types;
}
@@ -206,6 +209,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* @return ArrayIterator|Traversable
*/
+ #[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->actions);
@@ -214,6 +218,7 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
diff --git a/system/src/Grav/Framework/Acl/PermissionsReader.php b/system/src/Grav/Framework/Acl/PermissionsReader.php
index b157a5d..350fc96 100644
--- a/system/src/Grav/Framework/Acl/PermissionsReader.php
+++ b/system/src/Grav/Framework/Acl/PermissionsReader.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Acl
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -62,12 +62,14 @@ class PermissionsReader
{
$list = [];
foreach ($actions as $name => $action) {
- $prefixNname = $prefix . $name;
- $list[$prefixNname] = null;
+ $prefixName = $prefix . $name;
+ $list[$prefixName] = null;
// Support nested sets of actions.
if (isset($action['actions']) && is_array($action['actions'])) {
- $list += static::read($action['actions'], "{$prefixNname}.");
+ $innerList = static::read($action['actions'], "{$prefixName}.");
+
+ $list += $innerList;
}
unset($action['actions']);
@@ -76,7 +78,7 @@ class PermissionsReader
$action = static::addDefaults($action);
// Build flat list of actions.
- $list[$prefixNname] = $action;
+ $list[$prefixName] = $action;
}
return $list;
@@ -172,9 +174,6 @@ class PermissionsReader
$scopes[] = $action;
$action = array_replace_recursive(...$scopes);
- if (null === $action) {
- throw new RuntimeException('Internal error');
- }
$newType = $defaults['type'] ?? null;
if ($newType && $newType !== $type) {
diff --git a/system/src/Grav/Framework/Acl/RecursiveActionIterator.php b/system/src/Grav/Framework/Acl/RecursiveActionIterator.php
index ac219da..1fb9a60 100644
--- a/system/src/Grav/Framework/Acl/RecursiveActionIterator.php
+++ b/system/src/Grav/Framework/Acl/RecursiveActionIterator.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Acl
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -17,6 +17,7 @@ use RocketTheme\Toolbox\ArrayTraits\Iterator;
/**
* Class Action
* @package Grav\Framework\Acl
+ * @implements RecursiveIterator
*/
class RecursiveActionIterator implements RecursiveIterator, \Countable
{
@@ -26,6 +27,7 @@ class RecursiveActionIterator implements RecursiveIterator, \Countable
* @see \Iterator::key()
* @return string
*/
+ #[\ReturnTypeWillChange]
public function key()
{
/** @var Action $current */
diff --git a/system/src/Grav/Framework/Cache/AbstractCache.php b/system/src/Grav/Framework/Cache/AbstractCache.php
index bfb5125..b6d00a3 100644
--- a/system/src/Grav/Framework/Cache/AbstractCache.php
+++ b/system/src/Grav/Framework/Cache/AbstractCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/Adapter/ChainCache.php b/system/src/Grav/Framework/Cache/Adapter/ChainCache.php
index 76f5185..bca940f 100644
--- a/system/src/Grav/Framework/Cache/Adapter/ChainCache.php
+++ b/system/src/Grav/Framework/Cache/Adapter/ChainCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -33,11 +33,15 @@ class ChainCache extends AbstractCache
* Chain Cache constructor.
* @param array $caches
* @param null|int|DateInterval $defaultLifetime
- * @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
+ * @throws InvalidArgumentException
*/
public function __construct(array $caches, $defaultLifetime = null)
{
- parent::__construct('', $defaultLifetime);
+ try {
+ parent::__construct('', $defaultLifetime);
+ } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
+ throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
+ }
if (!$caches) {
throw new InvalidArgumentException('At least one cache must be specified');
diff --git a/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php b/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php
index 29e9e3b..15afed3 100644
--- a/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php
+++ b/system/src/Grav/Framework/Cache/Adapter/DoctrineCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -29,12 +29,16 @@ class DoctrineCache extends AbstractCache
* @param CacheProvider $doctrineCache
* @param string $namespace
* @param null|int|DateInterval $defaultLifetime
- * @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
+ * @throws InvalidArgumentException
*/
public function __construct(CacheProvider $doctrineCache, $namespace = '', $defaultLifetime = null)
{
// Do not use $namespace or $defaultLifetime directly, store them with constructor and fetch with methods.
- parent::__construct($namespace, $defaultLifetime);
+ try {
+ parent::__construct($namespace, $defaultLifetime);
+ } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
+ throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
+ }
// Set namespace to Doctrine Cache provider if it was given.
$namespace = $this->getNamespace();
diff --git a/system/src/Grav/Framework/Cache/Adapter/FileCache.php b/system/src/Grav/Framework/Cache/Adapter/FileCache.php
index 1995e15..7f1d5e7 100644
--- a/system/src/Grav/Framework/Cache/Adapter/FileCache.php
+++ b/system/src/Grav/Framework/Cache/Adapter/FileCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -42,9 +42,13 @@ class FileCache extends AbstractCache
*/
public function __construct($namespace = '', $defaultLifetime = null, $folder = null)
{
- parent::__construct($namespace, $defaultLifetime ?: 31557600); // = 1 year
+ try {
+ parent::__construct($namespace, $defaultLifetime ?: 31557600); // = 1 year
- $this->initFileCache($namespace, $folder ?? '');
+ $this->initFileCache($namespace, $folder ?? '');
+ } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
+ throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
+ }
}
/**
@@ -103,7 +107,13 @@ class FileCache extends AbstractCache
{
$file = $this->getFile($key);
- return (!file_exists($file) || @unlink($file) || !file_exists($file));
+ $result = false;
+ if (file_exists($file)) {
+ $result = @unlink($file);
+ $result &= !file_exists($file);
+ }
+
+ return $result;
}
/**
@@ -156,7 +166,7 @@ class FileCache extends AbstractCache
*/
protected function initFileCache($namespace, $directory)
{
- if (!isset($directory[0])) {
+ if ($directory === '') {
$directory = sys_get_temp_dir() . '/grav-cache';
} else {
$directory = realpath($directory) ?: $directory;
@@ -246,6 +256,7 @@ class FileCache extends AbstractCache
/**
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
if ($this->tmp !== null && file_exists($this->tmp)) {
diff --git a/system/src/Grav/Framework/Cache/Adapter/MemoryCache.php b/system/src/Grav/Framework/Cache/Adapter/MemoryCache.php
index c043bf9..21cd89c 100644
--- a/system/src/Grav/Framework/Cache/Adapter/MemoryCache.php
+++ b/system/src/Grav/Framework/Cache/Adapter/MemoryCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/Adapter/SessionCache.php b/system/src/Grav/Framework/Cache/Adapter/SessionCache.php
index e189e3e..02fe7c9 100644
--- a/system/src/Grav/Framework/Cache/Adapter/SessionCache.php
+++ b/system/src/Grav/Framework/Cache/Adapter/SessionCache.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/CacheInterface.php b/system/src/Grav/Framework/Cache/CacheInterface.php
index efd9d31..03dfa7a 100644
--- a/system/src/Grav/Framework/Cache/CacheInterface.php
+++ b/system/src/Grav/Framework/Cache/CacheInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/CacheTrait.php b/system/src/Grav/Framework/Cache/CacheTrait.php
index 287f924..37dd6c9 100644
--- a/system/src/Grav/Framework/Cache/CacheTrait.php
+++ b/system/src/Grav/Framework/Cache/CacheTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/Exception/CacheException.php b/system/src/Grav/Framework/Cache/Exception/CacheException.php
index 1db3256..db33883 100644
--- a/system/src/Grav/Framework/Cache/Exception/CacheException.php
+++ b/system/src/Grav/Framework/Cache/Exception/CacheException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Cache/Exception/InvalidArgumentException.php b/system/src/Grav/Framework/Cache/Exception/InvalidArgumentException.php
index 08a3435..70c0418 100644
--- a/system/src/Grav/Framework/Cache/Exception/InvalidArgumentException.php
+++ b/system/src/Grav/Framework/Cache/Exception/InvalidArgumentException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Cache
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Collection/AbstractFileCollection.php b/system/src/Grav/Framework/Collection/AbstractFileCollection.php
index 1be8d12..500aea8 100644
--- a/system/src/Grav/Framework/Collection/AbstractFileCollection.php
+++ b/system/src/Grav/Framework/Collection/AbstractFileCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -68,6 +68,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
/**
* @param Criteria $criteria
* @return ArrayCollection
+ * @phpstan-return ArrayCollection
* @todo Implement lazy matching
*/
public function matching(Criteria $criteria)
@@ -93,6 +94,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
}
+ /** @phpstan-ignore-next-line */
if (null === $next) {
throw new RuntimeException('Criteria is missing orderings');
}
@@ -162,6 +164,7 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
* @param SeekableIterator $iterator
* @param int $nestingLimit
* @return array
+ * @phpstan-param SeekableIterator $iterator
*/
protected function doInitializeByIterator(SeekableIterator $iterator, $nestingLimit)
{
@@ -211,7 +214,6 @@ class AbstractFileCollection extends AbstractLazyCollection implements FileColle
protected function doInitializeChildren(array $children, $nestingLimit)
{
$objects = [];
-
foreach ($children as $iterator) {
$objects += $this->doInitializeByIterator($iterator, $nestingLimit);
}
diff --git a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php
index 25d8672..02916d9 100644
--- a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php
+++ b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -14,6 +14,7 @@ use Closure;
use Grav\Framework\Compat\Serializable;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use InvalidArgumentException;
+use Iterator;
use function array_key_exists;
use function array_slice;
use function count;
@@ -79,17 +80,17 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function key()
{
- /** @phpstan-var TKey $key */
- $key = (string)key($this->entries);
-
- return $key;
+ /** @phpstan-var TKey */
+ return (string)key($this->entries);
}
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function next()
{
$value = next($this->entries);
@@ -101,6 +102,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function current()
{
$value = current($this->entries);
@@ -131,7 +133,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
{
$key = $this->isAllowedElement($element) ? $this->getCurrentKey($element) : null;
- if (!$key || !isset($this->entries[$key])) {
+ if (null !== $key || !isset($this->entries[$key])) {
return false;
}
@@ -143,49 +145,64 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* Required by interface ArrayAccess.
*
- * {@inheritDoc}
+ * @param string|int|null $offset
+ * @return bool
+ * @phpstan-param TKey|null $offset
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
- return $this->containsKey($offset);
+ /** @phpstan-ignore-next-line phpstan bug? */
+ return $offset !== null ? $this->containsKey($offset) : false;
}
/**
* Required by interface ArrayAccess.
*
- * {@inheritDoc}
+ * @param string|int|null $offset
+ * @return mixed
+ * @phpstan-param TKey|null $offset
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
- return $this->get($offset);
+ /** @phpstan-ignore-next-line phpstan bug? */
+ return $offset !== null ? $this->get($offset) : null;
}
/**
* Required by interface ArrayAccess.
*
- * {@inheritDoc}
+ * @param string|int|null $offset
+ * @param mixed $value
+ * @return void
+ * @phpstan-param TKey|null $offset
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (null === $offset) {
$this->add($value);
+ } else {
+ /** @phpstan-ignore-next-line phpstan bug? */
+ $this->set($offset, $value);
}
-
- $this->set($offset, $value);
}
/**
* Required by interface ArrayAccess.
*
- * {@inheritDoc}
+ * @param string|int|null $offset
+ * @return void
+ * @phpstan-param TKey|null $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
- $this->remove($offset);
+ if ($offset !== null) {
+ /** @phpstan-ignore-next-line phpstan bug? */
+ $this->remove($offset);
+ }
}
/**
@@ -255,6 +272,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function count()
{
return count($this->entries);
@@ -298,7 +316,9 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Required by interface IteratorAggregate.
*
* {@inheritDoc}
+ * @phpstan-return Iterator
*/
+ #[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->loadElements());
@@ -341,6 +361,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return __CLASS__ . '@' . spl_object_hash($this);
@@ -395,7 +416,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
$keys = $this->getKeys();
shuffle($keys);
- return $this->createFrom(array_replace(array_flip($keys), $this->entries) ?? []);
+ return $this->createFrom(array_replace(array_flip($keys), $this->entries));
}
/**
@@ -436,9 +457,11 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param int $size Size of each chunk.
* @return array
+ * @phpstan-return array>
*/
public function chunk($size)
{
+ /** @phpstan-var array> */
return $this->loadCollection($this->entries)->chunk($size);
}
@@ -466,6 +489,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->loadCollection()->jsonSerialize();
diff --git a/system/src/Grav/Framework/Collection/AbstractLazyCollection.php b/system/src/Grav/Framework/Collection/AbstractLazyCollection.php
index 9afaab1..b0a93f5 100644
--- a/system/src/Grav/Framework/Collection/AbstractLazyCollection.php
+++ b/system/src/Grav/Framework/Collection/AbstractLazyCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,11 +22,15 @@ use Doctrine\Common\Collections\AbstractLazyCollection as BaseAbstractLazyCollec
*/
abstract class AbstractLazyCollection extends BaseAbstractLazyCollection implements CollectionInterface
{
- /** @var ArrayCollection The backed collection to use */
+ /**
+ * @par ArrayCollection
+ * @phpstan-var ArrayCollection
+ */
protected $collection;
/**
* {@inheritDoc}
+ * @phpstan-return ArrayCollection
*/
public function reverse()
{
@@ -37,6 +41,7 @@ abstract class AbstractLazyCollection extends BaseAbstractLazyCollection impleme
/**
* {@inheritDoc}
+ * @phpstan-return ArrayCollection
*/
public function shuffle()
{
@@ -57,6 +62,8 @@ abstract class AbstractLazyCollection extends BaseAbstractLazyCollection impleme
/**
* {@inheritDoc}
+ * @phpstan-param array $keys
+ * @phpstan-return ArrayCollection
*/
public function select(array $keys)
{
@@ -67,6 +74,8 @@ abstract class AbstractLazyCollection extends BaseAbstractLazyCollection impleme
/**
* {@inheritDoc}
+ * @phpstan-param array $keys
+ * @phpstan-return ArrayCollection
*/
public function unselect(array $keys)
{
@@ -78,6 +87,7 @@ abstract class AbstractLazyCollection extends BaseAbstractLazyCollection impleme
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
$this->initialize();
diff --git a/system/src/Grav/Framework/Collection/ArrayCollection.php b/system/src/Grav/Framework/Collection/ArrayCollection.php
index d76aa05..cad02f2 100644
--- a/system/src/Grav/Framework/Collection/ArrayCollection.php
+++ b/system/src/Grav/Framework/Collection/ArrayCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -30,7 +30,10 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
*/
public function reverse()
{
- return $this->createFrom(array_reverse($this->toArray()));
+ $keys = array_reverse($this->toArray());
+
+ /** @phpstan-var static */
+ return $this->createFrom($keys);
}
/**
@@ -43,8 +46,10 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
{
$keys = $this->getKeys();
shuffle($keys);
+ $keys = array_replace(array_flip($keys), $this->toArray());
- return $this->createFrom(array_replace(array_flip($keys), $this->toArray()) ?? []);
+ /** @phpstan-var static */
+ return $this->createFrom($keys);
}
/**
@@ -52,9 +57,11 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
*
* @param int $size Size of each chunk.
* @return array
+ * @phpstan-return array>
*/
public function chunk($size)
{
+ /** @phpstan-var array> */
return array_chunk($this->toArray(), $size, true);
}
@@ -63,9 +70,9 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
*
* Collection is returned in the order of $keys given to the function.
*
- * @param array $keys
+ * @param array $keys
* @return static
- * @phpstan-param array $keys
+ * @phpstan-param TKey[] $keys
* @phpstan-return static
*/
public function select(array $keys)
@@ -77,6 +84,7 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
}
}
+ /** @phpstan-var static */
return $this->createFrom($list);
}
@@ -85,11 +93,15 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
*
* @param array $keys
* @return static
+ * @phpstan-param TKey[] $keys
* @phpstan-return static
*/
public function unselect(array $keys)
{
- return $this->select(array_diff($this->getKeys(), $keys));
+ $list = array_diff($this->getKeys(), $keys);
+
+ /** @phpstan-var static */
+ return $this->select($list);
}
/**
@@ -97,6 +109,7 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
diff --git a/system/src/Grav/Framework/Collection/CollectionInterface.php b/system/src/Grav/Framework/Collection/CollectionInterface.php
index 0739109..e098dd6 100644
--- a/system/src/Grav/Framework/Collection/CollectionInterface.php
+++ b/system/src/Grav/Framework/Collection/CollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -43,6 +43,7 @@ interface CollectionInterface extends Collection, JsonSerializable
*
* @param int $size Size of each chunk.
* @return array
+ * @phpstan-return array>
*/
public function chunk($size);
diff --git a/system/src/Grav/Framework/Collection/FileCollection.php b/system/src/Grav/Framework/Collection/FileCollection.php
index f7b4f25..bae0e7b 100644
--- a/system/src/Grav/Framework/Collection/FileCollection.php
+++ b/system/src/Grav/Framework/Collection/FileCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Collection/FileCollectionInterface.php b/system/src/Grav/Framework/Collection/FileCollectionInterface.php
index 45c446c..1b56da9 100644
--- a/system/src/Grav/Framework/Collection/FileCollectionInterface.php
+++ b/system/src/Grav/Framework/Collection/FileCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Collection
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Compat/Serializable.php b/system/src/Grav/Framework/Compat/Serializable.php
index 3c9bf6a..22e4648 100644
--- a/system/src/Grav/Framework/Compat/Serializable.php
+++ b/system/src/Grav/Framework/Compat/Serializable.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Compat
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/ContentBlock/ContentBlock.php b/system/src/Grav/Framework/ContentBlock/ContentBlock.php
index efcd5f3..7259df0 100644
--- a/system/src/Grav/Framework/ContentBlock/ContentBlock.php
+++ b/system/src/Grav/Framework/ContentBlock/ContentBlock.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\ContentBlock
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -161,6 +161,7 @@ class ContentBlock implements ContentBlockInterface
/**
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
try {
diff --git a/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php b/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php
index fb445a3..bb0e46f 100644
--- a/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php
+++ b/system/src/Grav/Framework/ContentBlock/ContentBlockInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\ContentBlock
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/ContentBlock/HtmlBlock.php b/system/src/Grav/Framework/ContentBlock/HtmlBlock.php
index 5c5eb43..69d417c 100644
--- a/system/src/Grav/Framework/ContentBlock/HtmlBlock.php
+++ b/system/src/Grav/Framework/ContentBlock/HtmlBlock.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\ContentBlock
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -29,6 +29,8 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
/** @var array */
protected $scripts = [];
/** @var array */
+ protected $links = [];
+ /** @var array */
protected $html = [];
/**
@@ -40,6 +42,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
$this->sortAssets($assets['styles']);
$this->sortAssets($assets['scripts']);
+ $this->sortAssets($assets['links']);
$this->sortAssets($assets['html']);
return $assets;
@@ -73,6 +76,15 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
return $this->getAssetsInLocation('scripts', $location);
}
+ /**
+ * @param string $location
+ * @return array
+ */
+ public function getLinks($location = 'head')
+ {
+ return $this->getAssetsInLocation('links', $location);
+ }
+
/**
* @param string $location
* @return array
@@ -98,6 +110,9 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
if ($this->scripts) {
$array['scripts'] = $this->scripts;
}
+ if ($this->links) {
+ $array['links'] = $this->links;
+ }
if ($this->html) {
$array['html'] = $this->html;
}
@@ -117,6 +132,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
$this->frameworks = isset($serialized['frameworks']) ? (array) $serialized['frameworks'] : [];
$this->styles = isset($serialized['styles']) ? (array) $serialized['styles'] : [];
$this->scripts = isset($serialized['scripts']) ? (array) $serialized['scripts'] : [];
+ $this->links = isset($serialized['links']) ? (array) $serialized['links'] : [];
$this->html = isset($serialized['html']) ? (array) $serialized['html'] : [];
}
@@ -199,11 +215,14 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
$content = (string) $element['content'];
$type = !empty($element['type']) ? (string) $element['type'] : 'text/css';
+ unset($element['content'], $element['type']);
+
$this->styles[$location][md5($content) . sha1($content)] = [
':type' => 'inline',
':priority' => (int) $priority,
'content' => $content,
- 'type' => $type
+ 'type' => $type,
+ 'element' => $element
];
return true;
@@ -229,18 +248,23 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
$src = $element['src'];
$type = !empty($element['type']) ? (string) $element['type'] : 'text/javascript';
- $defer = isset($element['defer']);
- $async = isset($element['async']);
+ $loading = !empty($element['loading']) ? (string) $element['loading'] : null;
+ $defer = !empty($element['defer']);
+ $async = !empty($element['async']);
$handle = !empty($element['handle']) ? (string) $element['handle'] : '';
+ unset($element['src'], $element['type'], $element['loading'], $element['defer'], $element['async'], $element['handle']);
+
$this->scripts[$location][md5($src) . sha1($src)] = [
':type' => 'file',
':priority' => (int) $priority,
'src' => $src,
'type' => $type,
+ 'loading' => $loading,
'defer' => $defer,
'async' => $async,
- 'handle' => $handle
+ 'handle' => $handle,
+ 'element' => $element
];
return true;
@@ -266,12 +290,83 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
$content = (string) $element['content'];
$type = !empty($element['type']) ? (string) $element['type'] : 'text/javascript';
+ $loading = !empty($element['loading']) ? (string) $element['loading'] : null;
+
+ unset($element['content'], $element['type'], $element['loading']);
$this->scripts[$location][md5($content) . sha1($content)] = [
':type' => 'inline',
':priority' => (int) $priority,
'content' => $content,
- 'type' => $type
+ 'type' => $type,
+ 'loading' => $loading,
+ 'element' => $element
+ ];
+
+ return true;
+ }
+
+ /**
+ * @param string|array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addModule($element, $priority = 0, $location = 'head')
+ {
+ if (!is_array($element)) {
+ $element = ['src' => (string) $element];
+ }
+
+ $element['type'] = 'module';
+
+ return $this->addScript($element, $priority, $location);
+ }
+
+ /**
+ * @param string|array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addInlineModule($element, $priority = 0, $location = 'head')
+ {
+ if (!is_array($element)) {
+ $element = ['content' => (string) $element];
+ }
+
+ $element['type'] = 'module';
+
+ return $this->addInlineScript($element, $priority, $location);
+ }
+
+ /**
+ * @param array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addLink($element, $priority = 0, $location = 'head')
+ {
+ if (!is_array($element) || empty($element['rel']) || empty($element['href'])) {
+ return false;
+ }
+
+ if (!isset($this->links[$location])) {
+ $this->links[$location] = [];
+ }
+
+ $rel = (string) $element['rel'];
+ $href = (string) $element['href'];
+
+ unset($element['rel'], $element['href']);
+
+ $this->links[$location][md5($href) . sha1($href)] = [
+ ':type' => 'file',
+ ':priority' => (int) $priority,
+ 'href' => $href,
+ 'rel' => $rel,
+ 'element' => $element,
];
return true;
@@ -309,6 +404,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
'frameworks' => $this->frameworks,
'styles' => $this->styles,
'scripts' => $this->scripts,
+ 'links' => $this->links,
'html' => $this->html
];
@@ -333,6 +429,14 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
}
}
+ foreach ($blockAssets['links'] as $location => $links) {
+ if (!isset($assets['links'][$location])) {
+ $assets['links'][$location] = $links;
+ } elseif ($links) {
+ $assets['links'][$location] += $links;
+ }
+ }
+
foreach ($blockAssets['html'] as $location => $htmls) {
if (!isset($assets['html'][$location])) {
$assets['html'][$location] = $htmls;
@@ -391,7 +495,7 @@ class HtmlBlock extends ContentBlock implements HtmlBlockInterface
*/
protected function sortAssets(array &$array)
{
- foreach ($array as $location => &$items) {
+ foreach ($array as &$items) {
$this->sortAssetsInLocation($items);
}
}
diff --git a/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php b/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php
index 616e4a2..b151d7b 100644
--- a/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php
+++ b/system/src/Grav/Framework/ContentBlock/HtmlBlockInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\ContentBlock
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -37,6 +37,13 @@ interface HtmlBlockInterface extends ContentBlockInterface
*/
public function getScripts($location = 'head');
+
+ /**
+ * @param string $location
+ * @return array
+ */
+ public function getLinks($location = 'head');
+
/**
* @param string $location
* @return array
@@ -76,7 +83,6 @@ interface HtmlBlockInterface extends ContentBlockInterface
*/
public function addScript($element, $priority = 0, $location = 'head');
-
/**
* @param string|array $element
* @param int $priority
@@ -85,6 +91,35 @@ interface HtmlBlockInterface extends ContentBlockInterface
*/
public function addInlineScript($element, $priority = 0, $location = 'head');
+
+ /**
+ * Shortcut for writing addScript(['type' => 'module', 'src' => ...]).
+ *
+ * @param string|array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addModule($element, $priority = 0, $location = 'head');
+
+ /**
+ * Shortcut for writing addInlineScript(['type' => 'module', 'content' => ...]).
+ *
+ * @param string|array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addInlineModule($element, $priority = 0, $location = 'head');
+
+ /**
+ * @param array $element
+ * @param int $priority
+ * @param string $location
+ * @return bool
+ */
+ public function addLink($element, $priority = 0, $location = 'head');
+
/**
* @param string $html
* @param int $priority
diff --git a/system/src/Grav/Framework/Controller/Traits/ControllerResponseTrait.php b/system/src/Grav/Framework/Controller/Traits/ControllerResponseTrait.php
index afa08aa..24e1fc2 100644
--- a/system/src/Grav/Framework/Controller/Traits/ControllerResponseTrait.php
+++ b/system/src/Grav/Framework/Controller/Traits/ControllerResponseTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Controller
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -97,7 +97,7 @@ trait ControllerResponseTrait
$headers = $headers ?? [];
$options = $options ?? ['force_download' => true];
- $file_parts = pathinfo($filename);
+ $file_parts = Utils::pathinfo($filename);
if (!isset($headers['Content-Type'])) {
$mimetype = Utils::getMimeByExtension($file_parts['extension']);
@@ -140,9 +140,9 @@ trait ControllerResponseTrait
$code = (int)$this->getConfig()->get('system.pages.redirect_default_code', 302);
}
+ $ext = Utils::pathinfo($url, PATHINFO_EXTENSION);
$accept = $this->getAccept(['application/json', 'text/html']);
-
- if ($accept === 'application/json') {
+ if ($ext === 'json' || $accept === 'application/json') {
return $this->createJsonResponse(['code' => $code, 'status' => 'redirect', 'redirect' => $url]);
}
@@ -217,6 +217,7 @@ trait ControllerResponseTrait
'code' => $code,
'status' => 'error',
'message' => $message,
+ 'redirect' => null,
'error' => [
'code' => $code,
'message' => $message
diff --git a/system/src/Grav/Framework/DI/Container.php b/system/src/Grav/Framework/DI/Container.php
index 76434a3..dde0da3 100644
--- a/system/src/Grav/Framework/DI/Container.php
+++ b/system/src/Grav/Framework/DI/Container.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\DI
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/AbstractFile.php b/system/src/Grav/Framework/File/AbstractFile.php
index b82bb33..b216ea6 100644
--- a/system/src/Grav/Framework/File/AbstractFile.php
+++ b/system/src/Grav/Framework/File/AbstractFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -55,6 +55,7 @@ class AbstractFile implements FileInterface
/**
* Unlock file when the object gets destroyed.
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
if ($this->isLocked()) {
@@ -65,6 +66,7 @@ class AbstractFile implements FileInterface
/**
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
$this->handle = null;
@@ -191,15 +193,16 @@ class AbstractFile implements FileInterface
$this->handle = @fopen($this->filepath, 'cb+') ?: null;
if (!$this->handle) {
$error = error_get_last();
+ $message = $error['message'] ?? 'Unknown error';
- throw new RuntimeException("Opening file for writing failed on error {$error['message']}");
+ throw new RuntimeException("Opening file for writing failed on error {$message}");
}
}
$lock = $block ? LOCK_EX : LOCK_EX | LOCK_NB;
// Some filesystems do not support file locks, only fail if another process holds the lock.
- $this->locked = flock($this->handle, $lock, $wouldblock) || !$wouldblock;
+ $this->locked = flock($this->handle, $lock, $wouldBlock) || !$wouldBlock;
return $this->locked;
}
diff --git a/system/src/Grav/Framework/File/CsvFile.php b/system/src/Grav/Framework/File/CsvFile.php
index 999f88a..7eba91e 100644
--- a/system/src/Grav/Framework/File/CsvFile.php
+++ b/system/src/Grav/Framework/File/CsvFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,4 +28,13 @@ class CsvFile extends DataFile
{
parent::__construct($filepath, $formatter);
}
+
+ /**
+ * @return array
+ */
+ public function load(): array
+ {
+ /** @var array */
+ return parent::load();
+ }
}
diff --git a/system/src/Grav/Framework/File/DataFile.php b/system/src/Grav/Framework/File/DataFile.php
index 114146f..189db53 100644
--- a/system/src/Grav/Framework/File/DataFile.php
+++ b/system/src/Grav/Framework/File/DataFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/File.php b/system/src/Grav/Framework/File/File.php
index 1d4055a..b1a1c4f 100644
--- a/system/src/Grav/Framework/File/File.php
+++ b/system/src/Grav/Framework/File/File.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -20,15 +20,6 @@ use function is_string;
*/
class File extends AbstractFile
{
- /**
- * {@inheritdoc}
- * @see FileInterface::load()
- */
- public function load()
- {
- return parent::load();
- }
-
/**
* {@inheritdoc}
* @see FileInterface::save()
diff --git a/system/src/Grav/Framework/File/Formatter/AbstractFormatter.php b/system/src/Grav/Framework/File/Formatter/AbstractFormatter.php
index f5ff3f2..6a6981b 100644
--- a/system/src/Grav/Framework/File/Formatter/AbstractFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/AbstractFormatter.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/Formatter/CsvFormatter.php b/system/src/Grav/Framework/File/Formatter/CsvFormatter.php
index 9d0a9a8..37ab5bb 100644
--- a/system/src/Grav/Framework/File/Formatter/CsvFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/CsvFormatter.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,6 +16,7 @@ use Grav\Framework\File\Interfaces\FileFormatterInterface;
use JsonSerializable;
use RuntimeException;
use stdClass;
+use function count;
use function is_array;
use function is_object;
use function is_scalar;
diff --git a/system/src/Grav/Framework/File/Formatter/IniFormatter.php b/system/src/Grav/Framework/File/Formatter/IniFormatter.php
index ec16959..ecf67d1 100644
--- a/system/src/Grav/Framework/File/Formatter/IniFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/IniFormatter.php
@@ -5,13 +5,14 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\File\Formatter;
use Grav\Framework\File\Interfaces\FileFormatterInterface;
+use RuntimeException;
/**
* Class IniFormatter
@@ -59,7 +60,7 @@ class IniFormatter extends AbstractFormatter
$decoded = @parse_ini_string($data);
if ($decoded === false) {
- throw new \RuntimeException('Decoding INI failed');
+ throw new RuntimeException('Decoding INI failed');
}
return $decoded;
diff --git a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php
index 6b19690..2bd6c79 100644
--- a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -75,9 +75,11 @@ class JsonFormatter extends AbstractFormatter
if (is_string($options)) {
$list = preg_split('/[\s,|]+/', $options);
$options = 0;
- foreach ($list as $option) {
- if (isset($this->encodeOptions[$option])) {
- $options += $this->encodeOptions[$option];
+ if ($list) {
+ foreach ($list as $option) {
+ if (isset($this->encodeOptions[$option])) {
+ $options += $this->encodeOptions[$option];
+ }
}
}
} else {
@@ -100,9 +102,11 @@ class JsonFormatter extends AbstractFormatter
if (is_string($options)) {
$list = preg_split('/[\s,|]+/', $options);
$options = 0;
- foreach ($list as $option) {
- if (isset($this->decodeOptions[$option])) {
- $options += $this->decodeOptions[$option];
+ if ($list) {
+ foreach ($list as $option) {
+ if (isset($this->decodeOptions[$option])) {
+ $options += $this->decodeOptions[$option];
+ }
}
}
} else {
@@ -117,6 +121,7 @@ class JsonFormatter extends AbstractFormatter
* Returns recursion depth used in decode() function.
*
* @return int
+ * @phpstan-return positive-int
*/
public function getDecodeDepth(): int
{
diff --git a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php
index 8a624df..e36276a 100644
--- a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php
@@ -5,13 +5,14 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\File\Formatter;
use Grav\Framework\File\Interfaces\FileFormatterInterface;
+use RuntimeException;
/**
* Class MarkdownFormatter
@@ -99,7 +100,7 @@ class MarkdownFormatter extends AbstractFormatter
// Normalize line endings to Unix style.
$encoded = preg_replace("/(\r\n|\r)/u", "\n", $encoded);
if (null === $encoded) {
- throw new \RuntimeException('Encoding markdown failed');
+ throw new RuntimeException('Encoding markdown failed');
}
return $encoded;
@@ -126,7 +127,7 @@ class MarkdownFormatter extends AbstractFormatter
// Normalize line endings to Unix style.
$data = preg_replace("/(\r\n|\r)/u", "\n", $data);
if (null === $data) {
- throw new \RuntimeException('Decoding markdown failed');
+ throw new RuntimeException('Decoding markdown failed');
}
// Parse header.
diff --git a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php
index f045d71..25aee81 100644
--- a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php
index 32d4d29..31aff2c 100644
--- a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php
+++ b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File\Formatter
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -107,7 +107,9 @@ class YamlFormatter extends AbstractFormatter
$saved = @ini_get('yaml.decode_php');
@ini_set('yaml.decode_php', '0');
$decoded = @yaml_parse($data);
- @ini_set('yaml.decode_php', $saved);
+ if ($saved !== false) {
+ @ini_set('yaml.decode_php', $saved);
+ }
if ($decoded !== false) {
return (array) $decoded;
diff --git a/system/src/Grav/Framework/File/IniFile.php b/system/src/Grav/Framework/File/IniFile.php
index 6cda609..0807ee3 100644
--- a/system/src/Grav/Framework/File/IniFile.php
+++ b/system/src/Grav/Framework/File/IniFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,4 +28,13 @@ class IniFile extends DataFile
{
parent::__construct($filepath, $formatter);
}
+
+ /**
+ * @return array
+ */
+ public function load(): array
+ {
+ /** @var array */
+ return parent::load();
+ }
}
diff --git a/system/src/Grav/Framework/File/Interfaces/FileFormatterInterface.php b/system/src/Grav/Framework/File/Interfaces/FileFormatterInterface.php
index 49eda4f..78714af 100644
--- a/system/src/Grav/Framework/File/Interfaces/FileFormatterInterface.php
+++ b/system/src/Grav/Framework/File/Interfaces/FileFormatterInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/Interfaces/FileInterface.php b/system/src/Grav/Framework/File/Interfaces/FileInterface.php
index 015b1ad..f2cc288 100644
--- a/system/src/Grav/Framework/File/Interfaces/FileInterface.php
+++ b/system/src/Grav/Framework/File/Interfaces/FileInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/JsonFile.php b/system/src/Grav/Framework/File/JsonFile.php
index f3b0902..7751e84 100644
--- a/system/src/Grav/Framework/File/JsonFile.php
+++ b/system/src/Grav/Framework/File/JsonFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/File/MarkdownFile.php b/system/src/Grav/Framework/File/MarkdownFile.php
index 4ae3aa0..a79d5ce 100644
--- a/system/src/Grav/Framework/File/MarkdownFile.php
+++ b/system/src/Grav/Framework/File/MarkdownFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,4 +28,13 @@ class MarkdownFile extends DataFile
{
parent::__construct($filepath, $formatter);
}
+
+ /**
+ * @return array
+ */
+ public function load(): array
+ {
+ /** @var array */
+ return parent::load();
+ }
}
diff --git a/system/src/Grav/Framework/File/YamlFile.php b/system/src/Grav/Framework/File/YamlFile.php
index 29224ce..c4300ad 100644
--- a/system/src/Grav/Framework/File/YamlFile.php
+++ b/system/src/Grav/Framework/File/YamlFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\File
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -28,4 +28,13 @@ class YamlFile extends DataFile
{
parent::__construct($filepath, $formatter);
}
+
+ /**
+ * @return array
+ */
+ public function load(): array
+ {
+ /** @var array */
+ return parent::load();
+ }
}
diff --git a/system/src/Grav/Framework/Filesystem/Filesystem.php b/system/src/Grav/Framework/Filesystem/Filesystem.php
index 9b077d7..ddbbab0 100644
--- a/system/src/Grav/Framework/Filesystem/Filesystem.php
+++ b/system/src/Grav/Framework/Filesystem/Filesystem.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -15,6 +15,7 @@ use Grav\Framework\Filesystem\Interfaces\FilesystemInterface;
use RuntimeException;
use function count;
use function dirname;
+use function is_array;
use function pathinfo;
/**
@@ -150,7 +151,10 @@ class Filesystem implements FilesystemInterface
*/
public function basename(string $path, ?string $suffix = null): string
{
- return $suffix ? basename($path, $suffix) : basename($path);
+ // Escape path.
+ $path = str_replace(['%2F', '%5C'], '/', rawurlencode($path));
+
+ return rawurldecode($suffix ? basename($path, $suffix) : basename($path));
}
/**
@@ -176,6 +180,7 @@ class Filesystem implements FilesystemInterface
* @param string $path
* @param int $levels
* @return string
+ * @phpstan-param positive-int $levels
*/
public function pathname(string $path, int $levels = 1): string
{
@@ -204,6 +209,7 @@ class Filesystem implements FilesystemInterface
* @param string $path
* @param int $levels
* @return array
+ * @phpstan-param positive-int $levels
*/
protected function dirnameInternal(?string $scheme, string $path, int $levels = 1): array
{
@@ -229,20 +235,30 @@ class Filesystem implements FilesystemInterface
*/
protected function pathinfoInternal(?string $scheme, string $path, ?int $options = null)
{
- if ($options) {
- return pathinfo($path, $options);
+ $path = str_replace(['%2F', '%5C'], ['/', '\\'], rawurlencode($path));
+
+ if (null === $options) {
+ $info = pathinfo($path);
+ } else {
+ $info = pathinfo($path, $options);
}
- $info = pathinfo($path);
+ if (!is_array($info)) {
+ return rawurldecode($info);
+ }
+
+ $info = array_map('rawurldecode', $info);
if (null !== $scheme) {
$info['scheme'] = $scheme;
- $dirname = isset($info['dirname']) && $info['dirname'] !== '.' ? $info['dirname'] : null;
- if (null !== $dirname) {
+ /** @phpstan-ignore-next-line because pathinfo('') doesn't have dirname */
+ $dirname = $info['dirname'] ?? '.';
+
+ if ('' !== $dirname && '.' !== $dirname) {
// In Windows dirname may be using backslashes, fix that.
if (DIRECTORY_SEPARATOR !== '/') {
- $dirname = str_replace('\\', '/', $dirname);
+ $dirname = str_replace(DIRECTORY_SEPARATOR, '/', $dirname);
}
$info['dirname'] = $scheme . '://' . $dirname;
diff --git a/system/src/Grav/Framework/Filesystem/Interfaces/FilesystemInterface.php b/system/src/Grav/Framework/Filesystem/Interfaces/FilesystemInterface.php
index 0e280a8..4006c8f 100644
--- a/system/src/Grav/Framework/Filesystem/Interfaces/FilesystemInterface.php
+++ b/system/src/Grav/Framework/Filesystem/Interfaces/FilesystemInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Filesystem
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -31,6 +31,7 @@ interface FilesystemInterface
* @param int $levels The number of parent directories to go up (>= 1).
* @return string Returns parent path.
* @throws RuntimeException
+ * @phpstan-param positive-int $levels
* @api
*/
public function parent(string $path, int $levels = 1): string;
@@ -46,7 +47,7 @@ interface FilesystemInterface
public function normalize(string $path): string;
/**
- * Returns filename component of path.
+ * Unicode-safe and stream-safe `\basename()` replacement.
*
* @param string $path A filename or path, does not need to exist as a file.
* @param string|null $suffix If the filename ends in suffix this will also be cut off.
@@ -56,7 +57,7 @@ interface FilesystemInterface
public function basename(string $path, ?string $suffix = null): string;
/**
- * Stream-safe `\dirname()` replacement.
+ * Unicode-safe and stream-safe `\dirname()` replacement.
*
* @see http://php.net/manual/en/function.dirname.php
*
@@ -64,12 +65,13 @@ interface FilesystemInterface
* @param int $levels The number of parent directories to go up (>= 1).
* @return string Returns path to the directory.
* @throws RuntimeException
+ * @phpstan-param positive-int $levels
* @api
*/
public function dirname(string $path, int $levels = 1): string;
/**
- * Stream-safe `\pathinfo()` replacement.
+ * Unicode-safe and stream-safe `\pathinfo()` replacement.
*
* @see http://php.net/manual/en/function.pathinfo.php
*
diff --git a/system/src/Grav/Framework/Flex/Flex.php b/system/src/Grav/Framework/Flex/Flex.php
index ce28521..4d662d1 100644
--- a/system/src/Grav/Framework/Flex/Flex.php
+++ b/system/src/Grav/Framework/Flex/Flex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -62,7 +62,7 @@ class Flex implements FlexInterface
*/
public function addDirectoryType(string $type, string $blueprint, array $config = [])
{
- $config = array_replace_recursive(['enabled' => true], $this->config ?? [], $config);
+ $config = array_replace_recursive(['enabled' => true], $this->config, $config);
$this->types[$type] = new FlexDirectory($type, $blueprint, $config);
@@ -123,6 +123,7 @@ class Flex implements FlexInterface
* @param array|null $keys
* @param string|null $keyField
* @return FlexCollectionInterface|null
+ * @phpstan-return FlexCollectionInterface|null
*/
public function getCollection(string $type, array $keys = null, string $keyField = null): ?FlexCollectionInterface
{
@@ -137,11 +138,12 @@ class Flex implements FlexInterface
* collection_class: Class to be used to create the collection. Defaults to ObjectCollection.
* @return FlexCollectionInterface
* @throws RuntimeException
+ * @phpstan-return FlexCollectionInterface
*/
public function getMixedCollection(array $keys, array $options = []): FlexCollectionInterface
{
$collectionClass = $options['collection_class'] ?? ObjectCollection::class;
- if (!class_exists($collectionClass)) {
+ if (!is_a($collectionClass, FlexCollectionInterface::class, true)) {
throw new RuntimeException(sprintf('Cannot create collection: Class %s does not exist', $collectionClass));
}
@@ -231,7 +233,7 @@ class Flex implements FlexInterface
// Use the original key ordering.
if (!$guessed) {
- $list = array_replace(array_fill_keys($keys, null), $list) ?? [];
+ $list = array_replace(array_fill_keys($keys, null), $list);
} else {
// We have mixed keys, we need to map flex keys back to storage keys.
$results = [];
diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php
index 54e0665..186c60a 100644
--- a/system/src/Grav/Framework/Flex/FlexCollection.php
+++ b/system/src/Grav/Framework/Flex/FlexCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -19,6 +19,7 @@ use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\Utils;
use Grav\Framework\Cache\CacheInterface;
use Grav\Framework\ContentBlock\HtmlBlock;
+use Grav\Framework\Flex\Interfaces\FlexIndexInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use Grav\Framework\Object\ObjectCollection;
use Grav\Framework\Flex\Interfaces\FlexCollectionInterface;
@@ -47,7 +48,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
private $_flexDirectory;
/** @var string */
- private $_keyField;
+ private $_keyField = 'storage_key';
/**
* Get list of cached methods.
@@ -124,6 +125,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
*/
public function getFlexFeatures(): array
{
+ /** @var array $implements */
$implements = class_implements($this);
$list = [];
@@ -152,7 +154,11 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
arsort($matching, SORT_NUMERIC);
}
- return $this->select(array_keys($matching));
+ /** @var string[] $array */
+ $array = array_keys($matching);
+
+ /** @phpstan-var static */
+ return $this->select($array);
}
/**
@@ -163,7 +169,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
{
$criteria = Criteria::create()->orderBy($order);
- /** @var FlexCollectionInterface $matching */
+ /** @phpstan-var FlexCollectionInterface $matching */
$matching = $this->matching($criteria);
return $matching;
@@ -171,7 +177,8 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
/**
* @param array $filters
- * @return FlexCollectionInterface|Collection
+ * @return static
+ * @phpstan-return static
*/
public function filterBy(array $filters)
{
@@ -182,6 +189,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
$criteria->andWhere($expr->eq($key, $value));
}
+ /** @phpstan-var static */
return $this->matching($criteria);
}
@@ -336,6 +344,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
*/
public function getIndex()
{
+ /** @phpstan-var FlexIndexInterface */
return $this->getFlexDirectory()->getIndex($this->getKeys(), $this->getKeyField());
}
@@ -460,7 +469,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
* @param string $key
* @return array
*/
- public function getMetaData(string $key): array
+ public function getMetaData($key): array
{
$object = $this->get($key);
@@ -481,7 +490,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
*/
public function getKeyField(): string
{
- return $this->_keyField ?? 'storage_key';
+ return $this->_keyField;
}
/**
@@ -496,13 +505,18 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
$list = $this->call('isAuthorized', [$action, $scope, $user]);
$list = array_filter($list);
- return $this->select(array_keys($list));
+ /** @var string[] $keys */
+ $keys = array_keys($list);
+
+ /** @phpstan-var static */
+ return $this->select($keys);
}
/**
* @param string $value
* @param string $field
- * @return T|null
+ * @return FlexObjectInterface|null
+ * @phpstan-return T|null
*/
public function find($value, $field = 'id')
{
@@ -520,6 +534,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
$elements = [];
@@ -538,6 +553,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php
index 29f1490..f96633b 100644
--- a/system/src/Grav/Framework/Flex/FlexDirectory.php
+++ b/system/src/Grav/Framework/Flex/FlexDirectory.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -21,7 +21,7 @@ use Grav\Common\Utils;
use Grav\Framework\Cache\Adapter\DoctrineCache;
use Grav\Framework\Cache\Adapter\MemoryCache;
use Grav\Framework\Cache\CacheInterface;
-use Grav\Framework\Flex\Interfaces\FlexAuthorizeInterface;
+use Grav\Framework\Filesystem\Filesystem;
use Grav\Framework\Flex\Interfaces\FlexCollectionInterface;
use Grav\Framework\Flex\Interfaces\FlexDirectoryInterface;
use Grav\Framework\Flex\Interfaces\FlexFormInterface;
@@ -45,7 +45,6 @@ use function is_callable;
/**
* Class FlexDirectory
* @package Grav\Framework\Flex
- * @template T
*/
class FlexDirectory implements FlexDirectoryInterface
{
@@ -57,9 +56,15 @@ class FlexDirectory implements FlexDirectoryInterface
protected $blueprint_file;
/** @var Blueprint[] */
protected $blueprints;
- /** @var FlexIndexInterface[] */
+ /**
+ * @var FlexIndexInterface[]
+ * @phpstan-var FlexIndexInterface[]
+ */
protected $indexes = [];
- /** @var FlexCollectionInterface|null */
+ /**
+ * @var FlexCollectionInterface|null
+ * @phpstan-var FlexCollectionInterface|null
+ */
protected $collection;
/** @var bool */
protected $enabled;
@@ -213,8 +218,17 @@ class FlexDirectory implements FlexDirectoryInterface
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
- /** @var string $filename Filename is always string */
- $filename = $locator->findResource($this->getDirectoryConfigUri($name), true, true);
+
+ $filename = $this->getDirectoryConfigUri($name);
+ if (file_exists($filename)) {
+ $filename = $locator->findResource($filename, true);
+ } else {
+ $filesystem = Filesystem::getInstance();
+ $dirname = $filesystem->dirname($filename);
+ $basename = $filesystem->basename($filename);
+ $dirname = $locator->findResource($dirname, true) ?: $locator->findResource($dirname, true, true);
+ $filename = "{$dirname}/{$basename}";
+ }
$file = YamlFile::instance($filename);
if (!empty($data)) {
@@ -318,7 +332,7 @@ class FlexDirectory implements FlexDirectoryInterface
* @param array|null $keys Array of keys.
* @param string|null $keyField Field to be used as the key.
* @return FlexCollectionInterface
- * @phpstan-return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function getCollection(array $keys = null, string $keyField = null): FlexCollectionInterface
{
@@ -345,6 +359,7 @@ class FlexDirectory implements FlexDirectoryInterface
* @param array|null $keys Array of keys.
* @param string|null $keyField Field to be used as the key.
* @return FlexIndexInterface
+ * @phpstan-return FlexIndexInterface
*/
public function getIndex(array $keys = null, string $keyField = null): FlexIndexInterface
{
@@ -353,7 +368,7 @@ class FlexDirectory implements FlexDirectoryInterface
$index = clone $index;
if (null !== $keys) {
- /** @var FlexIndexInterface $index */
+ /** @var FlexIndexInterface $index */
$index = $index->select($keys);
}
@@ -487,8 +502,11 @@ class FlexDirectory implements FlexDirectoryInterface
*/
public function createObject(array $data, string $key = '', bool $validate = false): FlexObjectInterface
{
- /** @var string|FlexObjectInterface $className */
+ /** @phpstan-var class-string $className */
$className = $this->objectClassName ?: $this->getObjectClass();
+ if (!is_a($className, FlexObjectInterface::class, true)) {
+ throw new \RuntimeException('Bad object class: ' . $className);
+ }
return new $className($data, $key, $this, $validate);
}
@@ -497,11 +515,15 @@ class FlexDirectory implements FlexDirectoryInterface
* @param array $entries
* @param string|null $keyField
* @return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function createCollection(array $entries, string $keyField = null): FlexCollectionInterface
{
- /** @var string|FlexCollectionInterface $className */
+ /** phpstan-var class-string $className */
$className = $this->collectionClassName ?: $this->getCollectionClass();
+ if (!is_a($className, FlexCollectionInterface::class, true)) {
+ throw new \RuntimeException('Bad collection class: ' . $className);
+ }
return $className::createFromArray($entries, $this, $keyField);
}
@@ -510,11 +532,15 @@ class FlexDirectory implements FlexDirectoryInterface
* @param array $entries
* @param string|null $keyField
* @return FlexIndexInterface
+ * @phpstan-return FlexIndexInterface
*/
public function createIndex(array $entries, string $keyField = null): FlexIndexInterface
{
- /** @var string|FlexIndexInterface $className */
+ /** @phpstan-var class-string $className */
$className = $this->indexClassName ?: $this->getIndexClass();
+ if (!is_a($className, FlexIndexInterface::class, true)) {
+ throw new \RuntimeException('Bad index class: ' . $className);
+ }
return $className::createFromArray($entries, $this, $keyField);
}
@@ -560,6 +586,7 @@ class FlexDirectory implements FlexDirectoryInterface
* @param array $entries
* @param string|null $keyField
* @return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function loadCollection(array $entries, string $keyField = null): FlexCollectionInterface
{
@@ -889,12 +916,17 @@ class FlexDirectory implements FlexDirectoryInterface
$className = $storage['class'] ?? SimpleStorage::class;
$options = $storage['options'] ?? [];
+ if (!is_a($className, FlexStorageInterface::class, true)) {
+ throw new \RuntimeException('Bad storage class: ' . $className);
+ }
+
return new $className($options);
}
/**
* @param string $keyField
* @return FlexIndexInterface
+ * @phpstan-return FlexIndexInterface
*/
protected function loadIndex(string $keyField): FlexIndexInterface
{
@@ -924,7 +956,7 @@ class FlexDirectory implements FlexDirectoryInterface
}
if (!is_array($keys)) {
- /** @var string|FlexIndexInterface $className */
+ /** @phpstan-var class-string $className */
$className = $this->getIndexClass();
$keys = $className::loadEntriesFromStorage($storage);
if (!$cache instanceof MemoryCache) {
@@ -946,7 +978,7 @@ class FlexDirectory implements FlexDirectoryInterface
// We need to do this in two steps as orderBy() calls loadIndex() again and we do not want infinite loop.
$this->indexes['storage_key'] = $index = $this->createIndex($keys, 'storage_key');
if ($ordering) {
- /** @var FlexCollectionInterface $collection */
+ /** @var FlexCollectionInterface $collection */
$collection = $this->indexes['storage_key']->orderBy($ordering);
$this->indexes['storage_key'] = $index = $collection->getIndex();
}
@@ -1035,7 +1067,9 @@ class FlexDirectory implements FlexDirectoryInterface
$newKey = $object->getStorageKey();
if ($oldKey !== $newKey) {
- $object->triggerEvent('move');
+ if (method_exists($object, 'triggerEvent')) {
+ $object->triggerEvent('move');
+ }
$storage->renameRow($oldKey, $newKey);
// TODO: media support.
}
diff --git a/system/src/Grav/Framework/Flex/FlexDirectoryForm.php b/system/src/Grav/Framework/Flex/FlexDirectoryForm.php
index 8d608fd..709f418 100644
--- a/system/src/Grav/Framework/Flex/FlexDirectoryForm.php
+++ b/system/src/Grav/Framework/Flex/FlexDirectoryForm.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -358,6 +358,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __get($name)
{
$method = "get{$name}";
@@ -375,6 +376,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value)
{
$method = "set{$name}";
@@ -387,6 +389,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($name)
{
$method = "get{$name}";
@@ -403,6 +406,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($name)
{
}
@@ -493,6 +497,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* Filter validated data.
*
* @param ArrayAccess|Data|null $data
+ * @phpstan-param ArrayAccess|Data|null $data
*/
protected function filterData($data = null): void
{
diff --git a/system/src/Grav/Framework/Flex/FlexForm.php b/system/src/Grav/Framework/Flex/FlexForm.php
index d25cefc..a1263f6 100644
--- a/system/src/Grav/Framework/Flex/FlexForm.php
+++ b/system/src/Grav/Framework/Flex/FlexForm.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -444,6 +444,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __get($name)
{
$method = "get{$name}";
@@ -461,6 +462,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value)
{
$method = "set{$name}";
@@ -473,6 +475,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($name)
{
$method = "get{$name}";
@@ -489,6 +492,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($name)
{
}
@@ -594,6 +598,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
*
* @param ArrayAccess|Data|null $data
* @return void
+ * @phpstan-param ArrayAccess|Data|null $data
*/
protected function filterData($data = null): void
{
diff --git a/system/src/Grav/Framework/Flex/FlexFormFlash.php b/system/src/Grav/Framework/Flex/FlexFormFlash.php
index feb7a9e..3f52cdb 100644
--- a/system/src/Grav/Framework/Flex/FlexFormFlash.php
+++ b/system/src/Grav/Framework/Flex/FlexFormFlash.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php
index 3ce0a46..54438af 100644
--- a/system/src/Grav/Framework/Flex/FlexIndex.php
+++ b/system/src/Grav/Framework/Flex/FlexIndex.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -11,6 +11,7 @@ namespace Grav\Framework\Flex;
use Exception;
use Grav\Common\Debugger;
+use Grav\Common\File\CompiledJsonFile;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\Grav;
use Grav\Common\Inflector;
@@ -39,14 +40,14 @@ use function in_array;
* @implements FlexIndexInterface
* @mixin C
*/
-class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexIndexInterface
+class FlexIndex extends ObjectIndex implements FlexIndexInterface
{
const VERSION = 1;
/** @var FlexDirectory|null */
private $_flexDirectory;
/** @var string */
- private $_keyField;
+ private $_keyField = 'storage_key';
/** @var array */
private $_indexKeys;
@@ -117,6 +118,14 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
$this->setKeyField(null);
}
+ /**
+ * @return string
+ */
+ public function getKey()
+ {
+ return $this->_key ?: $this->getFlexType() . '@@' . spl_object_hash($this);
+ }
+
/**
* {@inheritdoc}
* @see FlexCommonInterface::hasFlexFeature()
@@ -132,6 +141,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
public function getFlexFeatures(): array
{
+ /** @var array $implements */
$implements = class_implements($this->getFlexDirectory()->getCollectionClass());
$list = [];
@@ -164,7 +174,6 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
return $this->orderBy($orderings);
}
-
/**
* {@inheritdoc}
* @see FlexCollectionInterface::filterBy()
@@ -353,7 +362,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
public function getKeyField(): string
{
- return $this->_keyField ?? 'storage_key';
+ return $this->_keyField;
}
/**
@@ -416,7 +425,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
$previous = $search;
}
- return $this->createFrom(array_replace($previous ?? [], $this->getEntries()) ?? []);
+ return $this->createFrom(array_replace($previous ?? [], $this->getEntries()));
}
/**
@@ -432,12 +441,13 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
* @param array $arguments
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __call($name, $arguments)
{
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
- /** @var FlexCollection $className */
+ /** @phpstan-var class-string $className */
$className = $this->getFlexDirectory()->getCollectionClass();
$cachedMethods = $className::getCachedMethods();
@@ -492,9 +502,13 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
}
} else {
$collection = $this->loadCollection();
- $result = $collection->{$name}(...$arguments);
- if (!isset($cachedMethods[$name])) {
- $debugger->addMessage("Call '{$flexType}:{$name}()' isn't cached", 'debug');
+ if (\is_callable([$collection, $name])) {
+ $result = $collection->{$name}(...$arguments);
+ if (!isset($cachedMethods[$name])) {
+ $debugger->addMessage("Call '{$flexType}:{$name}()' isn't cached", 'debug');
+ }
+ } else {
+ $result = null;
}
}
@@ -522,6 +536,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
@@ -607,9 +622,11 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
* @param string $key
* @param mixed $value
* @return ObjectInterface|null
+ * @phpstan-return T|null
*/
protected function loadElement($key, $value): ?ObjectInterface
{
+ /** @phpstan-var T[] $objects */
$objects = $this->getFlexDirectory()->loadObjects([$key => $value]);
return $objects ? reset($objects): null;
@@ -618,10 +635,14 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
/**
* @param array|null $entries
* @return ObjectInterface[]
+ * @phpstan-return T[]
*/
protected function loadElements(array $entries = null): array
{
- return $this->getFlexDirectory()->loadObjects($entries ?? $this->getEntries());
+ /** @phpstan-var T[] $objects */
+ $objects = $this->getFlexDirectory()->loadObjects($entries ?? $this->getEntries());
+
+ return $objects;
}
/**
@@ -824,7 +845,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
/**
* @param FlexStorageInterface $storage
- * @return CompiledYamlFile|null
+ * @return CompiledYamlFile|CompiledJsonFile|null
*/
protected static function getIndexFile(FlexStorageInterface $storage)
{
diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php
index ac51b34..afc656c 100644
--- a/system/src/Grav/Framework/Flex/FlexObject.php
+++ b/system/src/Grav/Framework/Flex/FlexObject.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -69,13 +69,13 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
private $_forms = [];
/** @var Blueprint[] */
private $_blueprint = [];
- /** @var array */
+ /** @var array|null */
private $_meta;
- /** @var array */
+ /** @var array|null */
protected $_original;
- /** @var string */
+ /** @var string|null */
protected $storage_key;
- /** @var int */
+ /** @var int|null */
protected $storage_timestamp;
/**
@@ -163,6 +163,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*/
public function getFlexFeatures(): array
{
+ /** @var array $implements */
$implements = class_implements($this);
$list = [];
@@ -656,6 +657,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->getElements();
@@ -775,7 +777,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
$value = reset($result);
$meta = $value['__META'] ?? null;
if ($meta) {
- /** @var FlexIndex $indexClass */
+ /** @phpstan-var class-string $indexClass */
$indexClass = $this->getFlexDirectory()->getIndexClass();
$indexClass::updateObjectMeta($meta, $value, $storage);
$this->_meta = $meta;
@@ -887,8 +889,8 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
public function getDefaultValue(string $name, string $separator = null)
{
$separator = $separator ?: '.';
- $path = explode($separator, $name) ?: [];
- $offset = array_shift($path) ?? '';
+ $path = explode($separator, $name);
+ $offset = array_shift($path);
$current = $this->getDefaultValues();
@@ -950,6 +952,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->getFlexKey();
@@ -958,6 +961,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
@@ -973,6 +977,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/**
* Clone object.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
// Allows future compatibility as parent::__clone() works.
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexAuthorizeInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexAuthorizeInterface.php
index 102dbf4..c1025a4 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexAuthorizeInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexAuthorizeInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php
index 16be3d5..d14b69f 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -140,5 +140,5 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI
* @param string $key Key.
* @return array
*/
- public function getMetaData(string $key): array;
+ public function getMetaData($key): array;
}
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexCommonInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexCommonInterface.php
index ed045e2..7c1975f 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexCommonInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexCommonInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryFormInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryFormInterface.php
index df6f7d6..203c766 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryFormInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryFormInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryInterface.php
index 07eab01..a77df95 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexDirectoryInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -105,6 +105,7 @@ interface FlexDirectoryInterface extends FlexAuthorizeInterface
* @param array|null $keys Array of keys.
* @param string|null $keyField Field to be used as the key.
* @return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function getCollection(array $keys = null, string $keyField = null): FlexCollectionInterface;
@@ -116,6 +117,7 @@ interface FlexDirectoryInterface extends FlexAuthorizeInterface
* @param array|null $keys Array of keys.
* @param string|null $keyField Field to be used as the key.
* @return FlexIndexInterface
+ * @phpstan-return FlexIndexInterface
*/
public function getIndex(array $keys = null, string $keyField = null): FlexIndexInterface;
@@ -170,6 +172,7 @@ interface FlexDirectoryInterface extends FlexAuthorizeInterface
* @param array $entries
* @param string|null $keyField
* @return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function createCollection(array $entries, string $keyField = null): FlexCollectionInterface;
@@ -177,6 +180,7 @@ interface FlexDirectoryInterface extends FlexAuthorizeInterface
* @param array $entries
* @param string|null $keyField
* @return FlexIndexInterface
+ * @phpstan-return FlexIndexInterface
*/
public function createIndex(array $entries, string $keyField = null): FlexIndexInterface;
@@ -199,6 +203,7 @@ interface FlexDirectoryInterface extends FlexAuthorizeInterface
* @param array $entries
* @param string|null $keyField
* @return FlexCollectionInterface
+ * @phpstan-return FlexCollectionInterface
*/
public function loadCollection(array $entries, string $keyField = null): FlexCollectionInterface;
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexFormInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexFormInterface.php
index 32dab19..ba9996a 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexFormInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexFormInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -43,4 +43,9 @@ interface FlexFormInterface extends Serializable, FormInterface
* @return Route|null Returns Route object or null if file uploads are not enabled.
*/
public function getFileDeleteAjaxRoute($field, $filename);
+
+// /**
+// * @return FlexObjectInterface
+// */
+// public function getObject();
}
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php
index 71dd727..d8f8ba3 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexInterface.php
index 3c5a103..f1376a5 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -59,6 +59,7 @@ interface FlexInterface extends Countable
* @param array|null $keys
* @param string|null $keyField
* @return FlexCollectionInterface|null
+ * @phpstan-return FlexCollectionInterface|null
*/
public function getCollection(string $type, array $keys = null, string $keyField = null): ?FlexCollectionInterface;
@@ -68,6 +69,7 @@ interface FlexInterface extends Countable
* collection_class: Class to be used to create the collection. Defaults to ObjectCollection.
* @return FlexCollectionInterface
* @throws RuntimeException
+ * @phpstan-return FlexCollectionInterface
*/
public function getMixedCollection(array $keys, array $options = []): FlexCollectionInterface;
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexObjectFormInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexObjectFormInterface.php
index 044ee61..190a963 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexObjectFormInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexObjectFormInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexObjectInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexObjectInterface.php
index a1e3e3b..d02bc8b 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexObjectInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexObjectInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -23,6 +23,7 @@ use RuntimeException;
/**
* Defines Flex Objects.
*
+ * @extends ArrayAccess
* @used-by \Grav\Framework\Flex\FlexObject
* @since 1.6
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexStorageInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexStorageInterface.php
index 08c4335..4209924 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexStorageInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexStorageInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexTranslateInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexTranslateInterface.php
index 28e4888..8df11fa 100644
--- a/system/src/Grav/Framework/Flex/Interfaces/FlexTranslateInterface.php
+++ b/system/src/Grav/Framework/Flex/Interfaces/FlexTranslateInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php b/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php
index 9482568..5901557 100644
--- a/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php
+++ b/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -13,6 +13,7 @@ namespace Grav\Framework\Flex\Pages;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Framework\Flex\FlexCollection;
+use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use function array_search;
use function assert;
use function is_int;
@@ -20,7 +21,7 @@ use function is_int;
/**
* Class FlexPageCollection
* @package Grav\Plugin\FlexObjects\Types\FlexPages
- * @template T of \Grav\Framework\Flex\Interfaces\FlexObjectInterface
+ * @template T of FlexObjectInterface
* @extends FlexCollection
*/
class FlexPageCollection extends FlexCollection
@@ -56,8 +57,10 @@ class FlexPageCollection extends FlexCollection
*/
public function withPublished(bool $bool = true)
{
+ /** @var string[] $list */
$list = array_keys(array_filter($this->call('isPublished', [$bool])));
+ /** @phpstan-var static */
return $this->select($list);
}
@@ -68,8 +71,10 @@ class FlexPageCollection extends FlexCollection
*/
public function withVisible(bool $bool = true)
{
+ /** @var string[] $list */
$list = array_keys(array_filter($this->call('isVisible', [$bool])));
+ /** @phpstan-var static */
return $this->select($list);
}
@@ -80,8 +85,10 @@ class FlexPageCollection extends FlexCollection
*/
public function withRoutable(bool $bool = true)
{
+ /** @var string[] $list */
$list = array_keys(array_filter($this->call('isRoutable', [$bool])));
+ /** @phpstan-var static */
return $this->select($list);
}
@@ -148,9 +155,10 @@ class FlexPageCollection extends FlexCollection
public function adjacentSibling($path, $direction = 1)
{
$keys = $this->getKeys();
+ $direction = (int)$direction;
$pos = array_search($path, $keys, true);
- if ($pos !== false) {
+ if (is_int($pos)) {
$pos += $direction;
if (isset($keys[$pos])) {
return $this[$keys[$pos]];
@@ -170,7 +178,7 @@ class FlexPageCollection extends FlexCollection
{
$pos = array_search($path, $this->getKeys(), true);
- return $pos !== false ? $pos : null;
+ return is_int($pos) ? $pos : null;
}
/**
@@ -184,7 +192,6 @@ class FlexPageCollection extends FlexCollection
$keys = $collection->getStorageKeys();
// Assign next free order.
- /** @var FlexPageObject|null $last */
$last = null;
$order = 0;
foreach ($keys as $folder => $key) {
@@ -196,8 +203,9 @@ class FlexPageCollection extends FlexCollection
}
}
+ /** @var FlexPageObject|null $last */
$last = $collection[$last];
- return sprintf('%d.', $last ? $last->value('order') + 1 : 1);
+ return sprintf('%d.', $last ? $last->getFormValue('order') + 1 : 1);
}
}
diff --git a/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php b/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php
index 904d1f6..5bb5517 100644
--- a/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php
+++ b/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Pages/FlexPageObject.php b/system/src/Grav/Framework/Flex/Pages/FlexPageObject.php
index ebc26b4..e700424 100644
--- a/system/src/Grav/Framework/Flex/Pages/FlexPageObject.php
+++ b/system/src/Grav/Framework/Flex/Pages/FlexPageObject.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -55,6 +55,7 @@ class FlexPageObject extends FlexObject implements PageInterface, FlexTranslateI
/**
* Clone page.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
parent::__clone();
diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageAuthorsTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageAuthorsTrait.php
index 5d3e968..d0934e1 100644
--- a/system/src/Grav/Framework/Flex/Pages/Traits/PageAuthorsTrait.php
+++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageAuthorsTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php
index 6aff732..43dfee1 100644
--- a/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php
+++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -75,13 +75,13 @@ trait PageContentTrait
'template' => 'template',
];
- /** @var object */
+ /** @var object|null */
protected $header;
- /** @var string */
+ /** @var string|null */
protected $_summary;
- /** @var string */
+ /** @var string|null */
protected $_content;
/**
@@ -100,6 +100,7 @@ trait PageContentTrait
/**
* @inheritdoc
+ * @return Header
*/
public function header($var = null)
{
@@ -288,7 +289,7 @@ trait PageContentTrait
'process',
$var,
function ($value) {
- $value = array_replace(Grav::instance()['config']->get('system.pages.process', []), is_array($value) ? $value : []) ?? [];
+ $value = array_replace(Grav::instance()['config']->get('system.pages.process', []), is_array($value) ? $value : []);
foreach ($value as $process => $status) {
$value[$process] = (bool)$status;
}
@@ -664,6 +665,7 @@ trait PageContentTrait
*/
protected function processContent($content): string
{
+ $content = is_string($content) ? $content : '';
$grav = Grav::instance();
/** @var Config $config */
@@ -676,7 +678,6 @@ trait PageContentTrait
$twig_first = $this->getNestedProperty('header.twig_first') ?? $config->get('system.pages.twig_first', false);
$never_cache_twig = $this->getNestedProperty('header.never_cache_twig') ?? $config->get('system.pages.never_cache_twig', false);
- $cached = null;
if ($cache_enable) {
$cache = $this->getCache('render');
$key = md5($this->getCacheKey() . '-content');
@@ -688,12 +689,10 @@ trait PageContentTrait
if ($process_twig && $never_cache_twig) {
$this->_content = $this->processTwig($this->_content);
}
- } else {
- $cached = null;
}
}
- if (!$cached) {
+ if (null === $this->_content) {
$markdown_options = [];
if ($process_markdown) {
// Build markdown options.
@@ -746,6 +745,7 @@ trait PageContentTrait
}
if ($process_twig) {
+ \assert(is_string($this->_content));
$this->_content = $this->processTwig($this->_content);
}
}
@@ -755,6 +755,8 @@ trait PageContentTrait
}
}
+ \assert(is_string($this->_content));
+
// Handle summary divider
$delimiter = $config->get('site.summary.delimiter', '===');
$divider_pos = mb_strpos($this->_content, "{$delimiter}
");
diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php
index 6453bcf..d753803 100644
--- a/system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php
+++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -17,13 +17,12 @@ use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Page\Pages;
use Grav\Common\Utils;
use Grav\Common\Yaml;
-use Grav\Framework\Cache\CacheInterface;
use Grav\Framework\File\Formatter\MarkdownFormatter;
use Grav\Framework\File\Formatter\YamlFormatter;
use Grav\Framework\Filesystem\Filesystem;
-use Grav\Framework\Flex\FlexDirectory;
use Grav\Framework\Flex\Interfaces\FlexCollectionInterface;
use Grav\Framework\Flex\Interfaces\FlexIndexInterface;
+use Grav\Framework\Flex\Pages\FlexPageCollection;
use Grav\Framework\Flex\Pages\FlexPageIndex;
use Grav\Framework\Flex\Pages\FlexPageObject;
use InvalidArgumentException;
@@ -300,7 +299,7 @@ trait PageLegacyTrait
$parentStorageKey = ltrim($filesystem->dirname("/{$this->getMasterKey()}"), '/');
- /** @var FlexPageIndex $index */
+ /** @var FlexPageIndex> $index */
$index = $this->getFlexDirectory()->getIndex();
if ($parent) {
@@ -323,8 +322,9 @@ trait PageLegacyTrait
if ($this instanceof FlexPageObject) {
$key = trim($parentKey . '/' . $this->folder(), '/');
$key = preg_replace(static::PAGE_ORDER_PREFIX_REGEX, '', $key);
+ \assert(is_string($key));
} else {
- $key = trim($parentKey . '/' . basename($this->getKey()), '/');
+ $key = trim($parentKey . '/' . Utils::basename($this->getKey()), '/');
}
if ($index->containsKey($key)) {
@@ -336,7 +336,7 @@ trait PageLegacyTrait
} while ($index->containsKey($test));
$key = $test;
}
- $folder = basename($key);
+ $folder = Utils::basename($key);
// Get the folder name.
$order = $this->getProperty('order');
@@ -539,7 +539,7 @@ trait PageLegacyTrait
if ($language) {
$language = '.' . $language;
}
- $format = '.' . ($this->getProperty('format') ?? pathinfo($this->name(), PATHINFO_EXTENSION));
+ $format = '.' . ($this->getProperty('format') ?? Utils::pathinfo($this->name(), PATHINFO_EXTENSION));
return $language . $format;
}
diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php
index 90773cd..c4c8cd7 100644
--- a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php
+++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -15,10 +15,10 @@ use Grav\Common\Page\Interfaces\PageCollectionInterface;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Page\Pages;
use Grav\Common\Uri;
+use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use RuntimeException;
-use function dirname;
use function is_string;
/**
@@ -375,7 +375,7 @@ trait PageRoutableTrait
$value = $this->getMasterKey() ?: $this->getKey();
}
- return basename($value) ?: null;
+ return Utils::basename($value) ?: null;
}
);
}
diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php
index 877fec1..4bec685 100644
--- a/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php
+++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -26,6 +26,14 @@ trait PageTranslateTrait
/** @var PageInterface[] */
private $_translations = [];
+ /**
+ * @return bool
+ */
+ public function translated(): bool
+ {
+ return (bool)$this->translatedLanguages(true);
+ }
+
/**
* @param string|null $languageCode
* @param bool|null $fallback
diff --git a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php
index 1934f50..ee04c51 100644
--- a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php
+++ b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -127,6 +127,10 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface
$formatterClassName = $formatter['class'] ?? JsonFormatter::class;
$formatterOptions = $formatter['options'] ?? [];
+ if (!is_a($formatterClassName, FileFormatterInterface::class, true)) {
+ throw new \InvalidArgumentException('Bad Data Formatter');
+ }
+
$this->dataFormatter = new $formatterClassName($formatterOptions);
}
diff --git a/system/src/Grav/Framework/Flex/Storage/FileStorage.php b/system/src/Grav/Framework/Flex/Storage/FileStorage.php
index eabd658..1864439 100644
--- a/system/src/Grav/Framework/Flex/Storage/FileStorage.php
+++ b/system/src/Grav/Framework/Flex/Storage/FileStorage.php
@@ -5,13 +5,14 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Flex\Storage;
use FilesystemIterator;
+use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexStorageInterface;
use RuntimeException;
use SplFileInfo;
@@ -125,7 +126,7 @@ class FileStorage extends FolderStorage
*/
protected function getKeyFromPath(string $path): string
{
- return basename($path, $this->dataFormatter->getDefaultFileExtension());
+ return Utils::basename($path, $this->dataFormatter->getDefaultFileExtension());
}
/**
diff --git a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php
index b2b9533..600e989 100644
--- a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php
+++ b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -352,7 +352,7 @@ class FolderStorage extends AbstractFilesystemStorage
*/
protected function getKeyFromPath(string $path): string
{
- return basename($path);
+ return Utils::basename($path);
}
/**
@@ -688,7 +688,7 @@ class FolderStorage extends AbstractFilesystemStorage
$pattern .= '/{FILE}{EXT}';
} else {
$filesystem = Filesystem::getInstance(true);
- $this->dataFile = basename($pattern, $extension);
+ $this->dataFile = Utils::basename($pattern, $extension);
$pattern = $filesystem->dirname($pattern) . '/{FILE}{EXT}';
}
}
diff --git a/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php b/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php
index 6faac9d..73e2b06 100644
--- a/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php
+++ b/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -13,6 +13,7 @@ namespace Grav\Framework\Flex\Storage;
use Grav\Common\Data\Data;
use Grav\Common\Filesystem\Folder;
+use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
use InvalidArgumentException;
use LogicException;
@@ -30,7 +31,7 @@ class SimpleStorage extends AbstractFilesystemStorage
protected $dataFolder;
/** @var string */
protected $dataPattern;
- /** @var string */
+ /** @var string|null */
protected $prefix;
/** @var array|null */
protected $data;
@@ -53,9 +54,9 @@ class SimpleStorage extends AbstractFilesystemStorage
$filesystem = Filesystem::getInstance(true);
$extension = $this->dataFormatter->getDefaultFileExtension();
- $pattern = basename($options['folder']);
+ $pattern = Utils::basename($options['folder']);
- $this->dataPattern = basename($pattern, $extension) . $extension;
+ $this->dataPattern = Utils::basename($pattern, $extension) . $extension;
$this->dataFolder = $filesystem->dirname($options['folder']);
$this->keyField = $options['key'] ?? 'storage_key';
$this->keyLen = (int)($options['key_len'] ?? 32);
@@ -432,7 +433,7 @@ class SimpleStorage extends AbstractFilesystemStorage
*/
protected function getKeyFromPath(string $path): string
{
- return basename($path);
+ return Utils::basename($path);
}
/**
diff --git a/system/src/Grav/Framework/Flex/Traits/FlexAuthorizeTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexAuthorizeTrait.php
index 8cbd1d5..ef4c433 100644
--- a/system/src/Grav/Framework/Flex/Traits/FlexAuthorizeTrait.php
+++ b/system/src/Grav/Framework/Flex/Traits/FlexAuthorizeTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php
index dabfe17..ad437eb 100644
--- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php
+++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php
@@ -5,7 +5,7 @@ namespace Grav\Framework\Flex\Traits;
/**
* @package Grav\Framework\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -44,7 +44,7 @@ trait FlexMediaTrait
}
/** @var array */
- protected $_uploads;
+ protected $_uploads = [];
/**
* @return string|null
@@ -119,7 +119,7 @@ trait FlexMediaTrait
// Load settings for the field.
$schema = $this->getBlueprint()->schema();
- $settings = $field && is_object($schema) ? (array)$schema->getProperty($field) : null;
+ $settings = (array)$schema->getProperty($field);
if (!is_array($settings)) {
return null;
}
@@ -165,6 +165,9 @@ trait FlexMediaTrait
return $settings + ['accept' => '*', 'limit' => 1000, 'self' => true];
}
+ /**
+ * @return array
+ */
protected function getMediaFields(): array
{
// Load settings for the field.
@@ -286,6 +289,7 @@ trait FlexMediaTrait
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return parent::__debugInfo() + [
@@ -342,7 +346,7 @@ trait FlexMediaTrait
}
// Calculate path without the retina scaling factor.
- $realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', basename($filepath));
+ $realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', Utils::basename($filepath));
$list[$filename] = [$file, $settings];
@@ -397,11 +401,11 @@ trait FlexMediaTrait
}
/**
- * @return array
+ * @return array
*/
protected function getUpdatedMedia(): array
{
- return $this->_uploads ?? [];
+ return $this->_uploads;
}
/**
@@ -504,7 +508,7 @@ trait FlexMediaTrait
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use Media class that implements MediaUploadInterface instead', E_USER_DEPRECATED);
// Check the file extension.
- $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
+ $extension = strtolower(Utils::pathinfo($filename, PATHINFO_EXTENSION));
$grav = Grav::instance();
diff --git a/system/src/Grav/Framework/Flex/Traits/FlexRelatedDirectoryTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexRelatedDirectoryTrait.php
index 9f7380c..de98359 100644
--- a/system/src/Grav/Framework/Flex/Traits/FlexRelatedDirectoryTrait.php
+++ b/system/src/Grav/Framework/Flex/Traits/FlexRelatedDirectoryTrait.php
@@ -5,15 +5,15 @@ declare(strict_types=1);
/**
* @package Grav\Common\Flex
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Flex\Traits;
-use Grav\Framework\Flex\FlexCollection;
use Grav\Framework\Flex\FlexDirectory;
use Grav\Framework\Flex\Interfaces\FlexCollectionInterface;
+use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use RuntimeException;
use function in_array;
@@ -26,7 +26,7 @@ trait FlexRelatedDirectoryTrait
/**
* @param string $type
* @param string $property
- * @return FlexCollectionInterface
+ * @return FlexCollectionInterface
*/
protected function getCollectionByProperty($type, $property)
{
@@ -34,9 +34,9 @@ trait FlexRelatedDirectoryTrait
$collection = $directory->getCollection();
$list = $this->getNestedProperty($property) ?: [];
- /** @var FlexCollection $collection */
+ /** @var FlexCollectionInterface $collection */
$collection = $collection->filter(static function ($object) use ($list) {
- return in_array($object->id, $list, true);
+ return in_array($object->getKey(), $list, true);
});
return $collection;
diff --git a/system/src/Grav/Framework/Form/FormFlash.php b/system/src/Grav/Framework/Form/FormFlash.php
index 864e992..863eb4a 100644
--- a/system/src/Grav/Framework/Form/FormFlash.php
+++ b/system/src/Grav/Framework/Form/FormFlash.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -343,7 +343,7 @@ class FormFlash implements FormFlashInterface
// Prepare upload data for later save
$data = [
- 'name' => basename($filename),
+ 'name' => Utils::basename($filename),
'type' => Utils::getMimeByLocalFile($filename),
'size' => filesize($filename),
];
diff --git a/system/src/Grav/Framework/Form/FormFlashFile.php b/system/src/Grav/Framework/Form/FormFlashFile.php
index dc510e2..65af544 100644
--- a/system/src/Grav/Framework/Form/FormFlashFile.php
+++ b/system/src/Grav/Framework/Form/FormFlashFile.php
@@ -3,14 +3,17 @@
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Form;
+use Grav\Common\Security;
+use Grav\Common\Utils;
use Grav\Framework\Psr7\Stream;
use InvalidArgumentException;
+use JsonSerializable;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use RuntimeException;
@@ -23,7 +26,7 @@ use function sprintf;
* Class FormFlashFile
* @package Grav\Framework\Form
*/
-class FormFlashFile implements UploadedFileInterface, \JsonSerializable
+class FormFlashFile implements UploadedFileInterface, JsonSerializable
{
/** @var string */
private $field;
@@ -175,11 +178,27 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->upload;
}
+ /**
+ * @return void
+ */
+ public function checkXss(): void
+ {
+ $tmpFile = $this->getTmpFile();
+ $mime = $this->getClientMediaType();
+ if (Utils::contains($mime, 'svg', false)) {
+ $response = Security::detectXssFromSvgFile($tmpFile);
+ if ($response) {
+ throw new RuntimeException(sprintf('SVG file XSS check failed on %s', $response));
+ }
+ }
+ }
+
/**
* @return string|null
*/
@@ -199,6 +218,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
diff --git a/system/src/Grav/Framework/Form/Interfaces/FormFactoryInterface.php b/system/src/Grav/Framework/Form/Interfaces/FormFactoryInterface.php
index d21d4aa..6a85f66 100644
--- a/system/src/Grav/Framework/Form/Interfaces/FormFactoryInterface.php
+++ b/system/src/Grav/Framework/Form/Interfaces/FormFactoryInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Form/Interfaces/FormFlashInterface.php b/system/src/Grav/Framework/Form/Interfaces/FormFlashInterface.php
index d51bd8d..44bee02 100644
--- a/system/src/Grav/Framework/Form/Interfaces/FormFlashInterface.php
+++ b/system/src/Grav/Framework/Form/Interfaces/FormFlashInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Form/Interfaces/FormInterface.php b/system/src/Grav/Framework/Form/Interfaces/FormInterface.php
index 9815646..0edfc42 100644
--- a/system/src/Grav/Framework/Form/Interfaces/FormInterface.php
+++ b/system/src/Grav/Framework/Form/Interfaces/FormInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Form/Traits/FormTrait.php b/system/src/Grav/Framework/Form/Traits/FormTrait.php
index d77a402..710d8b0 100644
--- a/system/src/Grav/Framework/Form/Traits/FormTrait.php
+++ b/system/src/Grav/Framework/Form/Traits/FormTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Form
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -23,6 +23,7 @@ use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\Utils;
use Grav\Framework\Compat\Serializable;
use Grav\Framework\ContentBlock\HtmlBlock;
+use Grav\Framework\Form\FormFlashFile;
use Grav\Framework\Form\Interfaces\FormFlashInterface;
use Grav\Framework\Form\Interfaces\FormInterface;
use Grav\Framework\Session\SessionInterface;
@@ -65,10 +66,10 @@ trait FormTrait
private $sessionid;
/** @var bool */
private $submitted;
- /** @var ArrayAccess|Data|null */
+ /** @var ArrayAccess|Data|null */
private $data;
- /** @var array|UploadedFileInterface[] */
- private $files;
+ /** @var UploadedFileInterface[] */
+ private $files = [];
/** @var FormFlashInterface|null */
private $flash;
/** @var string */
@@ -203,7 +204,7 @@ trait FormTrait
*/
public function getFiles(): array
{
- return $this->files ?? [];
+ return $this->files;
}
/**
@@ -221,8 +222,8 @@ trait FormTrait
*/
public function getDefaultValue(string $name)
{
- $path = explode('.', $name) ?: [];
- $offset = array_shift($path) ?? '';
+ $path = explode('.', $name);
+ $offset = array_shift($path);
$current = $this->getDefaultValues();
@@ -692,7 +693,7 @@ trait FormTrait
throw new RuntimeException(sprintf('FlexForm: Bad HTTP method %s', $method));
}
- $body = $request->getParsedBody();
+ $body = (array)$request->getParsedBody();
$data = isset($body['data']) ? $this->decodeData($body['data']) : null;
$flash = $this->getFlash();
@@ -721,6 +722,7 @@ trait FormTrait
* @param ArrayAccess|Data|null $data
* @return void
* @throws ValidationException
+ * @phpstan-param ArrayAccess|Data|null $data
* @throws Exception
*/
protected function validateData($data = null): void
@@ -735,6 +737,7 @@ trait FormTrait
*
* @param ArrayAccess|Data|null $data
* @return void
+ * @phpstan-param ArrayAccess|Data|null $data
*/
protected function filterData($data = null): void
{
@@ -773,13 +776,16 @@ trait FormTrait
{
// Handle bad filenames.
$filename = $file->getClientFilename();
-
if ($filename && !Utils::checkFilename($filename)) {
$grav = Grav::instance();
throw new RuntimeException(
sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_UPLOAD', null, true), $filename, 'Bad filename')
);
}
+
+ if ($file instanceof FormFlashFile) {
+ $file->checkXss();
+ }
}
/**
@@ -797,9 +803,7 @@ trait FormTrait
// Decode JSON encoded fields and merge them to data.
if (isset($data['_json'])) {
$data = array_replace_recursive($data, $this->jsonDecode($data['_json']));
- if (null === $data) {
- throw new RuntimeException(__METHOD__ . '(): Unexpected error');
- }
+
unset($data['_json']);
}
diff --git a/system/src/Grav/Framework/Interfaces/RenderInterface.php b/system/src/Grav/Framework/Interfaces/RenderInterface.php
index 7a7d9d3..5bc6e58 100644
--- a/system/src/Grav/Framework/Interfaces/RenderInterface.php
+++ b/system/src/Grav/Framework/Interfaces/RenderInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Interfaces
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Logger/Processors/UserProcessor.php b/system/src/Grav/Framework/Logger/Processors/UserProcessor.php
index 885b4f0..f0ebef1 100644
--- a/system/src/Grav/Framework/Logger/Processors/UserProcessor.php
+++ b/system/src/Grav/Framework/Logger/Processors/UserProcessor.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Logger
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Media/Interfaces/MediaCollectionInterface.php b/system/src/Grav/Framework/Media/Interfaces/MediaCollectionInterface.php
index a3587d8..2bac98f 100644
--- a/system/src/Grav/Framework/Media/Interfaces/MediaCollectionInterface.php
+++ b/system/src/Grav/Framework/Media/Interfaces/MediaCollectionInterface.php
@@ -3,15 +3,21 @@
/**
* @package Grav\Framework\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Media\Interfaces;
+use ArrayAccess;
+use Countable;
+use Iterator;
+
/**
* Class implements media collection interface.
+ * @extends ArrayAccess
+ * @extends Iterator
*/
-interface MediaCollectionInterface extends \ArrayAccess, \Countable, \Iterator
+interface MediaCollectionInterface extends ArrayAccess, Countable, Iterator
{
}
diff --git a/system/src/Grav/Framework/Media/Interfaces/MediaInterface.php b/system/src/Grav/Framework/Media/Interfaces/MediaInterface.php
index 2c5a4b3..8688ad1 100644
--- a/system/src/Grav/Framework/Media/Interfaces/MediaInterface.php
+++ b/system/src/Grav/Framework/Media/Interfaces/MediaInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Media/Interfaces/MediaManipulationInterface.php b/system/src/Grav/Framework/Media/Interfaces/MediaManipulationInterface.php
index fef475f..bca9a22 100644
--- a/system/src/Grav/Framework/Media/Interfaces/MediaManipulationInterface.php
+++ b/system/src/Grav/Framework/Media/Interfaces/MediaManipulationInterface.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Media/Interfaces/MediaObjectInterface.php b/system/src/Grav/Framework/Media/Interfaces/MediaObjectInterface.php
index dc7f148..f4409c5 100644
--- a/system/src/Grav/Framework/Media/Interfaces/MediaObjectInterface.php
+++ b/system/src/Grav/Framework/Media/Interfaces/MediaObjectInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Media
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Mime/MimeTypes.php b/system/src/Grav/Framework/Mime/MimeTypes.php
index dadcddf..e3a5ea8 100644
--- a/system/src/Grav/Framework/Mime/MimeTypes.php
+++ b/system/src/Grav/Framework/Mime/MimeTypes.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Mime
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Access/ArrayAccessTrait.php b/system/src/Grav/Framework/Object/Access/ArrayAccessTrait.php
index affff03..4b67599 100644
--- a/system/src/Grav/Framework/Object/Access/ArrayAccessTrait.php
+++ b/system/src/Grav/Framework/Object/Access/ArrayAccessTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php b/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php
index 8365875..d9acb10 100644
--- a/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php
+++ b/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Access/NestedPropertyCollectionTrait.php b/system/src/Grav/Framework/Object/Access/NestedPropertyCollectionTrait.php
index 120c1a4..561b6fe 100644
--- a/system/src/Grav/Framework/Object/Access/NestedPropertyCollectionTrait.php
+++ b/system/src/Grav/Framework/Object/Access/NestedPropertyCollectionTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php b/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php
index 7409f4c..64107e0 100644
--- a/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -42,8 +42,8 @@ trait NestedPropertyTrait
public function getNestedProperty($property, $default = null, $separator = null)
{
$separator = $separator ?: '.';
- $path = explode($separator, $property) ?: [];
- $offset = array_shift($path) ?? '';
+ $path = explode($separator, $property);
+ $offset = array_shift($path);
if (!$this->hasProperty($offset)) {
return $default;
@@ -85,8 +85,8 @@ trait NestedPropertyTrait
public function setNestedProperty($property, $value, $separator = null)
{
$separator = $separator ?: '.';
- $path = explode($separator, $property) ?: [];
- $offset = array_shift($path) ?? '';
+ $path = explode($separator, $property);
+ $offset = array_shift($path);
if (!$path) {
$this->setProperty($offset, $value);
@@ -127,8 +127,8 @@ trait NestedPropertyTrait
public function unsetNestedProperty($property, $separator = null)
{
$separator = $separator ?: '.';
- $path = explode($separator, $property) ?: [];
- $offset = array_shift($path) ?? '';
+ $path = explode($separator, $property);
+ $offset = array_shift($path);
if (!$path) {
$this->unsetProperty($offset);
diff --git a/system/src/Grav/Framework/Object/Access/OverloadedPropertyTrait.php b/system/src/Grav/Framework/Object/Access/OverloadedPropertyTrait.php
index 0f0f89f..f417fba 100644
--- a/system/src/Grav/Framework/Object/Access/OverloadedPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Access/OverloadedPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -21,6 +21,7 @@ trait OverloadedPropertyTrait
* @param mixed $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
+ #[\ReturnTypeWillChange]
public function __isset($offset)
{
return $this->hasProperty($offset);
@@ -32,6 +33,7 @@ trait OverloadedPropertyTrait
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
+ #[\ReturnTypeWillChange]
public function __get($offset)
{
return $this->getProperty($offset);
@@ -44,6 +46,7 @@ trait OverloadedPropertyTrait
* @param mixed $value The value to set.
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($offset, $value)
{
$this->setProperty($offset, $value);
@@ -55,6 +58,7 @@ trait OverloadedPropertyTrait
* @param mixed $offset The name value to unset
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($offset)
{
$this->unsetProperty($offset);
diff --git a/system/src/Grav/Framework/Object/ArrayObject.php b/system/src/Grav/Framework/Object/ArrayObject.php
index 2bbe937..a38864c 100644
--- a/system/src/Grav/Framework/Object/ArrayObject.php
+++ b/system/src/Grav/Framework/Object/ArrayObject.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -19,6 +19,7 @@ use Grav\Framework\Object\Property\ArrayPropertyTrait;
/**
* Array Objects keep the data in private array property.
+ * @implements ArrayAccess
*/
class ArrayObject implements NestedObjectInterface, ArrayAccess
{
diff --git a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php
index 3c172fe..e29370a 100644
--- a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php
+++ b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -11,6 +11,7 @@ namespace Grav\Framework\Object\Base;
use Grav\Framework\Compat\Serializable;
use Grav\Framework\Object\Interfaces\ObjectInterface;
+use InvalidArgumentException;
use function call_user_func_array;
use function get_class;
use function is_callable;
@@ -19,6 +20,9 @@ use function is_object;
/**
* ObjectCollection Trait
* @package Grav\Framework\Object
+ *
+ * @template TKey as array-key
+ * @template T as ObjectInterface
*/
trait ObjectCollectionTrait
{
@@ -51,6 +55,7 @@ trait ObjectCollectionTrait
}
$class = get_class($this);
+
return $type . strtolower(substr($class, strrpos($class, '\\') + 1));
}
@@ -167,7 +172,7 @@ trait ObjectCollectionTrait
protected function doUnserialize(array $data)
{
if (!isset($data['key'], $data['type'], $data['elements']) || $data['type'] !== $this->getType()) {
- throw new \InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
+ throw new InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
}
$this->setKey($data['key']);
@@ -179,6 +184,7 @@ trait ObjectCollectionTrait
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->doSerialize();
@@ -189,6 +195,7 @@ trait ObjectCollectionTrait
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->getKey();
@@ -207,14 +214,18 @@ trait ObjectCollectionTrait
/**
* Create a copy from this collection by cloning all objects in the collection.
+ *
+ * @return static
*/
public function copy()
{
$list = [];
foreach ($this->getIterator() as $key => $value) {
+ /** @phpstan-ignore-next-line */
$list[$key] = is_object($value) ? clone $value : $value;
}
+ /** @phpstan-var static */
return $this->createFrom($list);
}
@@ -330,6 +341,7 @@ trait ObjectCollectionTrait
*
* @param string $property
* @return array
+ * @phpstan-return array
*/
public function group($property)
{
@@ -348,12 +360,13 @@ trait ObjectCollectionTrait
*
* @param string $property
* @return static[]
+ * @phpstan-return array>
*/
public function collectionGroup($property)
{
$collections = [];
foreach ($this->group($property) as $id => $elements) {
- /** @var static $collection */
+ /** @phpstan-var static $collection */
$collection = $this->createFrom($elements);
$collections[$id] = $collection;
diff --git a/system/src/Grav/Framework/Object/Base/ObjectTrait.php b/system/src/Grav/Framework/Object/Base/ObjectTrait.php
index d4e324b..86df8c7 100644
--- a/system/src/Grav/Framework/Object/Base/ObjectTrait.php
+++ b/system/src/Grav/Framework/Object/Base/ObjectTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -172,6 +172,7 @@ trait ObjectTrait
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->doSerialize();
@@ -182,6 +183,7 @@ trait ObjectTrait
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->getKey();
diff --git a/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php b/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php
index d8f1524..e8b12b7 100644
--- a/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php
+++ b/system/src/Grav/Framework/Object/Collection/ObjectExpressionVisitor.php
@@ -3,12 +3,13 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Object\Collection;
+use ArrayAccess;
use Closure;
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
use Doctrine\Common\Collections\Expr\Comparison;
@@ -42,7 +43,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
$field = rtrim($field, ')');
}
- if (isset($object[$field])) {
+ if ($object instanceof ArrayAccess && isset($object[$field])) {
$value = $object[$field];
} else {
$accessors = array('', 'get', 'is');
@@ -233,7 +234,7 @@ class ObjectExpressionVisitor extends ClosureExpressionVisitor
};
default:
- throw new RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
+ throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
}
}
}
diff --git a/system/src/Grav/Framework/Object/Interfaces/NestedObjectCollectionInterface.php b/system/src/Grav/Framework/Object/Interfaces/NestedObjectCollectionInterface.php
index a2431be..9f00bab 100644
--- a/system/src/Grav/Framework/Object/Interfaces/NestedObjectCollectionInterface.php
+++ b/system/src/Grav/Framework/Object/Interfaces/NestedObjectCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php b/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php
index 4d7a880..c144d8e 100644
--- a/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php
+++ b/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php b/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php
index 8169c24..bd25f61 100644
--- a/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php
+++ b/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php b/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php
index e8ec2c1..bc4d45d 100644
--- a/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php
+++ b/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/LazyObject.php b/system/src/Grav/Framework/Object/LazyObject.php
index 309c0d6..6be2558 100644
--- a/system/src/Grav/Framework/Object/LazyObject.php
+++ b/system/src/Grav/Framework/Object/LazyObject.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,6 +22,7 @@ use Grav\Framework\Object\Property\LazyPropertyTrait;
* not exist or is not initialized.
*
* @package Grav\Framework\Object
+ * @implements ArrayAccess
*/
class LazyObject implements NestedObjectInterface, ArrayAccess
{
diff --git a/system/src/Grav/Framework/Object/ObjectCollection.php b/system/src/Grav/Framework/Object/ObjectCollection.php
index 3fdebce..94392af 100644
--- a/system/src/Grav/Framework/Object/ObjectCollection.php
+++ b/system/src/Grav/Framework/Object/ObjectCollection.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -22,12 +22,13 @@ use function array_slice;
* Class contains a collection of objects.
*
* @template TKey of array-key
- * @template T
+ * @template T of \Grav\Framework\Object\Interfaces\ObjectInterface
* @extends ArrayCollection
* @implements NestedObjectCollectionInterface
*/
class ObjectCollection extends ArrayCollection implements NestedObjectCollectionInterface
{
+ /** @phpstan-use ObjectCollectionTrait */
use ObjectCollectionTrait;
use NestedPropertyCollectionTrait {
NestedPropertyCollectionTrait::group insteadof ObjectCollectionTrait;
@@ -65,6 +66,7 @@ class ObjectCollection extends ArrayCollection implements NestedObjectCollection
*/
public function limit($start, $limit = null)
{
+ /** @phpstan-var static */
return $this->createFrom($this->slice($start, $limit));
}
@@ -86,14 +88,11 @@ class ObjectCollection extends ArrayCollection implements NestedObjectCollection
if ($orderings = $criteria->getOrderings()) {
$next = null;
- /**
- * @var string $field
- * @var string $ordering
- */
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ObjectExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
}
+ /** @phpstan-ignore-next-line */
if ($next) {
uasort($filtered, $next);
}
@@ -106,11 +105,13 @@ class ObjectCollection extends ArrayCollection implements NestedObjectCollection
$filtered = array_slice($filtered, (int)$offset, $length);
}
+ /** @phpstan-var static */
return $this->createFrom($filtered);
}
/**
* @return array
+ * @phpstan-return array
*/
protected function getElements()
{
@@ -120,9 +121,11 @@ class ObjectCollection extends ArrayCollection implements NestedObjectCollection
/**
* @param array $elements
* @return array
+ * @phpstan-return array
*/
protected function setElements(array $elements)
{
+ /** @phpstan-var array $elements */
return $elements;
}
}
diff --git a/system/src/Grav/Framework/Object/ObjectIndex.php b/system/src/Grav/Framework/Object/ObjectIndex.php
index 50ac427..ab495bd 100644
--- a/system/src/Grav/Framework/Object/ObjectIndex.php
+++ b/system/src/Grav/Framework/Object/ObjectIndex.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -25,7 +25,7 @@ use function is_object;
*
* @template TKey of array-key
* @template T of \Grav\Framework\Object\Interfaces\ObjectInterface
- * @template C of \Grav\Framework\Collection\CollectionInterface
+ * @template C of ObjectCollectionInterface
* @extends AbstractIndexCollection
* @implements NestedObjectCollectionInterface
*/
@@ -35,7 +35,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
protected static $type;
/** @var string */
- private $_key;
+ protected $_key;
/**
* @param bool $prefix
@@ -95,6 +95,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param string $property Object property to be updated.
* @param string $value New value.
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function setProperty($property, $value)
{
@@ -105,6 +106,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param string $property Object property to be defined.
* @param mixed $default Default value.
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function defProperty($property, $default)
{
@@ -114,6 +116,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
/**
* @param string $property Object property to be unset.
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function unsetProperty($property)
{
@@ -146,6 +149,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param mixed $value New value.
* @param string|null $separator Separator, defaults to '.'
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function setNestedProperty($property, $value, $separator = null)
{
@@ -157,6 +161,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param mixed $default Default value.
* @param string|null $separator Separator, defaults to '.'
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function defNestedProperty($property, $default, $separator = null)
{
@@ -167,6 +172,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param string $property Object property to be unset.
* @param string|null $separator Separator, defaults to '.'
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function unsetNestedProperty($property, $separator = null)
{
@@ -183,9 +189,11 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
{
$list = [];
foreach ($this->getIterator() as $key => $value) {
+ /** @phpstan-ignore-next-line */
$list[$key] = is_object($value) ? clone $value : $value;
}
+ /** @phpstan-var static */
return $this->createFrom($list);
}
@@ -200,6 +208,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
/**
* @param array $ordering
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function orderBy(array $ordering)
{
@@ -232,6 +241,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
*
* @param string $property
* @return ObjectCollectionInterface[]
+ * @phpstan-return C[]
*/
public function collectionGroup($property)
{
@@ -239,14 +249,18 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
}
/**
- * {@inheritDoc}
+ * @param Criteria $criteria
+ * @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function matching(Criteria $criteria)
{
- /** @var ObjectCollectionInterface $collection */
$collection = $this->loadCollection($this->getEntries());
- return $collection->matching($criteria);
+ /** @phpstan-var C $matching */
+ $matching = $collection->matching($criteria);
+
+ return $matching;
}
/**
@@ -254,6 +268,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* @param array $arguments
* @return mixed
*/
+ #[\ReturnTypeWillChange]
abstract public function __call($name, $arguments);
/**
diff --git a/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php b/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php
index fa3fed1..8ab4c41 100644
--- a/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -97,7 +97,7 @@ trait ArrayPropertyTrait
*/
protected function getElements()
{
- return array_filter($this->_elements, function ($val) {
+ return array_filter($this->_elements, static function ($val) {
return $val !== null;
});
}
diff --git a/system/src/Grav/Framework/Object/Property/LazyPropertyTrait.php b/system/src/Grav/Framework/Object/Property/LazyPropertyTrait.php
index d5baddb..e689259 100644
--- a/system/src/Grav/Framework/Object/Property/LazyPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Property/LazyPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -87,8 +87,7 @@ trait LazyPropertyTrait
*/
protected function doUnsetProperty($property)
{
- $this->hasObjectProperty($property) ?
- $this->unsetObjectProperty($property) : $this->unsetArrayProperty($property);
+ $this->hasObjectProperty($property) ? $this->unsetObjectProperty($property) : $this->unsetArrayProperty($property);
}
/**
diff --git a/system/src/Grav/Framework/Object/Property/MixedPropertyTrait.php b/system/src/Grav/Framework/Object/Property/MixedPropertyTrait.php
index 584e812..1b57aab 100644
--- a/system/src/Grav/Framework/Object/Property/MixedPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Property/MixedPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php
index 435220a..bb0195d 100644
--- a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php
+++ b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Object/PropertyObject.php b/system/src/Grav/Framework/Object/PropertyObject.php
index dbeb5c4..d9cdde8 100644
--- a/system/src/Grav/Framework/Object/PropertyObject.php
+++ b/system/src/Grav/Framework/Object/PropertyObject.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Object
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -19,6 +19,8 @@ use Grav\Framework\Object\Property\ObjectPropertyTrait;
/**
* Property Objects keep their data in protected object properties.
+ *
+ * @implements ArrayAccess
*/
class PropertyObject implements NestedObjectInterface, ArrayAccess
{
diff --git a/system/src/Grav/Framework/Pagination/AbstractPagination.php b/system/src/Grav/Framework/Pagination/AbstractPagination.php
index 0be21ec..a4d902a 100644
--- a/system/src/Grav/Framework/Pagination/AbstractPagination.php
+++ b/system/src/Grav/Framework/Pagination/AbstractPagination.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -234,7 +234,9 @@ class AbstractPagination implements PaginationInterface
/**
* @return ArrayIterator
+ * @phpstan-return ArrayIterator
*/
+ #[\ReturnTypeWillChange]
public function getIterator()
{
$this->loadItems();
diff --git a/system/src/Grav/Framework/Pagination/AbstractPaginationPage.php b/system/src/Grav/Framework/Pagination/AbstractPaginationPage.php
index 95ff8af..072fea7 100644
--- a/system/src/Grav/Framework/Pagination/AbstractPaginationPage.php
+++ b/system/src/Grav/Framework/Pagination/AbstractPaginationPage.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -41,7 +41,7 @@ abstract class AbstractPaginationPage implements PaginationPageInterface
*/
public function getOptions(): array
{
- return $this->options ?? [];
+ return $this->options;
}
/**
diff --git a/system/src/Grav/Framework/Pagination/Interfaces/PaginationInterface.php b/system/src/Grav/Framework/Pagination/Interfaces/PaginationInterface.php
index 56d3361..1a82147 100644
--- a/system/src/Grav/Framework/Pagination/Interfaces/PaginationInterface.php
+++ b/system/src/Grav/Framework/Pagination/Interfaces/PaginationInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,6 +16,7 @@ use IteratorAggregate;
/**
* Interface PaginationInterface
* @package Grav\Framework\Pagination\Interfaces
+ * @extends IteratorAggregate
*/
interface PaginationInterface extends Countable, IteratorAggregate
{
diff --git a/system/src/Grav/Framework/Pagination/Interfaces/PaginationPageInterface.php b/system/src/Grav/Framework/Pagination/Interfaces/PaginationPageInterface.php
index b90594d..26c0692 100644
--- a/system/src/Grav/Framework/Pagination/Interfaces/PaginationPageInterface.php
+++ b/system/src/Grav/Framework/Pagination/Interfaces/PaginationPageInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Pagination/Pagination.php b/system/src/Grav/Framework/Pagination/Pagination.php
index e602872..8f2fa20 100644
--- a/system/src/Grav/Framework/Pagination/Pagination.php
+++ b/system/src/Grav/Framework/Pagination/Pagination.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Pagination/PaginationPage.php b/system/src/Grav/Framework/Pagination/PaginationPage.php
index 63ceb5f..e64abe9 100644
--- a/system/src/Grav/Framework/Pagination/PaginationPage.php
+++ b/system/src/Grav/Framework/Pagination/PaginationPage.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Pagination
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/AbstractUri.php b/system/src/Grav/Framework/Psr7/AbstractUri.php
index 85d802f..145437a 100644
--- a/system/src/Grav/Framework/Psr7/AbstractUri.php
+++ b/system/src/Grav/Framework/Psr7/AbstractUri.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -263,6 +263,7 @@ abstract class AbstractUri implements UriInterface
/**
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->getUrl();
diff --git a/system/src/Grav/Framework/Psr7/Request.php b/system/src/Grav/Framework/Psr7/Request.php
index cd65fd9..795a1a4 100644
--- a/system/src/Grav/Framework/Psr7/Request.php
+++ b/system/src/Grav/Framework/Psr7/Request.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Response.php b/system/src/Grav/Framework/Psr7/Response.php
index 6cb67e0..6189c4a 100644
--- a/system/src/Grav/Framework/Psr7/Response.php
+++ b/system/src/Grav/Framework/Psr7/Response.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -53,6 +53,7 @@ class Response implements ResponseInterface
* @param int $options Json encoding options
* @param int $depth Json encoding max depth
* @return static
+ * @phpstan-param positive-int $depth
*/
public function withJson($data, int $status = null, int $options = 0, int $depth = 512): ResponseInterface
{
@@ -257,7 +258,7 @@ class Response implements ResponseInterface
}
$output .= self::EOL;
- $output .= (string) $response->getBody();
+ $output .= $response->getBody();
return $output;
}
diff --git a/system/src/Grav/Framework/Psr7/ServerRequest.php b/system/src/Grav/Framework/Psr7/ServerRequest.php
index 4084834..cb5bcbb 100644
--- a/system/src/Grav/Framework/Psr7/ServerRequest.php
+++ b/system/src/Grav/Framework/Psr7/ServerRequest.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -98,13 +98,8 @@ class ServerRequest implements ServerRequestInterface
public function getCookieParam($key, $default = null)
{
$cookies = $this->getRequest()->getCookieParams();
- $result = $default;
- if (isset($cookies[$key])) {
- $result = $cookies[$key];
- }
-
- return $result;
+ return $cookies[$key] ?? $default;
}
/**
@@ -238,13 +233,8 @@ class ServerRequest implements ServerRequestInterface
public function getQueryParam($key, $default = null)
{
$getParams = $this->getQueryParams();
- $result = $default;
- if (isset($getParams[$key])) {
- $result = $getParams[$key];
- }
-
- return $result;
+ return $getParams[$key] ?? $default;
}
/**
diff --git a/system/src/Grav/Framework/Psr7/Stream.php b/system/src/Grav/Framework/Psr7/Stream.php
index a5a1043..6546bdc 100644
--- a/system/src/Grav/Framework/Psr7/Stream.php
+++ b/system/src/Grav/Framework/Psr7/Stream.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/MessageDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/MessageDecoratorTrait.php
index 39e3818..c09a03c 100644
--- a/system/src/Grav/Framework/Psr7/Traits/MessageDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/MessageDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php
index 13f4c6f..49f2a92 100644
--- a/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/RequestDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php
index 7b62c3c..4bbc736 100644
--- a/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/ResponseDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php
index 33c26e0..9222219 100644
--- a/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/ServerRequestDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/StreamDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/StreamDecoratorTrait.php
index db1e746..448323f 100644
--- a/system/src/Grav/Framework/Psr7/Traits/StreamDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/StreamDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -33,6 +33,7 @@ trait StreamDecoratorTrait
/**
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
$this->stream->close();
diff --git a/system/src/Grav/Framework/Psr7/Traits/UploadedFileDecoratorTrait.php b/system/src/Grav/Framework/Psr7/Traits/UploadedFileDecoratorTrait.php
index e0c65bd..eec3add 100644
--- a/system/src/Grav/Framework/Psr7/Traits/UploadedFileDecoratorTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/UploadedFileDecoratorTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php b/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php
index 607d757..73adb64 100644
--- a/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php
+++ b/system/src/Grav/Framework/Psr7/Traits/UriDecorationTrait.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/UploadedFile.php b/system/src/Grav/Framework/Psr7/UploadedFile.php
index bfa63cd..c3ed62e 100644
--- a/system/src/Grav/Framework/Psr7/UploadedFile.php
+++ b/system/src/Grav/Framework/Psr7/UploadedFile.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Psr7/Uri.php b/system/src/Grav/Framework/Psr7/Uri.php
index c920b33..63fe04e 100644
--- a/system/src/Grav/Framework/Psr7/Uri.php
+++ b/system/src/Grav/Framework/Psr7/Uri.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
/**
* @package Grav\Framework\Psr7
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -24,9 +24,6 @@ class Uri implements UriInterface
{
use UriDecorationTrait;
- /** @var array Array of Uri query. */
- private $queryParams;
-
public function __construct(string $uri = '')
{
$this->uri = new \Nyholm\Psr7\Uri($uri);
diff --git a/system/src/Grav/Framework/RequestHandler/Exception/InvalidArgumentException.php b/system/src/Grav/Framework/RequestHandler/Exception/InvalidArgumentException.php
index 451e586..2456ea1 100644
--- a/system/src/Grav/Framework/RequestHandler/Exception/InvalidArgumentException.php
+++ b/system/src/Grav/Framework/RequestHandler/Exception/InvalidArgumentException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/RequestHandler/Exception/NotFoundException.php b/system/src/Grav/Framework/RequestHandler/Exception/NotFoundException.php
index 28a226a..ce79ab2 100644
--- a/system/src/Grav/Framework/RequestHandler/Exception/NotFoundException.php
+++ b/system/src/Grav/Framework/RequestHandler/Exception/NotFoundException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -21,9 +21,6 @@ use function in_array;
*/
class NotFoundException extends RequestException
{
- /** @var ServerRequestInterface */
- private $request;
-
/**
* NotFoundException constructor.
* @param ServerRequestInterface $request
@@ -37,9 +34,4 @@ class NotFoundException extends RequestException
parent::__construct($request, 'Not Found', 404, $previous);
}
}
-
- public function getRequest(): ServerRequestInterface
- {
- return $this->request;
- }
}
diff --git a/system/src/Grav/Framework/RequestHandler/Exception/NotHandledException.php b/system/src/Grav/Framework/RequestHandler/Exception/NotHandledException.php
index 1b18473..7b4a0e7 100644
--- a/system/src/Grav/Framework/RequestHandler/Exception/NotHandledException.php
+++ b/system/src/Grav/Framework/RequestHandler/Exception/NotHandledException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/RequestHandler/Exception/PageExpiredException.php b/system/src/Grav/Framework/RequestHandler/Exception/PageExpiredException.php
index 747c0ca..f752167 100644
--- a/system/src/Grav/Framework/RequestHandler/Exception/PageExpiredException.php
+++ b/system/src/Grav/Framework/RequestHandler/Exception/PageExpiredException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/RequestHandler/Exception/RequestException.php b/system/src/Grav/Framework/RequestHandler/Exception/RequestException.php
index 6079964..678b267 100644
--- a/system/src/Grav/Framework/RequestHandler/Exception/RequestException.php
+++ b/system/src/Grav/Framework/RequestHandler/Exception/RequestException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php b/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php
index 9eadf72..36ef3a5 100644
--- a/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php
+++ b/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/RequestHandler/RequestHandler.php b/system/src/Grav/Framework/RequestHandler/RequestHandler.php
index 5b03805..2ce2427 100644
--- a/system/src/Grav/Framework/RequestHandler/RequestHandler.php
+++ b/system/src/Grav/Framework/RequestHandler/RequestHandler.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -12,9 +12,11 @@ declare(strict_types=1);
namespace Grav\Framework\RequestHandler;
use Grav\Framework\RequestHandler\Traits\RequestHandlerTrait;
+use Pimple\Container;
use Psr\Container\ContainerInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
+use function assert;
/**
* Class RequestHandler
@@ -47,7 +49,11 @@ class RequestHandler implements RequestHandlerInterface
*/
public function addCallable(string $name, callable $callable): self
{
- $this->container[$name] = $callable;
+ if (null !== $this->container) {
+ assert($this->container instanceof Container);
+ $this->container[$name] = $callable;
+ }
+
array_unshift($this->middleware, $name);
return $this;
@@ -62,7 +68,11 @@ class RequestHandler implements RequestHandlerInterface
*/
public function addMiddleware(string $name, MiddlewareInterface $middleware): self
{
- $this->container[$name] = $middleware;
+ if (null !== $this->container) {
+ assert($this->container instanceof Container);
+ $this->container[$name] = $middleware;
+ }
+
array_unshift($this->middleware, $name);
return $this;
diff --git a/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php b/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php
index 1b5a79e..ff82889 100644
--- a/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php
+++ b/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\RequestHandler
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php
index f9a7fa7..d4d9078 100644
--- a/system/src/Grav/Framework/Route/Route.php
+++ b/system/src/Grav/Framework/Route/Route.php
@@ -3,12 +3,13 @@
/**
* @package Grav\Framework\Route
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Framework\Route;
+use Grav\Framework\Uri\Uri;
use Grav\Framework\Uri\UriFactory;
use InvalidArgumentException;
use function array_slice;
@@ -318,7 +319,7 @@ class Route
}
/**
- * @return \Grav\Framework\Uri\Uri
+ * @return Uri
*/
public function getUri()
{
@@ -344,6 +345,7 @@ class Route
* @return string
* @deprecated 1.6 Use ->toString(true) or ->getUri() instead.
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() will change in the future to return route, not relative url: use ->toString(true) or ->getUri() instead.', E_USER_DEPRECATED);
diff --git a/system/src/Grav/Framework/Route/RouteFactory.php b/system/src/Grav/Framework/Route/RouteFactory.php
index 68baf55..fa1a76c 100644
--- a/system/src/Grav/Framework/Route/RouteFactory.php
+++ b/system/src/Grav/Framework/Route/RouteFactory.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Route
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Session/Exceptions/SessionException.php b/system/src/Grav/Framework/Session/Exceptions/SessionException.php
index 5ad948b..a07e87d 100644
--- a/system/src/Grav/Framework/Session/Exceptions/SessionException.php
+++ b/system/src/Grav/Framework/Session/Exceptions/SessionException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Session
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Session/Messages.php b/system/src/Grav/Framework/Session/Messages.php
index 5d854a2..37c62a9 100644
--- a/system/src/Grav/Framework/Session/Messages.php
+++ b/system/src/Grav/Framework/Session/Messages.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Session
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Session/Session.php b/system/src/Grav/Framework/Session/Session.php
index 3feae5a..108563e 100644
--- a/system/src/Grav/Framework/Session/Session.php
+++ b/system/src/Grav/Framework/Session/Session.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Session
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -189,7 +189,11 @@ class Session implements SessionInterface
return $this;
}
- $sessionName = session_name();
+ $sessionName = $this->getName();
+ if (null === $sessionName) {
+ return $this;
+ }
+
$sessionExists = isset($_COOKIE[$sessionName]);
// Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836
@@ -341,7 +345,7 @@ class Session implements SessionInterface
$this->removeCookie();
setcookie(
- session_name(),
+ $name,
'',
$this->getCookieOptions(-42000)
);
@@ -392,6 +396,7 @@ class Session implements SessionInterface
/**
* @inheritdoc
*/
+ #[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($_SESSION);
@@ -408,6 +413,7 @@ class Session implements SessionInterface
/**
* @inheritdoc
*/
+ #[\ReturnTypeWillChange]
public function __isset($name)
{
return isset($_SESSION[$name]);
@@ -416,6 +422,7 @@ class Session implements SessionInterface
/**
* @inheritdoc
*/
+ #[\ReturnTypeWillChange]
public function __get($name)
{
return $_SESSION[$name] ?? null;
@@ -424,6 +431,7 @@ class Session implements SessionInterface
/**
* @inheritdoc
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value)
{
$_SESSION[$name] = $value;
@@ -432,6 +440,7 @@ class Session implements SessionInterface
/**
* @inheritdoc
*/
+ #[\ReturnTypeWillChange]
public function __unset($name)
{
unset($_SESSION[$name]);
@@ -478,9 +487,15 @@ class Session implements SessionInterface
{
$this->removeCookie();
+ $sessionName = $this->getName();
+ $sessionId = $this->getId();
+ if (null === $sessionName || null === $sessionId) {
+ return;
+ }
+
setcookie(
- session_name(),
- session_id(),
+ $sessionName,
+ $sessionId,
$this->getCookieOptions()
);
}
diff --git a/system/src/Grav/Framework/Session/SessionInterface.php b/system/src/Grav/Framework/Session/SessionInterface.php
index 43ca40f..fa2873d 100644
--- a/system/src/Grav/Framework/Session/SessionInterface.php
+++ b/system/src/Grav/Framework/Session/SessionInterface.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Session
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -16,6 +16,7 @@ use RuntimeException;
/**
* Class Session
* @package Grav\Framework\Session
+ * @extends IteratorAggregate
*/
interface SessionInterface extends IteratorAggregate
{
@@ -107,7 +108,9 @@ interface SessionInterface extends IteratorAggregate
* Retrieve an external iterator
*
* @return ArrayIterator Return an ArrayIterator of $_SESSION
+ * @phpstan-return ArrayIterator
*/
+ #[\ReturnTypeWillChange]
public function getIterator();
/**
@@ -123,6 +126,7 @@ interface SessionInterface extends IteratorAggregate
* @param string $name
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($name);
/**
@@ -131,6 +135,7 @@ interface SessionInterface extends IteratorAggregate
* @param string $name
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function __get($name);
/**
@@ -140,6 +145,7 @@ interface SessionInterface extends IteratorAggregate
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value);
/**
@@ -148,5 +154,6 @@ interface SessionInterface extends IteratorAggregate
* @param string $name
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($name);
}
diff --git a/system/src/Grav/Framework/Uri/Uri.php b/system/src/Grav/Framework/Uri/Uri.php
index c43496e..6355a1f 100644
--- a/system/src/Grav/Framework/Uri/Uri.php
+++ b/system/src/Grav/Framework/Uri/Uri.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Uri
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Framework/Uri/UriFactory.php b/system/src/Grav/Framework/Uri/UriFactory.php
index f7724b7..ebfec03 100644
--- a/system/src/Grav/Framework/Uri/UriFactory.php
+++ b/system/src/Grav/Framework/Uri/UriFactory.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Uri
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -125,7 +125,7 @@ class UriFactory
$encodedUrl = preg_replace_callback(
'%[^:/@?&=#]+%u',
- function ($matches) {
+ static function ($matches) {
return rawurlencode($matches[0]);
},
$url
diff --git a/system/src/Grav/Framework/Uri/UriPartsFilter.php b/system/src/Grav/Framework/Uri/UriPartsFilter.php
index 71a5135..260711b 100644
--- a/system/src/Grav/Framework/Uri/UriPartsFilter.php
+++ b/system/src/Grav/Framework/Uri/UriPartsFilter.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Framework\Uri
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Installer/Install.php b/system/src/Grav/Installer/Install.php
index 4df9dcd..0f23e89 100644
--- a/system/src/Grav/Installer/Install.php
+++ b/system/src/Grav/Installer/Install.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Installer
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -36,9 +36,11 @@ final class Install
'php' => [
'name' => 'PHP',
'versions' => [
- '7.4' => '7.4.0',
+ '8.1' => '8.1.0',
+ '8.0' => '8.0.0',
+ '7.4' => '7.4.1',
'7.3' => '7.3.6',
- '' => '7.4.12'
+ '' => '8.0.13'
]
],
'grav' => [
@@ -114,7 +116,7 @@ final class Install
/** @var string|null */
private $location;
- /** @var VersionUpdater */
+ /** @var VersionUpdater|null */
private $updater;
/** @var static */
@@ -151,6 +153,7 @@ final class Install
* @param string|null $zip
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __invoke(?string $zip)
{
$this->zip = $zip;
@@ -249,6 +252,11 @@ ERR;
}
try {
+ if (null === $this->updater) {
+ $versions = Versions::instance(USER_DIR . 'config/versions.yaml');
+ $this->updater = new VersionUpdater('core/grav', __DIR__ . '/updates', $this->getVersion(), $versions);
+ }
+
// Update user/config/version.yaml before copying the files to avoid frontend from setting the version schema.
$this->updater->install();
@@ -279,7 +287,7 @@ ERR;
public function finalize(): void
{
// Finalize can be run without installing Grav first.
- if (!$this->updater) {
+ if (null === $this->updater) {
$versions = Versions::instance(USER_DIR . 'config/versions.yaml');
$this->updater = new VersionUpdater('core/grav', __DIR__ . '/updates', GRAV_VERSION, $versions);
$this->updater->install();
diff --git a/system/src/Grav/Installer/InstallException.php b/system/src/Grav/Installer/InstallException.php
index 145b7c9..cdd5b7a 100644
--- a/system/src/Grav/Installer/InstallException.php
+++ b/system/src/Grav/Installer/InstallException.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Installer
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Installer/VersionUpdate.php b/system/src/Grav/Installer/VersionUpdate.php
index faaf2a2..1fde783 100644
--- a/system/src/Grav/Installer/VersionUpdate.php
+++ b/system/src/Grav/Installer/VersionUpdate.php
@@ -3,6 +3,7 @@
namespace Grav\Installer;
use Closure;
+use Grav\Common\Utils;
/**
* Class VersionUpdate
@@ -50,7 +51,7 @@ final class VersionUpdate
public function getPatch(): string
{
- return $this->date;
+ return $this->patch;
}
public function getUpdater(): VersionUpdater
diff --git a/system/src/Grav/Installer/Versions.php b/system/src/Grav/Installer/Versions.php
index 03f3b0b..92a64ce 100644
--- a/system/src/Grav/Installer/Versions.php
+++ b/system/src/Grav/Installer/Versions.php
@@ -3,7 +3,7 @@
/**
* @package Grav\Installer
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
diff --git a/system/src/Grav/Installer/YamlUpdater.php b/system/src/Grav/Installer/YamlUpdater.php
index 9af2055..fe1c7f1 100644
--- a/system/src/Grav/Installer/YamlUpdater.php
+++ b/system/src/Grav/Installer/YamlUpdater.php
@@ -3,12 +3,13 @@
/**
* @package Grav\Installer
*
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
+ * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Installer;
+use Grav\Common\Utils;
use Symfony\Component\Yaml\Yaml;
use function assert;
use function count;
diff --git a/system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php b/system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php
index 8c441bb..1ff7fd4 100644
--- a/system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php
+++ b/system/src/Twig/DeferredExtension/DeferredNodeVisitorCompat.php
@@ -22,16 +22,28 @@ final class DeferredNodeVisitorCompat implements NodeVisitorInterface
{
private $hasDeferred = false;
- public function enterNode(\Twig_NodeInterface $node, Environment $env) : Node
+ /**
+ * @param \Twig_NodeInterface $node
+ * @param Environment $env
+ * @return Node
+ */
+ public function enterNode(\Twig_NodeInterface $node, Environment $env): Node
{
if (!$this->hasDeferred && $node instanceof DeferredBlockNode) {
$this->hasDeferred = true;
}
+ \assert($node instanceof Node);
+
return $node;
}
- public function leaveNode(\Twig_NodeInterface $node, Environment $env) : ?Node
+ /**
+ * @param \Twig_NodeInterface $node
+ * @param Environment $env
+ * @return Node|null
+ */
+ public function leaveNode(\Twig_NodeInterface $node, Environment $env): ?Node
{
if ($this->hasDeferred && $node instanceof ModuleNode) {
$node->setNode('constructor_end', new Node([new DeferredExtensionNode(), $node->getNode('constructor_end')]));
@@ -39,9 +51,14 @@ final class DeferredNodeVisitorCompat implements NodeVisitorInterface
$this->hasDeferred = false;
}
+ \assert($node instanceof Node);
+
return $node;
}
+ /**
+ * @return int
+ */
public function getPriority() : int
{
return 0;
diff --git a/user/config/versions.yaml b/user/config/versions.yaml
index 9480e4c..092f378 100644
--- a/user/config/versions.yaml
+++ b/user/config/versions.yaml
@@ -1,8 +1,9 @@
core:
grav:
- version: 1.7.25
+ version: 1.7.31
schema: 1.7.0_2020-11-20_1
history:
- { version: 1.7.16, date: '2021-06-10 14:03:35' }
- { version: 1.7.21, date: '2021-09-16 12:41:14' }
- { version: 1.7.25, date: '2021-12-06 12:22:00' }
+ - { version: 1.7.31, date: '2022-03-15 08:48:47' }
diff --git a/user/pages_offline/05.demande-de-devis/form.fr.md b/user/pages_offline/05.demande-de-devis/form.fr.md
new file mode 100644
index 0000000..3849630
--- /dev/null
+++ b/user/pages_offline/05.demande-de-devis/form.fr.md
@@ -0,0 +1,169 @@
+---
+title: 'Le Campus, au cœur du Val de Drôme, un site tout équipé pour vos événements.'
+media_order: vue_ext.jpg
+entete:
+ text: 'Vous souhaitez organiser un événement, une rencontre professionnelle, une formation, un séjour ? Décrivez-nous votre projet en quelques clics, nous sommes à votre écoute !'
+metadata:
+ description: 'Le Campus, au cœur du Val de Drôme, un site tout équipé pour vos événements.'
+visible: false
+form:
+ name: ajax-test-form
+ action: /demande-de-devis
+ template: form-messages
+ refresh_prevention: true
+ fields:
+ -
+ name: 'Quelle est la nature de votre évènement ?'
+ placeholder: 'Choisissez votre évènement ?'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ label: 'Quelle est la nature de votre évènement ?'
+ options:
+ reunion: Réunion
+ seminaire: Séminaire
+ convention: Convention
+ vœux: Vœux
+ web_conference: 'Web conférence'
+ salon_forum_exposition: 'Salon, Forum, Exposition'
+ conference: Conférence
+ evenement_culturel: 'Evènement culturel'
+ autre: Autres
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Quelle sera l''envergure de votre évènement ?'
+ placeholder: 'Nombre de personnes'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ 25: 'Inférieure ou égal à 25 personnes'
+ 50: 'Inférieure ou égal à 50 personnes'
+ 100: 'Inférieure ou égal à 100 personnes'
+ 150: 'Supérieure à 150 personnes'
+ validate:
+ required: true
+ -
+ name: 'Quand se déroulera votre événement ?'
+ placeholder: 'jj/mm/yy'
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+
+ name: 'Date de lévenement'
+ placeholder: 'Choisissez vos date ?'
+ autocomplete: 'on'
+ type: date
+ label: 'Quand se déroulera votre événement ?'
+ -
+ name: 'Durée prévue'
+ placeholder: 'Choisissez vos date ?'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ 1/2j: 'Une demi journée'
+ 1j: 'Une journée'
+ 1s: 'Une soirée'
+ 2j: 'Deux jours'
+ 3j: 'Trois jours'
+ +3j: 'Plus de trois jours'
+ validate:
+ required: true
+ -
+ name: Prénom
+ placeholder: Prénom
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Nom
+ placeholder: Nom
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Adresse mail'
+ placeholder: 'Adresse mail'
+ type: email
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Téléphone
+ placeholder: Téléphone
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Fonction
+ placeholder: Fonction
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Société
+ placeholder: Société
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Votre profil'
+ placeholder: 'quel est votre profil'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ Agence_evenementielle: 'Agence évènementielle'
+ associations: 'Associations (sociétés savantes, fédérations, syndicats) '
+ societes_entreprises: 'Sociétés / Entreprises'
+ Organismes_professionnels: 'Organismes professionnels'
+ validate:
+ required: true
+ buttons:
+ -
+ type: submit
+ value: Envoyer
+ process:
+ -
+ email:
+ from: '{{ config.plugins.email.from }}'
+ to:
+ - '{{ config.plugins.email.to }}'
+ - '{{ form.value.email }}'
+ subject: '[Feedback] {{ form.value.name|e }}'
+ body: '{% include ''forms/data.html.twig'' %}'
+ -
+ save:
+ fileprefix: feedback-
+ dateformat: Ymd-His-u
+ extension: txt
+ body: '{% include ''forms/data.txt.twig'' %}'
+ -
+ message: 'Merci, votre demande de devis à bien été envoyé ! Elle sera traité dans les prochains jours.'
+---
+
+Location de salles polyvalentes, amphitéâtre de 200 places, matériel performant dans toutes les salles, restauration de qualité bio ou locale sur demande...
+**Le Campus et son équipe à taille humaine vous garantit la réussite de votre séjour, de votre séminaire ou de votre événement.**
diff --git a/user/pages_offline/05.demande-de-devis/form.md b/user/pages_offline/05.demande-de-devis/form.md
new file mode 100644
index 0000000..37dc62a
--- /dev/null
+++ b/user/pages_offline/05.demande-de-devis/form.md
@@ -0,0 +1,169 @@
+---
+title: 'Le Campus, au cœur du Val de Drôme, un site tout équipé pour vos événements.'
+media_order: vue_ext.jpg
+entete:
+ text: 'Vous souhaitez organiser un événement, une rencontre professionnelle, une formation, un séjour ? Décrivez-nous votre projet en quelques clics, nous sommes à votre écoute !'
+metadata:
+ description: 'Le Campus, au cœur du Val de Drôme, un site tout équipé pour vos événements.'
+visible: false
+form:
+ name: ajax-test-form
+ action: /demande-de-devis
+ template: form-messages
+ refresh_prevention: true
+ fields:
+ -
+ name: 'Quelle est la nature de votre évènement ?'
+ placeholder: 'Choisissez votre évènement ?'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ label: 'Quelle est la nature de votre évènement ?'
+ options:
+ reunion: Réunion
+ seminaire: Séminaire
+ convention: Convention
+ vœux: Vœux
+ web_conference: 'Web conférence'
+ salon_forum_exposition: 'Salon, Forum, Exposition'
+ conference: Conférence
+ evenement_culturel: 'Evènement culturel'
+ autre: Autres
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Quelle sera l''envergure de votre évènement ?'
+ placeholder: 'Nombre de personnes'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ 25: 'Inférieure ou égal à 25 personnes'
+ 50: 'Inférieure ou égal à 50 personnes'
+ 100: 'Inférieure ou égal à 100 personnes'
+ 150: 'Supérieure à 150 personnes'
+ validate:
+ required: true
+ -
+ name: 'Quand se déroulera votre événement ?'
+ placeholder: 'jj/mm/yy'
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+
+ name: 'Date de lévenement'
+ placeholder: 'Choisissez vos date ?'
+ autocomplete: 'on'
+ type: date
+ label: 'Quand se déroulera votre événement ?'
+ -
+ name: 'Durée prévue'
+ placeholder: 'Choisissez vos date ?'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ 1/2j: 'Une demi journée'
+ 1j: 'Une journée'
+ 1s: 'Une soirée'
+ 2j: 'Deux jours'
+ 3j: 'Trois jours'
+ +3j: 'Plus de trois jours'
+ validate:
+ required: true
+ -
+ name: Prénom
+ placeholder: Prénom
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Nom
+ placeholder: Nom
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Adresse mail'
+ placeholder: 'Adresse mail'
+ type: email
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Téléphone
+ placeholder: Téléphone
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Fonction
+ placeholder: Fonction
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: Société
+ placeholder: Société
+ type: text
+ size: long
+ classes: fancy
+ validate:
+ required: true
+ -
+ name: 'Votre profil'
+ placeholder: 'quel est votre profil'
+ autofocus: 'on'
+ autocomplete: 'on'
+ type: radio
+ size: long
+ classes: fancy
+ options:
+ Agence_evenementielle: 'Agence évènementielle'
+ associations: 'Associations (sociétés savantes, fédérations, syndicats) '
+ societes_entreprises: 'Sociétés / Entreprises'
+ Organismes_professionnels: 'Organismes professionnels'
+ validate:
+ required: true
+ buttons:
+ -
+ type: submit
+ value: Envoyer
+ process:
+ -
+ email:
+ from: '{{ config.plugins.email.from }}'
+ to:
+ - '{{ config.plugins.email.to }}'
+ - '{{ form.value.email }}'
+ subject: '[Feedback] {{ form.value.name|e }}'
+ body: '{% include ''forms/data.html.twig'' %}'
+ -
+ save:
+ fileprefix: feedback-
+ dateformat: Ymd-His-u
+ extension: txt
+ body: '{% include 'forms/data.txt.twig' %}'
+ -
+ message: Merci, votre demande de devis à bien été envoyé ! Elle sera traité dans les prochains jours.
+---
+
+Location de salles polyvalentes, amphitéâtre de 200 places, matériel performant dans toutes les salles, restauration de qualité bio ou locale sur demande...
+**Le Campus et son équipe à taille humaine vous garantit la réussite de votre séjour, de votre séminaire ou de votre événement.**
diff --git a/user/pages_offline/05.demande-de-devis/vue_ext.jpg b/user/pages_offline/05.demande-de-devis/vue_ext.jpg
new file mode 100644
index 0000000..413cd8d
Binary files /dev/null and b/user/pages_offline/05.demande-de-devis/vue_ext.jpg differ
diff --git a/user/themes/lecampus/scss/theme/_form3.scss b/user/themes/lecampus/scss/theme/_form3.scss
new file mode 100644
index 0000000..aaf0430
--- /dev/null
+++ b/user/themes/lecampus/scss/theme/_form3.scss
@@ -0,0 +1,119 @@
+.start#form{
+ .entete{
+ border-top: 1px solid $light-blue;
+ }
+ h2{
+ margin-top: 0;
+ }
+ .body-wrapper{
+ width: 100%;
+ min-width: 250px;
+ margin: auto auto 140px auto;
+ form{
+ width: calc( (100% / 2));
+ margin-top: 20px;
+ margin: auto;
+ & > .form-columns{
+ width: 100%;
+ margin: 20px 0;
+ & > .form-column.w-100{
+ & > .form-group{
+ width: 100%;
+ & > .form-data{
+ width: 100%;
+ & > .form-textarea-wrapper {
+ width: 100%;
+ textarea{
+ width: 100%;
+ resize: none;
+ border: none;
+ }
+ }
+ }
+ }
+ }
+ & > .form-column {
+ padding: 20px 0;
+ display: flex;
+ width: 100%;
+ &:not(:nth-last-child(1)){
+ border-bottom: 1px solid $red;
+ }
+ & > .form-group{
+ width: auto;
+ .form-data{
+ @include inlineflex();
+ margin: 0px 0px;
+ &> div{
+ overflow: hidden;
+ margin: 10px 10px;
+ min-width: 100px;
+ border: 2px solid $red;
+ border-radius: 30px;
+ padding: 10px 20px;
+ &.check{
+ background: $red;
+ color: white;
+ }
+ input{
+ border: none;
+ }
+ input[type='radio'] {
+ visibility: hidden;
+ position: absolute;
+ }
+ label{
+ cursor: pointer;
+ }
+ }
+ }
+
+ }
+ }
+ }
+ .button-wrapper{
+ background: $red;
+ height: 100px;
+ position: absolute;
+ left: 0;
+ width: 100%;
+ button{
+ margin-right: 25%;
+ position: absolute;
+ right: 0;
+ top: 50%;
+ -webkit-transform: translateY(-50%);
+ transform: translateY(-50%);
+ background: white;
+ border-radius: 30px;
+ padding: 10px 35px;
+ box-shadow:none;
+ border:0;
+ }
+ }
+ }
+ #send-valide{
+ -webkit-transform: translate(-50%, -50%);
+ transform: translate(-50%, -50%);
+ background: $red;
+ border-radius: 20px;
+ position: fixed;
+ width: 30%;
+ min-height: 30%;
+ left: 50%;
+ top: 50%;
+ padding: 50px;
+ .toast{
+ position: relative;
+ text-align: center;
+ color: white;
+ }
+ .ok{
+ color: white;
+ position: absolute;
+ right: 20px;
+ bottom: 20px;
+ }
+ }
+ }
+}
diff --git a/webserver-configs/htaccess.txt b/webserver-configs/htaccess.txt
index 83063ae..098c582 100644
--- a/webserver-configs/htaccess.txt
+++ b/webserver-configs/htaccess.txt
@@ -59,9 +59,9 @@ RewriteRule .* index.php [L]
# Block all direct access for these folders
RewriteRule ^(\.git|cache|bin|logs|backup|webserver-configs|tests)/(.*) error [F]
# Block access to specific file types for these system folders
-RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
+RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
# Block access to specific file types for these user folders
-RewriteRule ^(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
+RewriteRule ^(user)/(.*)\.(txt|md|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ error [F]
# Block all direct access to .md files:
RewriteRule \.md$ error [F]
# Block all direct access to files and folders beginning with a dot
diff --git a/webserver-configs/lighttpd.conf b/webserver-configs/lighttpd.conf
index 512362f..f14c5a8 100644
--- a/webserver-configs/lighttpd.conf
+++ b/webserver-configs/lighttpd.conf
@@ -33,7 +33,7 @@ $HTTP["url"] =~ "^/grav_path/(LICENSE\.txt|composer\.json|composer\.lock|nginx\.
$HTTP["url"] =~ "^/grav_path/(\.git|cache|bin|logs|backup|tests)/(.*)" {
url.access-deny = ("")
}
-$HTTP["url"] =~ "^/grav_path/(system|user|vendor)/(.*)\.(txt|md|html|yaml|yml|php|twig|sh|bat)$" {
+$HTTP["url"] =~ "^/grav_path/(system|user|vendor)/(.*)\.(txt|md|html|json|yaml|yml|php|twig|sh|bat)$" {
url.access-deny = ("")
}
$HTTP["url"] =~ "^/grav_path/(\.(.*))" {
diff --git a/webserver-configs/nginx.conf b/webserver-configs/nginx.conf
index bbca7d3..fc7d06b 100644
--- a/webserver-configs/nginx.conf
+++ b/webserver-configs/nginx.conf
@@ -20,9 +20,9 @@ server {
# deny all direct access for these folders
location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
# deny running scripts inside core system folders
- location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
+ location ~* /(system|vendor)/.*\.(txt|xml|md|html|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
# deny running scripts inside user folder
- location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
+ location ~* /user/.*\.(txt|md|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
# deny access to specific files in the root folder
location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
## End - Security
diff --git a/webserver-configs/web.config b/webserver-configs/web.config
index 892ce92..1c351a3 100644
--- a/webserver-configs/web.config
+++ b/webserver-configs/web.config
@@ -18,7 +18,7 @@
-
+
@@ -26,11 +26,11 @@
-
+
-
+