diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e67e47..c394dad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,144 @@
+# 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
+
+1. [](#new)
+ * Updated phpstan to v1.0
+ * Added `FlexObject::getDiff()` to see difference to the saved object
+2. [](#improved)
+ * Use Symfony `dump` instead of PHP's `vardump` in side the `{{ vardump(x) }}` Twig vardump function
+ * Added `route` and `request` to `onPagesInitialized` event
+ * Improved page cloning, added method `Page::initialize()`
+ * Improved `FlexObject::getChanges()`: return changed lists and arrays as whole instead of just changed keys/values
+ * Improved form validation JSON responses to contain list of failed fields with their error messages
+ * Improved redirects: send redirect response in JSON if the request was in JSON
+3. [](#bugfix)
+ * Fixed path traversal vulnerability when using `bin/grav server`
+ * Fixed unescaped error messages in JSON error responses
+ * Fixed `|t(variable)` twig filter in admin
+ * Fixed `FlexObject::getChanges()` always returning empty array
+ * Fixed form validation exceptions to use `400 Bad Request` instead of `500 Internal Server Error`
+
+# v1.7.24
+## 10/26/2021
+
+1. [](#new)
+ * Added support for image watermarks
+ * Added support to disable a form, making it readonly
+2. [](#improved)
+ * Flex `$user->authorize()` now checks user groups before `admin.super`, allowing deny rules to work properly
+3. [](#bugfix)
+ * Fixed a bug in `PermissionsReader` in PHP 7.3
+ * Fixed `session_store_active` language option (#3464)
+ * Fixed deprecated warnings on `ArrayAccess` in PHP 8.1
+ * Fixed XSS detection with `:`
+
# v1.7.23
## 09/29/2021
1. [](#new)
* Added method `Pages::referrerRoute()` to get the referrer route and language
* Added true unique `Utils::uniqueId()` / `{{ unique_id() }}` utilities with length, prefix, and suffix support
+ * Added `UserObject::isMyself()` method to check if flex user is currently logged in
+ * Added support for custom form field options validation with `validate: options: key|ignore`
2. [](#improved)
* Replaced GPL `SVG-Sanitizer` with MIT licensed `DOM-Sanitizer`
* `Uri::referrer()` now accepts third parameter, if set to `true`, it returns route without base or language code [#3411](https://github.com/getgrav/grav/issues/3411)
diff --git a/README.md b/README.md
index 31a4a7e..562726d 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,13 @@
[](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
@@ -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..9e58706 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 1 -c ./tests/phpstan/phpstan.neon --memory-limit=720M system/src",
+ "phpstan-framework": "vendor/bin/phpstan analyse -l 4 -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 68dc24c..2153094 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,68 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "23dd68cea2a3f2d963e57638131f1122",
+ "content-hash": "1067938388862c52927c6450e8a36df0",
"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.2.10",
+ "version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/composer/ca-bundle.git",
- "reference": "9fdb22c2e97a614657716178093cd1da90a64aa8"
+ "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/composer/ca-bundle/zipball/9fdb22c2e97a614657716178093cd1da90a64aa8",
- "reference": "9fdb22c2e97a614657716178093cd1da90a64aa8",
+ "url": "https://api.github.com/repos/composer/ca-bundle/zipball/4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b",
+ "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b",
"shasum": ""
},
"require": {
@@ -77,7 +29,7 @@
"phpstan/phpstan": "^0.12.55",
"psr/log": "^1.0",
"symfony/phpunit-bridge": "^4.2 || ^5",
- "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0"
+ "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
},
"type": "library",
"extra": {
@@ -112,7 +64,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/ca-bundle/issues",
- "source": "https://github.com/composer/ca-bundle/tree/1.2.10"
+ "source": "https://github.com/composer/ca-bundle/tree/1.3.1"
},
"funding": [
{
@@ -128,7 +80,7 @@
"type": "tidelift"
}
],
- "time": "2021-06-07T13:58:28+00:00"
+ "time": "2021-10-28T20:44:15+00:00"
},
{
"name": "composer/semver",
@@ -596,21 +548,21 @@
},
{
"name": "filp/whoops",
- "version": "2.14.3",
+ "version": "2.14.5",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
- "reference": "89584ce67dd32307f1063cc43846674f4679feda"
+ "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/filp/whoops/zipball/89584ce67dd32307f1063cc43846674f4679feda",
- "reference": "89584ce67dd32307f1063cc43846674f4679feda",
+ "url": "https://api.github.com/repos/filp/whoops/zipball/a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
+ "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
"shasum": ""
},
"require": {
"php": "^5.5.9 || ^7.0 || ^8.0",
- "psr/log": "^1.0.1"
+ "psr/log": "^1.0.1 || ^2.0 || ^3.0"
},
"require-dev": {
"mockery/mockery": "^0.9 || ^1.0",
@@ -655,7 +607,7 @@
],
"support": {
"issues": "https://github.com/filp/whoops/issues",
- "source": "https://github.com/filp/whoops/tree/2.14.3"
+ "source": "https://github.com/filp/whoops/tree/2.14.5"
},
"funding": [
{
@@ -663,7 +615,7 @@
"type": "github"
}
],
- "time": "2021-09-19T12:00:00+00:00"
+ "time": "2022-01-07T12:00:00+00:00"
},
{
"name": "getgrav/cache",
@@ -778,16 +730,16 @@
},
{
"name": "guzzlehttp/psr7",
- "version": "1.8.2",
+ "version": "1.8.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
- "reference": "dc960a912984efb74d0a90222870c72c87f10c91"
+ "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/psr7/zipball/dc960a912984efb74d0a90222870c72c87f10c91",
- "reference": "dc960a912984efb74d0a90222870c72c87f10c91",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85",
+ "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85",
"shasum": ""
},
"require": {
@@ -812,25 +764,46 @@
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\Psr7\\": "src/"
- },
"files": [
"src/functions_include.php"
- ]
+ ],
+ "psr-4": {
+ "GuzzleHttp\\Psr7\\": "src/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ },
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
+ {
+ "name": "George Mponos",
+ "email": "gmponos@gmail.com",
+ "homepage": "https://github.com/gmponos"
+ },
+ {
+ "name": "Tobias Nyholm",
+ "email": "tobias.nyholm@gmail.com",
+ "homepage": "https://github.com/Nyholm"
+ },
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com",
+ "homepage": "https://github.com/sagikazarmark"
+ },
{
"name": "Tobias Schultze",
+ "email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
@@ -847,28 +820,42 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
- "source": "https://github.com/guzzle/psr7/tree/1.8.2"
+ "source": "https://github.com/guzzle/psr7/tree/1.8.3"
},
- "time": "2021-04-26T09:17:50+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/GrahamCampbell",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/Nyholm",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-10-05T13:56:00+00:00"
},
{
"name": "itsgoingd/clockwork",
- "version": "v5.1.0",
+ "version": "v5.1.4",
"source": {
"type": "git",
"url": "https://github.com/itsgoingd/clockwork.git",
- "reference": "b963dee47429a49c9669981cfa9a8362ce209278"
+ "reference": "7252aa771b77ac8678b44290fd7ec7577435cce6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/b963dee47429a49c9669981cfa9a8362ce209278",
- "reference": "b963dee47429a49c9669981cfa9a8362ce209278",
+ "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/7252aa771b77ac8678b44290fd7ec7577435cce6",
+ "reference": "7252aa771b77ac8678b44290fd7ec7577435cce6",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=5.6",
- "psr/log": "1.*"
+ "psr/log": "1.* || ^2.0"
},
"type": "library",
"extra": {
@@ -910,7 +897,7 @@
],
"support": {
"issues": "https://github.com/itsgoingd/clockwork/issues",
- "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.0"
+ "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.4"
},
"funding": [
{
@@ -918,20 +905,20 @@
"type": "github"
}
],
- "time": "2021-08-07T23:04:17+00:00"
+ "time": "2022-01-30T12:36:18+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": {
@@ -981,9 +968,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",
@@ -1118,21 +1105,21 @@
},
{
"name": "maximebf/debugbar",
- "version": "v1.17.1",
+ "version": "v1.17.3",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
- "reference": "0a3532556be0145603f8a9de23e76dc28eed7054"
+ "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/0a3532556be0145603f8a9de23e76dc28eed7054",
- "reference": "0a3532556be0145603f8a9de23e76dc28eed7054",
+ "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e8ac3499af0ea5b440908e06cc0abe5898008b3c",
+ "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c",
"shasum": ""
},
"require": {
"php": "^7.1|^8",
- "psr/log": "^1.0",
+ "psr/log": "^1|^2|^3",
"symfony/var-dumper": "^2.6|^3|^4|^5"
},
"require-dev": {
@@ -1177,9 +1164,9 @@
],
"support": {
"issues": "https://github.com/maximebf/php-debugbar/issues",
- "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.1"
+ "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.3"
},
- "time": "2021-08-01T09:19:02+00:00"
+ "time": "2021-10-19T12:33:27+00:00"
},
{
"name": "miljar/php-exif",
@@ -1329,16 +1316,16 @@
},
{
"name": "nyholm/psr7",
- "version": "1.4.1",
+ "version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/Nyholm/psr7.git",
- "reference": "2212385b47153ea71b1c1b1374f8cb5e4f7892ec"
+ "reference": "1461e07a0f2a975a52082ca3b769ca912b816226"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Nyholm/psr7/zipball/2212385b47153ea71b1c1b1374f8cb5e4f7892ec",
- "reference": "2212385b47153ea71b1c1b1374f8cb5e4f7892ec",
+ "url": "https://api.github.com/repos/Nyholm/psr7/zipball/1461e07a0f2a975a52082ca3b769ca912b816226",
+ "reference": "1461e07a0f2a975a52082ca3b769ca912b816226",
"shasum": ""
},
"require": {
@@ -1390,7 +1377,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": [
{
@@ -1402,7 +1389,7 @@
"type": "github"
}
],
- "time": "2021-07-02T08:32:20+00:00"
+ "time": "2022-02-02T18:37:57+00:00"
},
{
"name": "nyholm/psr7-server",
@@ -1526,29 +1513,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": {
@@ -1573,9 +1560,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",
@@ -1628,27 +1615,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/"
@@ -1661,7 +1643,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)",
@@ -1675,9 +1657,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",
@@ -2048,16 +2030,16 @@
},
{
"name": "rhukster/dom-sanitizer",
- "version": "1.0.5",
+ "version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/rhukster/dom-sanitizer.git",
- "reference": "836d1dd9808adee0e4bb0ce4cdacc0f9a1497b7e"
+ "reference": "4db3ef1ac3d5505d044c5eb12aa106ba745bf129"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/rhukster/dom-sanitizer/zipball/836d1dd9808adee0e4bb0ce4cdacc0f9a1497b7e",
- "reference": "836d1dd9808adee0e4bb0ce4cdacc0f9a1497b7e",
+ "url": "https://api.github.com/repos/rhukster/dom-sanitizer/zipball/4db3ef1ac3d5505d044c5eb12aa106ba745bf129",
+ "reference": "4db3ef1ac3d5505d044c5eb12aa106ba745bf129",
"shasum": ""
},
"require": {
@@ -2087,22 +2069,22 @@
"description": "A simple but effective DOM/SVG/MathML Sanitizer for PHP 7.4+",
"support": {
"issues": "https://github.com/rhukster/dom-sanitizer/issues",
- "source": "https://github.com/rhukster/dom-sanitizer/tree/1.0.5"
+ "source": "https://github.com/rhukster/dom-sanitizer/tree/1.0.6"
},
- "time": "2021-09-29T20:14:54+00:00"
+ "time": "2021-09-30T15:41:33+00:00"
},
{
"name": "rockettheme/toolbox",
- "version": "1.5.10",
+ "version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/rockettheme/toolbox.git",
- "reference": "d9738de013fa12df77754a0f11dded220b246efb"
+ "reference": "a0eb328b9c416e526c8264b48ccbc1a7519e8618"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/rockettheme/toolbox/zipball/d9738de013fa12df77754a0f11dded220b246efb",
- "reference": "d9738de013fa12df77754a0f11dded220b246efb",
+ "url": "https://api.github.com/repos/rockettheme/toolbox/zipball/a0eb328b9c416e526c8264b48ccbc1a7519e8618",
+ "reference": "a0eb328b9c416e526c8264b48ccbc1a7519e8618",
"shasum": ""
},
"require": {
@@ -2110,12 +2092,14 @@
"php": ">=5.6.0",
"pimple/pimple": "~3.0",
"symfony/event-dispatcher": "^3.4|^4.0",
+ "symfony/polyfill-php80": "^1.23",
+ "symfony/polyfill-php81": "^1.23",
"symfony/yaml": "^3.4|^4.0"
},
"require-dev": {
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-deprecation-rules": "^0.12",
- "phpunit/phpunit": "~7.0"
+ "phpstan/phpstan": "^1.2",
+ "phpstan/phpstan-deprecation-rules": "^1.0",
+ "phpunit/phpunit": "^8.0"
},
"type": "library",
"autoload": {
@@ -2129,7 +2113,10 @@
"RocketTheme\\Toolbox\\ResourceLocator\\": "ResourceLocator/src",
"RocketTheme\\Toolbox\\Session\\": "Session/src",
"RocketTheme\\Toolbox\\StreamWrapper\\": "StreamWrapper/src"
- }
+ },
+ "exclude-from-classmap": [
+ "**/tests/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2143,9 +2130,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.0"
},
- "time": "2021-09-29T16:50:13+00:00"
+ "time": "2021-12-15T19:20:00+00:00"
},
{
"name": "seld/cli-prompt",
@@ -2204,16 +2191,16 @@
},
{
"name": "symfony/console",
- "version": "v4.4.30",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "a3f7189a0665ee33b50e9e228c46f50f5acbed22"
+ "reference": "0259f01dbf9d77badddbbf4c2abb681f24c9cac6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/a3f7189a0665ee33b50e9e228c46f50f5acbed22",
- "reference": "a3f7189a0665ee33b50e9e228c46f50f5acbed22",
+ "url": "https://api.github.com/repos/symfony/console/zipball/0259f01dbf9d77badddbbf4c2abb681f24c9cac6",
+ "reference": "0259f01dbf9d77badddbbf4c2abb681f24c9cac6",
"shasum": ""
},
"require": {
@@ -2274,7 +2261,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.30"
+ "source": "https://github.com/symfony/console/tree/v4.4.37"
},
"funding": [
{
@@ -2290,25 +2277,25 @@
"type": "tidelift"
}
],
- "time": "2021-08-25T19:27:26+00:00"
+ "time": "2022-01-26T16:15:26+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": {
@@ -2332,7 +2319,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.1-dev"
+ "dev-main": "1.1-dev"
}
},
"autoload": {
@@ -2368,7 +2355,7 @@
"standards"
],
"support": {
- "source": "https://github.com/symfony/contracts/tree/v1.1.10"
+ "source": "https://github.com/symfony/contracts/tree/v1.1.11"
},
"funding": [
{
@@ -2384,20 +2371,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": {
@@ -2452,7 +2439,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": [
{
@@ -2468,20 +2455,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.31",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-client.git",
- "reference": "6b900ffa399e25203f30f79f6f4a56b89eee14c2"
+ "reference": "8129ccd6233338e1d495b7734c003053766cb262"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/http-client/zipball/6b900ffa399e25203f30f79f6f4a56b89eee14c2",
- "reference": "6b900ffa399e25203f30f79f6f4a56b89eee14c2",
+ "url": "https://api.github.com/repos/symfony/http-client/zipball/8129ccd6233338e1d495b7734c003053766cb262",
+ "reference": "8129ccd6233338e1d495b7734c003053766cb262",
"shasum": ""
},
"require": {
@@ -2533,7 +2520,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.31"
+ "source": "https://github.com/symfony/http-client/tree/v4.4.37"
},
"funding": [
{
@@ -2549,25 +2536,28 @@
"type": "tidelift"
}
],
- "time": "2021-09-06T10:00:00+00:00"
+ "time": "2022-01-19T13:29:07+00:00"
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.23.0",
+ "version": "v1.24.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"
},
@@ -2612,7 +2602,7 @@
"portable"
],
"support": {
- "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0"
},
"funding": [
{
@@ -2628,25 +2618,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.24.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"
},
@@ -2661,12 +2654,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Iconv\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Iconv\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2692,7 +2685,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-iconv/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-iconv/tree/v1.24.0"
},
"funding": [
{
@@ -2708,25 +2701,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.24.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"
},
@@ -2772,7 +2768,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0"
},
"funding": [
{
@@ -2788,11 +2784,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.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php74.git",
@@ -2818,12 +2814,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Php74\\": ""
- },
"files": [
"bootstrap.php"
- ]
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php74\\": ""
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -2852,7 +2848,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-php74/tree/v1.23.0"
+ "source": "https://github.com/symfony/polyfill-php74/tree/v1.24.0"
},
"funding": [
{
@@ -2872,16 +2868,16 @@
},
{
"name": "symfony/polyfill-php80",
- "version": "v1.23.1",
+ "version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
- "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be"
+ "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9"
},
"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/57b712b08eddb97c762a8caa32c84e037892d2e9",
+ "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9",
"shasum": ""
},
"require": {
@@ -2898,12 +2894,12 @@
}
},
"autoload": {
- "psr-4": {
- "Symfony\\Polyfill\\Php80\\": ""
- },
"files": [
"bootstrap.php"
],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php80\\": ""
+ },
"classmap": [
"Resources/stubs"
]
@@ -2935,7 +2931,7 @@
"shim"
],
"support": {
- "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1"
+ "source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0"
},
"funding": [
{
@@ -2951,20 +2947,99 @@
"type": "tidelift"
}
],
- "time": "2021-07-28T13:41:28+00:00"
+ "time": "2021-09-13T13:58:33+00:00"
},
{
- "name": "symfony/process",
- "version": "v4.4.30",
+ "name": "symfony/polyfill-php81",
+ "version": "v1.24.0",
"source": {
"type": "git",
- "url": "https://github.com/symfony/process.git",
- "reference": "13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d"
+ "url": "https://github.com/symfony/polyfill-php81.git",
+ "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/process/zipball/13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d",
- "reference": "13d3161ef63a8ec21eeccaaf9a4d7f784a87a97d",
+ "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/5de4ba2d41b15f9bd0e19b2ab9674135813ec98f",
+ "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "1.23-dev"
+ },
+ "thanks": {
+ "name": "symfony/polyfill",
+ "url": "https://github.com/symfony/polyfill"
+ }
+ },
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Php81\\": ""
+ },
+ "classmap": [
+ "Resources/stubs"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "support": {
+ "source": "https://github.com/symfony/polyfill-php81/tree/v1.24.0"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-09-13T13:58:11+00:00"
+ },
+ {
+ "name": "symfony/process",
+ "version": "v4.4.37",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/process.git",
+ "reference": "b2d924e5a4cb284f293d5092b1dbf0d364cb8b67"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/process/zipball/b2d924e5a4cb284f293d5092b1dbf0d364cb8b67",
+ "reference": "b2d924e5a4cb284f293d5092b1dbf0d364cb8b67",
"shasum": ""
},
"require": {
@@ -2997,7 +3072,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": [
{
@@ -3013,20 +3088,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.31",
+ "version": "v4.4.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-dumper.git",
- "reference": "1f12cc0c2e880a5f39575c19af81438464717839"
+ "reference": "e74eee4ec02de71db3d60151aa5b203c990556df"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/var-dumper/zipball/1f12cc0c2e880a5f39575c19af81438464717839",
- "reference": "1f12cc0c2e880a5f39575c19af81438464717839",
+ "url": "https://api.github.com/repos/symfony/var-dumper/zipball/e74eee4ec02de71db3d60151aa5b203c990556df",
+ "reference": "e74eee4ec02de71db3d60151aa5b203c990556df",
"shasum": ""
},
"require": {
@@ -3086,7 +3161,7 @@
"dump"
],
"support": {
- "source": "https://github.com/symfony/var-dumper/tree/v4.4.31"
+ "source": "https://github.com/symfony/var-dumper/tree/v4.4.37"
},
"funding": [
{
@@ -3102,20 +3177,20 @@
"type": "tidelift"
}
],
- "time": "2021-09-24T15:30:11+00:00"
+ "time": "2022-01-02T09:41:36+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": {
@@ -3157,7 +3232,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": [
{
@@ -3173,20 +3248,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": {
@@ -3239,7 +3314,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": [
{
@@ -3251,20 +3326,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": {
@@ -3305,33 +3380,32 @@
],
"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": [
{
"name": "behat/gherkin",
- "version": "v4.8.0",
+ "version": "v4.9.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Gherkin.git",
- "reference": "2391482cd003dfdc36b679b27e9f5326bd656acd"
+ "reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Behat/Gherkin/zipball/2391482cd003dfdc36b679b27e9f5326bd656acd",
- "reference": "2391482cd003dfdc36b679b27e9f5326bd656acd",
+ "url": "https://api.github.com/repos/Behat/Gherkin/zipball/0bc8d1e30e96183e4f36db9dc79caead300beff4",
+ "reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4",
"shasum": ""
},
"require": {
"php": "~7.2|~8.0"
},
"require-dev": {
- "cucumber/cucumber": "dev-gherkin-16.0.0",
+ "cucumber/cucumber": "dev-gherkin-22.0.0",
"phpunit/phpunit": "~8|~9",
- "symfony/phpunit-bridge": "~3|~4|~5",
"symfony/yaml": "~3|~4|~5"
},
"suggest": {
@@ -3340,7 +3414,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.4-dev"
+ "dev-master": "4.x-dev"
}
},
"autoload": {
@@ -3371,29 +3445,29 @@
],
"support": {
"issues": "https://github.com/Behat/Gherkin/issues",
- "source": "https://github.com/Behat/Gherkin/tree/v4.8.0"
+ "source": "https://github.com/Behat/Gherkin/tree/v4.9.0"
},
- "time": "2021-02-04T12:44:21+00:00"
+ "time": "2021-10-12T13:05:09+00:00"
},
{
"name": "codeception/codeception",
- "version": "4.1.22",
+ "version": "4.1.29",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
- "reference": "9777ec3690ceedc4bce2ed13af7af4ca4ee3088f"
+ "reference": "f8dec8f2bf5347cc596aaf141753f4fb2504c17c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Codeception/Codeception/zipball/9777ec3690ceedc4bce2ed13af7af4ca4ee3088f",
- "reference": "9777ec3690ceedc4bce2ed13af7af4ca4ee3088f",
+ "url": "https://api.github.com/repos/Codeception/Codeception/zipball/f8dec8f2bf5347cc596aaf141753f4fb2504c17c",
+ "reference": "f8dec8f2bf5347cc596aaf141753f4fb2504c17c",
"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": "*",
@@ -3406,11 +3480,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",
@@ -3433,6 +3507,9 @@
"branch-alias": []
},
"autoload": {
+ "files": [
+ "functions.php"
+ ],
"psr-4": {
"Codeception\\": "src/Codeception",
"Codeception\\Extension\\": "ext"
@@ -3460,7 +3537,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.29"
},
"funding": [
{
@@ -3468,7 +3545,7 @@
"type": "open_collective"
}
],
- "time": "2021-08-06T17:15:34+00:00"
+ "time": "2022-01-29T16:56:03+00:00"
},
{
"name": "codeception/lib-asserts",
@@ -3703,16 +3780,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": {
@@ -3746,9 +3823,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",
@@ -3907,24 +3984,25 @@
},
{
"name": "guzzlehttp/guzzle",
- "version": "7.3.0",
+ "version": "7.4.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "7008573787b430c1c1f650e3722d9bba59967628"
+ "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628",
- "reference": "7008573787b430c1c1f650e3722d9bba59967628",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79",
+ "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79",
"shasum": ""
},
"require": {
"ext-json": "*",
- "guzzlehttp/promises": "^1.4",
- "guzzlehttp/psr7": "^1.7 || ^2.0",
+ "guzzlehttp/promises": "^1.5",
+ "guzzlehttp/psr7": "^1.8.3 || ^2.1",
"php": "^7.2.5 || ^8.0",
- "psr/http-client": "^1.0"
+ "psr/http-client": "^1.0",
+ "symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
@@ -3934,7 +4012,7 @@
"ext-curl": "*",
"php-http/client-integration-tests": "^3.0",
"phpunit/phpunit": "^8.5.5 || ^9.3.5",
- "psr/log": "^1.1"
+ "psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
@@ -3944,7 +4022,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "7.3-dev"
+ "dev-master": "7.4-dev"
}
},
"autoload": {
@@ -3960,19 +4038,43 @@
"MIT"
],
"authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ },
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
+ {
+ "name": "Jeremy Lindblom",
+ "email": "jeremeamia@gmail.com",
+ "homepage": "https://github.com/jeremeamia"
+ },
+ {
+ "name": "George Mponos",
+ "email": "gmponos@gmail.com",
+ "homepage": "https://github.com/gmponos"
+ },
+ {
+ "name": "Tobias Nyholm",
+ "email": "tobias.nyholm@gmail.com",
+ "homepage": "https://github.com/Nyholm"
+ },
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
- "homepage": "https://sagikazarmark.hu"
+ "homepage": "https://github.com/sagikazarmark"
+ },
+ {
+ "name": "Tobias Schultze",
+ "email": "webmaster@tubo-world.de",
+ "homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
- "homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
@@ -3986,7 +4088,7 @@
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
- "source": "https://github.com/guzzle/guzzle/tree/7.3.0"
+ "source": "https://github.com/guzzle/guzzle/tree/7.4.1"
},
"funding": [
{
@@ -3998,28 +4100,24 @@
"type": "github"
},
{
- "url": "https://github.com/alexeyshockov",
- "type": "github"
- },
- {
- "url": "https://github.com/gmponos",
- "type": "github"
+ "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
+ "type": "tidelift"
}
],
- "time": "2021-03-23T11:33:13+00:00"
+ "time": "2021-12-06T18:43:05+00:00"
},
{
"name": "guzzlehttp/promises",
- "version": "1.4.1",
+ "version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
- "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d"
+ "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d",
- "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
+ "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"shasum": ""
},
"require": {
@@ -4031,7 +4129,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.4-dev"
+ "dev-master": "1.5-dev"
}
},
"autoload": {
@@ -4047,10 +4145,25 @@
"MIT"
],
"authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ },
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Tobias Nyholm",
+ "email": "tobias.nyholm@gmail.com",
+ "homepage": "https://github.com/Nyholm"
+ },
+ {
+ "name": "Tobias Schultze",
+ "email": "webmaster@tubo-world.de",
+ "homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
@@ -4059,9 +4172,23 @@
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
- "source": "https://github.com/guzzle/promises/tree/1.4.1"
+ "source": "https://github.com/guzzle/promises/tree/1.5.1"
},
- "time": "2021-03-07T09:25:29+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/GrahamCampbell",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/Nyholm",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-10-22T20:56:57+00:00"
},
{
"name": "myclabs/deep-copy",
@@ -4080,9 +4207,6 @@
"require": {
"php": "^7.1 || ^8.0"
},
- "replace": {
- "myclabs/deep-copy": "self.version"
- },
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/common": "^2.6",
@@ -4090,12 +4214,12 @@
},
"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": [
@@ -4123,16 +4247,16 @@
},
{
"name": "nikic/php-parser",
- "version": "v4.13.0",
+ "version": "v4.13.2",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "50953a2691a922aa1769461637869a0a2faa3f53"
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53",
- "reference": "50953a2691a922aa1769461637869a0a2faa3f53",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077",
+ "reference": "210577fe3cf7badcc5814d99455df46564f3c077",
"shasum": ""
},
"require": {
@@ -4173,9 +4297,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2"
},
- "time": "2021-09-20T12:20:58+00:00"
+ "time": "2021-11-30T19:35:32+00:00"
},
{
"name": "phar-io/manifest",
@@ -4343,16 +4467,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
- "version": "5.2.2",
+ "version": "5.3.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
- "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556"
+ "reference": "622548b623e81ca6d78b721c5e029f4ce664f170"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556",
- "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170",
+ "reference": "622548b623e81ca6d78b721c5e029f4ce664f170",
"shasum": ""
},
"require": {
@@ -4363,7 +4487,8 @@
"webmozart/assert": "^1.9.1"
},
"require-dev": {
- "mockery/mockery": "~1.3.2"
+ "mockery/mockery": "~1.3.2",
+ "psalm/phar": "^4.8"
},
"type": "library",
"extra": {
@@ -4393,22 +4518,22 @@
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
- "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master"
+ "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0"
},
- "time": "2020-09-03T19:13:55+00:00"
+ "time": "2021-10-19T17:43:47+00:00"
},
{
"name": "phpdocumentor/type-resolver",
- "version": "1.5.0",
+ "version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
- "reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f"
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30f38bffc6f24293dadd1823936372dfa9e86e2f",
- "reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
+ "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"shasum": ""
},
"require": {
@@ -4443,22 +4568,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.0"
+ "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
},
- "time": "2021-09-17T15:28:14+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": {
@@ -4510,22 +4635,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": "0.12.99",
+ "version": "1.4.6",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
- "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7"
+ "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7",
- "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8a7761f1c520e0dad6e04d862fdc697445457cfe",
+ "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe",
"shasum": ""
},
"require": {
@@ -4541,7 +4666,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "0.12-dev"
+ "dev-master": "1.4-dev"
}
},
"autoload": {
@@ -4556,7 +4681,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
- "source": "https://github.com/phpstan/phpstan/tree/0.12.99"
+ "source": "https://github.com/phpstan/phpstan/tree/1.4.6"
},
"funding": [
{
@@ -4576,36 +4701,35 @@
"type": "tidelift"
}
],
- "time": "2021-09-12T20:09:55+00:00"
+ "time": "2022-02-06T12:56:13+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
- "version": "0.12.6",
+ "version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
- "reference": "46dbd43c2db973d2876d6653e53f5c2cc3a01fbb"
+ "reference": "e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/46dbd43c2db973d2876d6653e53f5c2cc3a01fbb",
- "reference": "46dbd43c2db973d2876d6653e53f5c2cc3a01fbb",
+ "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682",
+ "reference": "e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0",
- "phpstan/phpstan": "^0.12.60"
+ "phpstan/phpstan": "^1.0"
},
"require-dev": {
- "phing/phing": "^2.16.3",
"php-parallel-lint/php-parallel-lint": "^1.2",
- "phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^7.5.20"
+ "phpstan/phpstan-phpunit": "^1.0",
+ "phpunit/phpunit": "^9.5"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
- "dev-master": "0.12-dev"
+ "dev-master": "1.0-dev"
},
"phpstan": {
"includes": [
@@ -4625,29 +4749,29 @@
"description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
"support": {
"issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
- "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/0.12.6"
+ "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.0.0"
},
- "time": "2020-12-13T10:20:54+00:00"
+ "time": "2021-09-23T11:02:21+00:00"
},
{
"name": "phpunit/php-code-coverage",
- "version": "9.2.7",
+ "version": "9.2.10",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "d4c798ed8d51506800b441f7a13ecb0f76f12218"
+ "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d4c798ed8d51506800b441f7a13ecb0f76f12218",
- "reference": "d4c798ed8d51506800b441f7a13ecb0f76f12218",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687",
+ "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
- "nikic/php-parser": "^4.12.0",
+ "nikic/php-parser": "^4.13.0",
"php": ">=7.3",
"phpunit/php-file-iterator": "^3.0.3",
"phpunit/php-text-template": "^2.0.2",
@@ -4696,7 +4820,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.7"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10"
},
"funding": [
{
@@ -4704,20 +4828,20 @@
"type": "github"
}
],
- "time": "2021-09-17T05:39:03+00:00"
+ "time": "2021-12-05T09:12:13+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": {
@@ -4756,7 +4880,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": [
{
@@ -4764,7 +4888,7 @@
"type": "github"
}
],
- "time": "2020-09-28T05:57:25+00:00"
+ "time": "2021-12-02T12:48:52+00:00"
},
{
"name": "phpunit/php-invoker",
@@ -4949,16 +5073,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.10",
+ "version": "9.5.13",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a"
+ "reference": "597cb647654ede35e43b137926dfdfef0fb11743"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
- "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/597cb647654ede35e43b137926dfdfef0fb11743",
+ "reference": "597cb647654ede35e43b137926dfdfef0fb11743",
"shasum": ""
},
"require": {
@@ -5036,11 +5160,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.13"
},
"funding": [
{
- "url": "https://phpunit.de/donate.html",
+ "url": "https://phpunit.de/sponsors.html",
"type": "custom"
},
{
@@ -5048,7 +5172,7 @@
"type": "github"
}
],
- "time": "2021-09-25T07:38:51+00:00"
+ "time": "2022-01-24T07:33:35+00:00"
},
{
"name": "psr/http-client",
@@ -5531,16 +5655,16 @@
},
{
"name": "sebastian/exporter",
- "version": "4.0.3",
+ "version": "4.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65"
+ "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65",
- "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9",
+ "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9",
"shasum": ""
},
"require": {
@@ -5589,14 +5713,14 @@
}
],
"description": "Provides the functionality to export PHP variables for visualization",
- "homepage": "http://www.github.com/sebastianbergmann/exporter",
+ "homepage": "https://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
- "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3"
+ "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4"
},
"funding": [
{
@@ -5604,7 +5728,7 @@
"type": "github"
}
],
- "time": "2020-09-28T05:24:23+00:00"
+ "time": "2021-11-11T14:18:36+00:00"
},
{
"name": "sebastian/global-state",
@@ -6068,28 +6192,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": ""
@@ -6120,7 +6244,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": [
{
@@ -6136,20 +6260,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": {
@@ -6186,7 +6310,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": [
{
@@ -6202,20 +6326,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": {
@@ -6224,7 +6348,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "2.4-dev"
+ "dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -6253,7 +6377,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": [
{
@@ -6269,25 +6393,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.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
- "reference": "c7eef3a60ccfdd8eafe07f81652e769ac9c7146c"
+ "reference": "2634381fdf27a2a0a8ac8eb404025eb656c65d0c"
},
"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/2634381fdf27a2a0a8ac8eb404025eb656c65d0c",
+ "reference": "2634381fdf27a2a0a8ac8eb404025eb656c65d0c",
"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"
@@ -6297,7 +6421,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": ""
@@ -6328,7 +6452,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.3"
},
"funding": [
{
@@ -6344,24 +6468,25 @@
"type": "tidelift"
}
],
- "time": "2021-08-29T19:32:13+00:00"
+ "time": "2022-01-02T09:53:40+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",
@@ -6390,7 +6515,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": [
{
@@ -6406,7 +6531,7 @@
"type": "tidelift"
}
],
- "time": "2021-08-04T21:20:46+00:00"
+ "time": "2022-01-26T16:34:36+00:00"
},
{
"name": "theseer/tokenizer",
@@ -6535,5 +6660,5 @@
"platform-overrides": {
"php": "7.3.6"
},
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.2.0"
}
diff --git a/index.php b/index.php
index 091e9a8..3e30831 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;
diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml
index dffe099..b6beb41 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
@@ -1446,6 +1509,10 @@ form:
title: PLUGIN_ADMIN.ADVANCED
underline: true
+ gpm_section:
+ type: section
+ title: PLUGIN_ADMIN.GPM_SECTION
+
gpm.releases:
type: toggle
label: PLUGIN_ADMIN.GPM_RELEASES
@@ -1455,23 +1522,6 @@ form:
stable: PLUGIN_ADMIN.STABLE
testing: PLUGIN_ADMIN.TESTING
- gpm.proxy_url:
- type: text
- size: medium
- placeholder: "e.g. 127.0.0.1:3128"
- label: PLUGIN_ADMIN.PROXY_URL
- help: PLUGIN_ADMIN.PROXY_URL_HELP
-
- gpm.method:
- type: toggle
- label: PLUGIN_ADMIN.GPM_METHOD
- highlight: auto
- help: PLUGIN_ADMIN.GPM_METHOD_HELP
- options:
- auto: PLUGIN_ADMIN.AUTO
- fopen: PLUGIN_ADMIN.FOPEN
- curl: PLUGIN_ADMIN.CURL
-
gpm.official_gpm_only:
type: toggle
label: PLUGIN_ADMIN.GPM_OFFICIAL_ONLY
@@ -1484,17 +1534,80 @@ form:
validate:
type: bool
- gpm.verify_peer:
+ http_section:
+ type: section
+ title: PLUGIN_ADMIN.HTTP_SECTION
+
+ http.method:
type: toggle
- label: PLUGIN_ADMIN.GPM_VERIFY_PEER
+ label: PLUGIN_ADMIN.GPM_METHOD
+ highlight: auto
+ help: PLUGIN_ADMIN.GPM_METHOD_HELP
+ options:
+ auto: PLUGIN_ADMIN.AUTO
+ fopen: PLUGIN_ADMIN.FOPEN
+ curl: PLUGIN_ADMIN.CURL
+
+ http.enable_proxy:
+ type: toggle
+ label: PLUGIN_ADMIN.SSL_ENABLE_PROXY
highlight: 1
- help: PLUGIN_ADMIN.GPM_VERIFY_PEER_HELP
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ default: false
+ validate:
+ type: bool
+
+ http.proxy_url:
+ type: text
+ size: medium
+ placeholder: "e.g. 127.0.0.1:3128"
+ label: PLUGIN_ADMIN.PROXY_URL
+ help: PLUGIN_ADMIN.PROXY_URL_HELP
+
+ http.proxy_cert_path:
+ type: text
+ size: medium
+ placeholder: "e.g. /Users/bob/certs/"
+ label: PLUGIN_ADMIN.PROXY_CERT
+ help: PLUGIN_ADMIN.PROXY_CERT_HELP
+
+ http.verify_peer:
+ type: toggle
+ label: PLUGIN_ADMIN.SSL_VERIFY_PEER
+ highlight: 1
+ help: PLUGIN_ADMIN.SSL_VERIFY_PEER_HELP
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
+ http.verify_host:
+ type: toggle
+ label: PLUGIN_ADMIN.SSL_VERIFY_HOST
+ highlight: 1
+ help: PLUGIN_ADMIN.SSL_VERIFY_HOST_HELP
+ options:
+ 1: PLUGIN_ADMIN.YES
+ 0: PLUGIN_ADMIN.NO
+ validate:
+ type: bool
+
+ http.concurrent_connections:
+ type: number
+ size: x-small
+ label: PLUGIN_ADMIN.HTTP_CONNECTIONS
+ help: PLUGIN_ADMIN.HTTP_CONNECTIONS_HELP
+ validate:
+ min: 1
+ max: 20
+
+ misc_section:
+ type: section
+ title: PLUGIN_ADMIN.MISC_SECTION
+
reverse_proxy_setup:
type: toggle
label: PLUGIN_ADMIN.REVERSE_PROXY
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..cfe5376 100644
--- a/system/blueprints/user/account.yaml
+++ b/system/blueprints/user/account.yaml
@@ -107,6 +107,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 fb5f391..2de075b 100644
--- a/system/config/system.yaml
+++ b/system/config/system.yaml
@@ -96,7 +96,7 @@ cache:
purge_at: '0 4 * * *' # How often to purge old file cache (using new scheduler)
clear_at: '0 3 * * *' # How often to clear cache (using new scheduler)
clear_job_type: 'standard' # Type to clear when processing the scheduled clear job `standard`|`all`
- clear_images_by_default: false # By default grav does not include processed images in cache clear, this can be enabled
+ clear_images_by_default: false # By default grav does not include processed images in cache clear, this can be enabled
cli_compatibility: false # Ensures only non-volatile drivers are used (file, redis, memcache, etc.)
lifetime: 604800 # Lifetime of cached data in seconds (0 = infinite)
gzip: false # GZip compress the page output
@@ -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
@@ -162,6 +165,12 @@ images:
retina_scale: 1 # scale to adjust auto-sizes for better handling of HiDPI resolutions
defaults:
loading: auto # Let browser pick [auto|lazy|eager]
+ watermark:
+ image: 'system://images/watermark.png' # Path to a watermark image
+ position_y: 'center' # top|center|bottom
+ position_x: 'center' # left|center|right
+ scale: 33 # percentage of watermark scale
+ watermark_all: false # automatically watermark all images
media:
enable_media_timestamp: false # Enable media timestamps
@@ -176,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)
@@ -184,11 +194,17 @@ session:
gpm:
releases: stable # Set to either 'stable' or 'testing'
- proxy_url: # Configure a manual proxy URL for GPM (eg 127.0.0.1:3128)
- method: 'auto' # Either 'curl', 'fopen' or 'auto'. 'auto' will try fopen first and if not available cURL
- verify_peer: true # Sometimes on some systems (Windows most commonly) GPM is unable to connect because the SSL certificate cannot be verified. Disabling this setting might help.
official_gpm_only: true # By default GPM direct-install will only allow URLs via the official GPM proxy to ensure security
+http:
+ method: auto # Either 'curl', 'fopen' or 'auto'. 'auto' will try fopen first and if not available cURL
+ enable_proxy: true # Enable proxy server configuration
+ proxy_url: # Configure a manual proxy URL for GPM (eg 127.0.0.1:3128)
+ proxy_cert_path: # Local path to proxy certificate folder containing pem files
+ concurrent_connections: 5 # Concurrent HTTP connections when multiplexing
+ verify_peer: true # Enable/Disable SSL verification of peer certificates
+ verify_host: true # Enable/Disable SSL verification of host certificates
+
accounts:
type: regular # EXPERIMENTAL: Account type: regular or flex
storage: file # EXPERIMENTAL: Flex storage type: file or folder
diff --git a/system/defines.php b/system/defines.php
index e3cbb36..39dd692 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.23');
+define('GRAV_VERSION', '1.7.30');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);
diff --git a/system/images/watermark.png b/system/images/watermark.png
new file mode 100644
index 0000000..0f38a75
Binary files /dev/null and b/system/images/watermark.png differ
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 187d4d8..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.
*/
@@ -13,8 +13,25 @@ if (PHP_SAPI !== 'cli-server') {
$_SERVER['PHP_CLI_ROUTER'] = true;
-if (is_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_NAME'])) {
- return false;
+$root = $_SERVER['DOCUMENT_ROOT'];
+$path = $_SERVER['SCRIPT_NAME'];
+if ($path !== '/index.php' && is_file($root . $path)) {
+ if (!(
+ // Block all direct access to files and folders beginning with a dot
+ strpos($path, '/.') !== false
+ // 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|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|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
+ || preg_match('`^/(LICENSE\.txt|composer\.lock|composer\.json|\.htaccess)$`ui', $path)
+ )) {
+ return false;
+ }
}
$grav_index = 'index.php';
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..134c62f 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.
*/
@@ -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 = [];
@@ -184,7 +198,7 @@ class Assets extends PropertyObject
call_user_func_array([$this, 'add'], $args);
} else {
// Get extension
- $extension = pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION);
+ $extension = Utils::pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION);
// JavaScript or CSS
if ($extension !== '') {
@@ -193,6 +207,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 +238,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 +246,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 +287,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 +337,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 +447,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 +479,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 +511,58 @@ 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 $group
+ * @param $attributes
+ * @return string
+ */
+ public function jsModule($group = 'head', $attributes = [])
+ {
+ return $this->render(self::JS_MODULE, $group, $attributes);
+ }
+
+ 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;
+ }
+
+ protected function isValidType($type)
+ {
+ return in_array($type, [self::CSS_TYPE, self::JS_TYPE, self::JS_MODULE_TYPE]);
+ }
+
+ 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..798bdd3
--- /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 $groups
+ * @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 b70def9..9c23908 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.
*/
@@ -105,7 +105,7 @@ 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)));
+ $download = urlencode(base64_encode(Utils::basename($backup)));
$url = rtrim(Grav::instance()['uri']->rootUrl(true), '/') . '/' . trim(
$base_url,
'/'
@@ -144,9 +144,8 @@ class Backups
public static function getTotalBackupsSize()
{
$backups = static::getAvailableBackups();
- $size = array_sum(array_column($backups, 'size'));
- return $size ?? 0;
+ 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 7990bec..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.
*/
@@ -83,7 +83,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
}
if (!empty($messages)) {
- throw (new ValidationException())->setMessages($messages);
+ throw (new ValidationException('', 400))->setMessages($messages);
}
}
@@ -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));
}
/**
@@ -199,7 +205,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
/** @var Config $config */
$config = Grav::instance()['config'];
if (!$config->get('system.strict_mode.blueprint_strict_compat', true)) {
- throw new RuntimeException(sprintf('%s is not defined in blueprints', $key));
+ throw new RuntimeException(sprintf('%s is not defined in blueprints', $key), 400);
}
user_error(sprintf('Having extra key %s in your data is deprecated with blueprint having \'validation: strict\'', $key), E_USER_DEPRECATED);
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 c5b21ff..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.
*/
@@ -781,14 +781,22 @@ class Validation
}
// If creating new values is allowed, no further checks are needed.
- if (!empty($field['selectize']['create'])) {
+ $validateOptions = $field['validate']['options'] ?? null;
+ if (!empty($field['selectize']['create']) || $validateOptions === 'ignore') {
return true;
}
$options = $field['options'] ?? [];
$use = $field['use'] ?? 'values';
- if (empty($field['selectize']) || empty($field['multiple'])) {
+ if ($validateOptions) {
+ // Use custom options structure.
+ foreach ($options as &$option) {
+ $option = $option[$validateOptions] ?? null;
+ }
+ unset($option);
+ $options = array_values($options);
+ } elseif (empty($field['selectize']) || empty($field['multiple'])) {
$options = array_keys($options);
}
if ($use === 'keys') {
@@ -808,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 2d94ab8..9a3d900 100644
--- a/system/src/Grav/Common/Data/ValidationException.php
+++ b/system/src/Grav/Common/Data/ValidationException.php
@@ -3,23 +3,25 @@
/**
* @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.
*/
namespace Grav\Common\Data;
use Grav\Common\Grav;
+use JsonSerializable;
use RuntimeException;
/**
* Class ValidationException
* @package Grav\Common\Data
*/
-class ValidationException extends RuntimeException
+class ValidationException extends RuntimeException implements JsonSerializable
{
/** @var array */
protected $messages = [];
+ protected $escape = true;
/**
* @param array $messages
@@ -32,21 +34,34 @@ class ValidationException extends RuntimeException
$language = Grav::instance()['language'];
$this->message = $language->translate('GRAV.FORM.VALIDATION_FAIL', null, true) . ' ' . $this->message;
- foreach ($messages as $variable => &$list) {
+ foreach ($messages as $list) {
$list = array_unique($list);
foreach ($list as $message) {
- $this->message .= "
$message";
+ $this->message .= '
' . htmlspecialchars($message, ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
}
return $this;
}
+ public function setSimpleMessage(bool $escape = true): void
+ {
+ $first = reset($this->messages);
+ $message = reset($first);
+
+ $this->message = $escape ? htmlspecialchars($message, ENT_QUOTES | ENT_HTML5, 'UTF-8') : $message;
+ }
+
/**
* @return array
*/
- public function getMessages()
+ public function getMessages(): array
{
return $this->messages;
}
+
+ public function jsonSerialize(): array
+ {
+ return ['validation' => $this->messages];
+ }
}
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 f02a648..c0ca5c4 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)
{
@@ -554,6 +564,9 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$filters = array_filter($filters, static function($val) { return $val !== null && $val !== ''; });
if ($page) {
+ $status = 'success';
+ $msg = 'PLUGIN_ADMIN.PAGE_ROUTE_FOUND';
+
if ($page->root() && (!$filter_type || in_array('root', $filter_type, true))) {
if ($field) {
$response[] = [
@@ -593,9 +606,6 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
}
}
- $status = 'success';
- $msg = 'PLUGIN_ADMIN.PAGE_ROUTE_FOUND';
-
/** @var PageIndex $children */
$children = $page->children()->getIndex();
$selectedChildren = $children->filterBy($filters, true);
@@ -627,7 +637,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',
@@ -682,7 +692,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$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' => [
@@ -721,7 +731,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
$response = Utils::arrayFlatten($sorted);
}
- return [$status, $msg ?? 'PLUGIN_ADMIN.NO_ROUTE_PROVIDED', $response, $path];
+ return [$status, $msg, $response, $path];
}
/**
@@ -787,6 +797,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageInterface $page
* @return PageCollection
+ * @phpstan-return C
*/
public function addPage(PageInterface $page)
{
@@ -798,6 +809,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
* Create a copy of this collection
*
* @return static
+ * @phpstan-return static
*/
public function copy()
{
@@ -810,6 +822,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageCollectionInterface $collection
* @return PageCollection
+ * @phpstan-return C
*/
public function merge(PageCollectionInterface $collection)
{
@@ -822,6 +835,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param PageCollectionInterface $collection
* @return PageCollection
+ * @phpstan-return C
*/
public function intersect(PageCollectionInterface $collection)
{
@@ -833,6 +847,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param int $size
* @return PageCollection[]
+ * @phpstan-return C[]
*/
public function batch($size)
{
@@ -844,6 +859,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 +875,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 +919,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 +934,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 +950,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 +984,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 +1009,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 +1022,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 +1035,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 +1048,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 +1061,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 +1072,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 +1083,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 +1096,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 +1109,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 +1122,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 +1136,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string $type
* @return static The collection
+ * @phpstan-return static
*/
public function ofType($type)
{
@@ -1118,6 +1150,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
*
* @param string[] $types
* @return static The collection
+ * @phpstan-return static
*/
public function ofOneOfTheseTypes($types)
{
@@ -1131,6 +1164,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..fed11b4 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) {
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 310c313..d921791 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
*/
@@ -230,6 +242,22 @@ class UserObject extends FlexObject implements UserInterface, Countable
return $this;
}
+ /**
+ * @param UserInterface|null $user
+ * @return bool
+ */
+ public function isMyself(?UserInterface $user = null): bool
+ {
+ if (null === $user) {
+ $user = $this->getActiveUser();
+ if ($user && !$user->authenticated) {
+ $user = null;
+ }
+ }
+
+ return $user && $this->username === $user->username;
+ }
+
/**
* Checks user authorization to the action.
*
@@ -264,10 +292,11 @@ 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;
}
@@ -280,13 +309,14 @@ class UserObject extends FlexObject implements UserInterface, Countable
return $authorized;
}
- // If specific rule isn't hit, check if user is super user.
- if ($access->authorize('admin.super') === true) {
- return true;
+ // Check group access.
+ $authorized = $this->getGroups()->authorize($action, $scope);
+ if (is_bool($authorized)) {
+ return $authorized;
}
- // Check group access.
- return $this->getGroups()->authorize($action, $scope);
+ // If any specific rule isn't hit, check if user is a superuser.
+ return $access->authorize('admin.super') === true;
}
/**
@@ -616,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);
}
@@ -671,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';
@@ -775,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];
@@ -886,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;
@@ -898,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;
@@ -914,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/Response.php b/system/src/Grav/Common/GPM/Response.php
index 47cef7c..98654b6 100644
--- a/system/src/Grav/Common/GPM/Response.php
+++ b/system/src/Grav/Common/GPM/Response.php
@@ -1,143 +1,3 @@
'Grav CMS'
- ];
-
- /**
- * Makes a request to the URL by using the preferred method
- *
- * @param string $uri URL to call
- * @param array $overrides An array of parameters for both `curl` and `fopen`
- * @param callable|null $callback Either a function or callback in array notation
- * @return string The response of the request
- * @throws TransportExceptionInterface
- */
- public static function get($uri = '', $overrides = [], $callback = null)
- {
- if (empty($uri)) {
- throw new TransportException('missing URI');
- }
-
- // check if this function is available, if so use it to stop any timeouts
- try {
- if (Utils::functionExists('set_time_limit')) {
- @set_time_limit(0);
- }
- } catch (Exception $e) {
- }
-
- $config = Grav::instance()['config'];
- $referer = defined('GRAV_CLI') ? 'grav_cli' : Grav::instance()['uri']->rootUrl(true);
- $options = new HttpOptions();
-
- // Set default Headers
- $options->setHeaders(array_merge([ 'Referer' => $referer ], self::$headers));
-
- // Disable verify Peer if required
- $verify_peer = $config->get('system.gpm.verify_peer', true);
- if ($verify_peer !== true) {
- $options->verifyPeer($verify_peer);
- }
-
- // Set proxy url if provided
- $proxy_url = $config->get('system.gpm.proxy_url', false);
- if ($proxy_url) {
- $options->setProxy($proxy_url);
- }
-
- // Use callback if provided
- if ($callback) {
- self::$callback = $callback;
- $options->setOnProgress([Response::class, 'progress']);
- }
-
- $preferred_method = $config->get('system.gpm.method', 'auto');
-
- $settings = array_merge_recursive($options->toArray(), $overrides);
-
- switch ($preferred_method) {
- case 'curl':
- $client = new CurlHttpClient($settings);
- break;
- case 'fopen':
- case 'native':
- $client = new NativeHttpClient($settings);
- break;
- default:
- $client = HttpClient::create($settings);
- }
-
- $response = $client->request('GET', $uri);
-
- return $response->getContent();
- }
-
-
- /**
- * Is this a remote file or not
- *
- * @param string $file
- * @return bool
- */
- public static function isRemote($file)
- {
- return (bool) filter_var($file, FILTER_VALIDATE_URL);
- }
-
- /**
- * Progress normalized for cURL and Fopen
- * Accepts a variable length of arguments passed in by stream method
- *
- * @return void
- */
- public static function progress(int $bytes_transferred, int $filesize, array $info)
- {
-
- if ($bytes_transferred > 0) {
- $percent = $filesize <= 0 ? 0 : (int)(($bytes_transferred * 100) / $filesize);
-
- $progress = [
- 'code' => $info['http_code'],
- 'filesize' => $filesize,
- 'transferred' => $bytes_transferred,
- 'percent' => $percent < 100 ? $percent : 100
- ];
-
- if (self::$callback !== null) {
- call_user_func(self::$callback, $progress);
- }
- }
- }
-}
+// Create alias for the deprecated class.
+class_alias(\Grav\Common\HTTP\Response::class, \Grav\Common\GPM\Response::class);
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 8f3a73a..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);
@@ -69,6 +73,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
if ($this->gettersVariable) {
@@ -84,6 +89,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($this->gettersVariable) {
@@ -99,6 +105,7 @@ abstract class Getters implements ArrayAccess, Countable
* @param int|string $offset
* @param mixed $value
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if ($this->gettersVariable) {
@@ -112,6 +119,7 @@ abstract class Getters implements ArrayAccess, Countable
/**
* @param int|string $offset
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->gettersVariable) {
@@ -125,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 f591961..18d4902 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;
@@ -62,6 +64,7 @@ use function get_class;
use function in_array;
use function is_callable;
use function is_int;
+use function is_string;
use function strlen;
/**
@@ -343,7 +346,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 +398,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 +411,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 +425,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,37 +434,47 @@ 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));
}
return new Response($code, ['Location' => $url]);
@@ -639,6 +652,7 @@ class Grav extends Container
* @param array $args
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __call($method, $args)
{
$closure = $this->{$method} ?? null;
@@ -715,18 +729,36 @@ class Grav extends Container
*/
public function fallbackUrl($path)
{
- $this->fireEvent('onPageFallBackUrl');
-
/** @var Uri $uri */
$uri = $this['uri'];
/** @var Config $config */
$config = $this['config'];
- $uri_extension = strtolower($uri->extension());
- $fallback_types = $config->get('system.media.allowed_fallback_types', null);
+ $path_parts = Utils::pathinfo($path);
+
+ /** @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;
@@ -735,16 +767,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])) {
@@ -774,11 +798,9 @@ class Grav extends Container
}
Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
}
-
- // Nothing found
- return false;
}
- return $page ?? false;
+ // Nothing found
+ return false;
}
}
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
new file mode 100644
index 0000000..c85d6b2
--- /dev/null
+++ b/system/src/Grav/Common/HTTP/Client.php
@@ -0,0 +1,130 @@
+ 'Grav CMS'
+ ];
+
+ public static function getClient(array $overrides = [], int $connections = 6, callable $callback = null): HttpClientInterface
+ {
+ $config = Grav::instance()['config'];
+ $options = static::getOptions();
+
+ // Use callback if provided
+ if ($callback) {
+ self::$callback = $callback;
+ $options->setOnProgress([Client::class, 'progress']);
+ }
+
+ $settings = array_merge($options->toArray(), $overrides);
+ $preferred_method = $config->get('system.http.method');
+ // Try old GPM setting if value is the same as system default
+ if ($preferred_method === 'auto') {
+ $preferred_method = $config->get('system.gpm.method', 'auto');
+ }
+
+ switch ($preferred_method) {
+ case 'curl':
+ $client = new CurlHttpClient($settings, $connections);
+ break;
+ case 'fopen':
+ case 'native':
+ $client = new NativeHttpClient($settings, $connections);
+ break;
+ default:
+ $client = HttpClient::create($settings, $connections);
+ }
+
+ return $client;
+ }
+
+ /**
+ * Get HTTP Options
+ *
+ * @return HttpOptions
+ */
+ public static function getOptions(): HttpOptions
+ {
+ $config = Grav::instance()['config'];
+ $referer = defined('GRAV_CLI') ? 'grav_cli' : Grav::instance()['uri']->rootUrl(true);
+
+ $options = new HttpOptions();
+
+ // Set default Headers
+ $options->setHeaders(array_merge([ 'Referer' => $referer ], self::$headers));
+
+ // Disable verify Peer if required
+ $verify_peer = $config->get('system.http.verify_peer');
+ // Try old GPM setting if value is default
+ if ($verify_peer === true) {
+ $verify_peer = $config->get('system.gpm.verify_peer', null) ?? $verify_peer;
+ }
+ $options->verifyPeer($verify_peer);
+
+ // Set verify Host
+ $verify_host = $config->get('system.http.verify_host', true);
+ $options->verifyHost($verify_host);
+
+ // New setting and must be enabled for Proxy to work
+ if ($config->get('system.http.enable_proxy', true)) {
+ // Set proxy url if provided
+ $proxy_url = $config->get('system.http.proxy_url', $config->get('system.gpm.proxy_url', null));
+ if ($proxy_url !== null) {
+ $options->setProxy($proxy_url);
+ }
+
+ // Certificate
+ $proxy_cert = $config->get('system.http.proxy_cert_path', null);
+ if ($proxy_cert !== null) {
+ $options->setCaPath($proxy_cert);
+ }
+ }
+
+ return $options;
+ }
+
+ /**
+ * Progress normalized for cURL and Fopen
+ * Accepts a variable length of arguments passed in by stream method
+ *
+ * @return void
+ */
+ public static function progress(int $bytes_transferred, int $filesize, array $info)
+ {
+
+ if ($bytes_transferred > 0) {
+ $percent = $filesize <= 0 ? 0 : (int)(($bytes_transferred * 100) / $filesize);
+
+ $progress = [
+ 'code' => $info['http_code'],
+ 'filesize' => $filesize,
+ 'transferred' => $bytes_transferred,
+ 'percent' => $percent < 100 ? $percent : 100
+ ];
+
+ if (self::$callback !== null) {
+ call_user_func(self::$callback, $progress);
+ }
+ }
+ }
+}
diff --git a/system/src/Grav/Common/HTTP/Response.php b/system/src/Grav/Common/HTTP/Response.php
new file mode 100644
index 0000000..4a5bc8b
--- /dev/null
+++ b/system/src/Grav/Common/HTTP/Response.php
@@ -0,0 +1,96 @@
+getContent();
+ }
+
+
+ /**
+ * Makes a request to the URL by using the preferred method
+ *
+ * @param string $method method to call such as GET, PUT, etc
+ * @param string $uri URL to call
+ * @param array $overrides An array of parameters for both `curl` and `fopen`
+ * @param callable|null $callback Either a function or callback in array notation
+ * @return ResponseInterface
+ * @throws TransportExceptionInterface
+ */
+ public static function request(string $method, string $uri, array $overrides = [], callable $callback = null): ResponseInterface
+ {
+ if (empty($method)) {
+ throw new TransportException('missing method (GET, PUT, etc.)');
+ }
+
+ if (empty($uri)) {
+ throw new TransportException('missing URI');
+ }
+
+ // check if this function is available, if so use it to stop any timeouts
+ try {
+ if (Utils::functionExists('set_time_limit')) {
+ @set_time_limit(0);
+ }
+ } catch (Exception $e) {}
+
+ $client = Client::getClient($overrides, 6, $callback);
+
+ return $client->request($method, $uri);
+ }
+
+
+ /**
+ * Is this a remote file or not
+ *
+ * @param string $file
+ * @return bool
+ */
+ public static function isRemote($file): bool
+ {
+ return (bool) filter_var($file, FILTER_VALIDATE_URL);
+ }
+
+
+}
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 f0a3532..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.
*/
@@ -86,12 +86,14 @@ class LanguageCodes
'ja-JP' => [ 'name' => 'Japanese', 'nativeName' => '日本語' ], // not iso-639-1
'ka' => [ 'name' => 'Georgian', 'nativeName' => 'ქართული' ],
'kk' => [ 'name' => 'Kazakh', 'nativeName' => 'Қазақ' ],
+ 'km' => [ 'name' => 'Khmer', 'nativeName' => 'Khmer' ],
'kn' => [ 'name' => 'Kannada', 'nativeName' => 'ಕನ್ನಡ' ],
'ko' => [ 'name' => 'Korean', 'nativeName' => '한국어' ],
'ku' => [ 'name' => 'Kurdish', 'nativeName' => 'Kurdî' ],
'la' => [ 'name' => 'Latin', 'nativeName' => 'Latina' ],
'lb' => [ 'name' => 'Luxembourgish', 'nativeName' => 'Lëtzebuergesch' ],
'lg' => [ 'name' => 'Luganda', 'nativeName' => 'Luganda' ],
+ 'lo' => [ 'name' => 'Lao', 'nativeName' => 'Lao' ],
'lt' => [ 'name' => 'Lithuanian', 'nativeName' => 'Lietuvių' ],
'lv' => [ 'name' => 'Latvian', 'nativeName' => 'Latviešu' ],
'mai' => [ 'name' => 'Maithili', 'nativeName' => 'मैथिली মৈথিলী' ],
@@ -101,6 +103,7 @@ class LanguageCodes
'ml' => [ 'name' => 'Malayalam', 'nativeName' => 'മലയാളം' ],
'mn' => [ 'name' => 'Mongolian', 'nativeName' => 'Монгол' ],
'mr' => [ 'name' => 'Marathi', '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' ],
@@ -132,6 +135,7 @@ class LanguageCodes
'st' => [ 'name' => 'Southern Sotho', 'nativeName' => 'Sesotho' ],
'sv' => [ 'name' => 'Swedish', 'nativeName' => 'Svenska' ],
'sv-SE' => [ 'name' => 'Swedish', 'nativeName' => 'Svenska' ],
+ 'sw' => [ 'name' => 'Swahili', 'nativeName' => 'Swahili' ],
'ta' => [ 'name' => 'Tamil', 'nativeName' => 'தமிழ்' ],
'ta-IN' => [ 'name' => 'Tamil (India)', 'nativeName' => 'தமிழ் (இந்தியா)' ],
'ta-LK' => [ 'name' => 'Tamil (Sri Lanka)', 'nativeName' => 'தமிழ் (இலங்கை)' ],
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..4af3052 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.
*/
@@ -63,6 +63,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 +216,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 06056eb..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.
*/
@@ -50,6 +50,8 @@ trait ImageMediaTrait
/** @var integer */
protected $retina_scale;
+ /** @var bool */
+ protected $watermark;
/** @var array */
public static $magic_actions = [
@@ -379,6 +381,8 @@ trait ImageMediaTrait
$this->aspect_ratio = $config->get('system.images.cls.aspect_ratio', false);
$this->retina_scale = $config->get('system.images.cls.retina_scale', 1);
+ $this->watermark = $config->get('system.images.watermark.watermark_all', false);
+
return $this;
}
@@ -415,6 +419,10 @@ trait ImageMediaTrait
$this->image->merge(ImageFile::open($overlay));
}
+ if ($this->watermark) {
+ $this->watermark();
+ }
+
return $this->image->cacheFile($this->format, $this->quality, false, [$this->get('width'), $this->get('height'), $this->get('modified')]);
}
}
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..06cb99a 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.
*/
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..36a4503 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.
*/
@@ -132,9 +132,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 +573,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..b16bb53 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.
*/
diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php
index 32b917c..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();
@@ -187,6 +190,7 @@ class Collection extends Iterator implements PageCollectionInterface
* @param string $offset
* @return PageInterface|null
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->pages->get($offset) ?: null;
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 5156ede..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);
@@ -58,7 +60,7 @@ interface PageContentInterface
/**
* Needed by the onPageContentProcessed event to set the raw page content
*
- * @param string $content
+ * @param string|null $content
*/
public function setRawContent($content);
@@ -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 94fd2c4..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,10 +60,51 @@ 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
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return parent::offsetExists($offset) ?: isset(static::$global[$offset]);
@@ -72,6 +114,7 @@ class Media extends AbstractMedia
* @param string $offset
* @return MediaObjectInterface|null
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return parent::offsetGet($offset) ?: static::$global[$offset];
@@ -84,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.
@@ -96,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 4097c8f..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;
@@ -46,6 +47,7 @@ class GlobalMedia extends AbstractMedia
* @param string $offset
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return parent::offsetExists($offset) ?: !empty($this->resolveStream($offset));
@@ -55,6 +57,7 @@ class GlobalMedia extends AbstractMedia
* @param string $offset
* @return MediaObjectInterface|null
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return parent::offsetGet($offset) ?: $this->addMedium($offset);
@@ -87,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 70d13f8..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.
*/
@@ -17,6 +17,7 @@ use Grav\Common\Media\Interfaces\MediaLinkInterface;
use Grav\Common\Media\Traits\ImageLoadingTrait;
use Grav\Common\Media\Traits\ImageMediaTrait;
use Grav\Common\Utils;
+use Gregwar\Image\Image;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use function func_get_args;
use function in_array;
@@ -88,6 +89,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
/**
* Also unset the image on destruct.
*/
+ #[\ReturnTypeWillChange]
public function __destruct()
{
unset($this->image);
@@ -96,6 +98,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
/**
* Also clone image.
*/
+ #[\ReturnTypeWillChange]
public function __clone()
{
if ($this->image) {
@@ -246,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;";
@@ -302,25 +305,102 @@ 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();
+
+ $locator = $grav['locator'];
+ $config = $grav['config'];
+
+ $args = func_get_args();
+
+ $file = $args[0] ?? '1'; // using '1' because of markdown. doing  returns $args[0]='1';
+ $file = $file === '1' ? $config->get('system.images.watermark.image') : $args[0];
+
+ $watermark = $locator->findResource($file);
+ $watermark = ImageFile::open($watermark);
+
+ // Scaling operations
+ $scale = ($scale ?? $config->get('system.images.watermark.scale', 100)) / 100;
+ $wwidth = $this->get('width') * $scale;
+ $wheight = $this->get('height') * $scale;
+ $watermark->resize($wwidth, $wheight);
+
+ // Position operations
+ $position = !empty($args[1]) ? explode('-', $args[1]) : ['center', 'center']; // todo change to config
+ $positionY = $position[0] ?? $config->get('system.images.watermark.position_y', 'center');
+ $positionX = $position[1] ?? $config->get('system.images.watermark.position_x', 'center');
+
+ switch ($positionY)
+ {
+ case 'top':
+ $positionY = 0;
+ break;
+
+ case 'bottom':
+ $positionY = $this->get('height')-$wheight;
+ break;
+
+ case 'center':
+ $positionY = ($this->get('height')/2) - ($wheight/2);
+ break;
+ }
+
+ switch ($positionX)
+ {
+ case 'left':
+ $positionX = 0;
+ break;
+
+ case 'right':
+ $positionX = $this->get('width')-$wwidth;
+ break;
+
+ case 'center':
+ $positionX = ($this->get('width')/2) - ($wwidth/2);
+ break;
+ }
+
+ $this->__call('merge', [$watermark,$positionX, $positionY]);
return $this;
}
@@ -344,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 {
@@ -375,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..620446b 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'];
@@ -193,7 +194,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 +209,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/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 2099be2..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,26 @@ class Page implements PageInterface
return $this;
}
+ #[\ReturnTypeWillChange]
+ public function __clone()
+ {
+ $this->initialized = false;
+ $this->header = $this->header ? clone $this->header : null;
+ }
+
+ /**
+ * @return void
+ */
+ public function initialize(): void
+ {
+ if (!$this->initialized) {
+ $this->initialized = true;
+ $this->route = null;
+ $this->raw_route = null;
+ $this->_forms = null;
+ }
+ }
+
/**
* @return void
*/
@@ -368,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)
{
@@ -975,7 +995,7 @@ class Page implements PageInterface
/**
* Needed by the onPageContentProcessed event to set the raw page content
*
- * @param string $content
+ * @param string|null $content
* @return void
*/
public function setRawContent($content)
@@ -1227,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
*
@@ -1434,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;
@@ -2078,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);
}
@@ -2119,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 941c9a7..8ad2ccd 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.
*/
@@ -649,7 +649,7 @@ class Pages
$cmd = $value;
$params = [];
} elseif (is_array($value) && count($value) === 1 && !is_int(key($value))) {
- // Format: @command.param: { attr1: value1, attr2: value2 }
+ // Format: @command.param: { attr1: value1, attr2: value2 }
$cmd = (string)key($value);
$params = (array)current($value);
} else {
@@ -2065,7 +2065,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 b32e39e..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}"] ?? [];
}
/**
@@ -227,6 +227,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
if ($offset === 'title') {
@@ -244,6 +245,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($offset === 'title') {
@@ -262,6 +264,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param mixed $value The value to set.
* @throws LogicException
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
@@ -273,6 +276,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset The offset to unset.
* @throws LogicException
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
@@ -410,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 6114464..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.
*/
@@ -44,7 +44,7 @@ class InitializeProcessor extends ProcessorBase
public $title = 'Initialize';
/** @var bool */
- private static $cli_initialized = false;
+ protected static $cli_initialized = false;
/**
* @param Grav $grav
@@ -105,12 +105,12 @@ class InitializeProcessor extends ProcessorBase
// TODO: remove in 2.0.
$this->container['accounts'];
+ // Initialize session (used by URI, see issue #3269).
+ $this->initializeSession($config);
+
// Initialize URI (uses session, see issue #3269).
$this->initializeUri($config);
- // Initialize session.
- $this->initializeSession($config);
-
// Grav may return redirect response right away.
$redirectCode = (int)$config->get('system.pages.redirect_trailing_slash', 1);
if ($redirectCode) {
diff --git a/system/src/Grav/Common/Processors/PagesProcessor.php b/system/src/Grav/Common/Processors/PagesProcessor.php
index 470ca90..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.
*/
@@ -42,15 +42,29 @@ class PagesProcessor extends ProcessorBase
$this->container['debugger']->addMessage($this->container['cache']->getCacheStatus());
$this->container['pages']->init();
- $this->container->fireEvent('onPagesInitialized', new Event(['pages' => $this->container['pages']]));
- $this->container->fireEvent('onPageInitialized', new Event(['page' => $this->container['page']]));
+
+ $route = $this->container['route'];
+
+ $this->container->fireEvent('onPagesInitialized', new Event(
+ [
+ 'pages' => $this->container['pages'],
+ 'route' => $route,
+ 'request' => $request
+ ]
+ ));
+ $this->container->fireEvent('onPageInitialized', new Event(
+ [
+ 'page' => $this->container['page'],
+ 'route' => $route,
+ 'request' => $request
+ ]
+ ));
/** @var PageInterface $page */
$page = $this->container['page'];
if (!$page->routable()) {
$exception = new RequestException($request, 'Page Not Found', 404);
- $route = $this->container['route'];
// If no page found, fire event
$event = new Event([
'page' => $page,
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 833e648..017720c 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.
*/
@@ -61,7 +61,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);
@@ -138,7 +138,7 @@ class Security
$options = static::getXssDefaults();
}
- $list = [];
+ $list = [[]];
foreach ($array as $key => $value) {
if (is_array($value)) {
$list[] = static::detectXssFromArray($value, $prefix . $key . '.', $options);
@@ -148,11 +148,7 @@ class Security
}
}
- if (!empty($list)) {
- return array_merge(...$list);
- }
-
- return $list;
+ return array_merge(...$list);
}
/**
@@ -207,7 +203,7 @@ class Security
$string = preg_replace('!(+[0-9]+)!u', '$1;', $string);
// Decode entities
- $string = html_entity_decode($string, ENT_NOQUOTES, 'UTF-8');
+ $string = html_entity_decode($string, ENT_NOQUOTES | ENT_HTML5, 'UTF-8');
// Strip whitespace characters
$string = preg_replace('!\s!u', '', $string);
@@ -218,7 +214,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 b56f62f..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.
*/
@@ -179,7 +179,7 @@ class ConfigServiceProvider implements ServiceProviderInterface
* @param string $folder_path
* @return array
*/
- private static function pluginFolderPaths($plugins, $folder_path)
+ protected static function pluginFolderPaths($plugins, $folder_path)
{
$paths = [];
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 638617c..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.
*
@@ -847,6 +868,12 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
if (($numargs === 3 && is_array($args[1])) || ($numargs === 2 && !is_array($args[1]))) {
$lang = array_pop($args);
+ /** @var Language $language */
+ $language = $this->grav['language'];
+ if (is_string($lang) && !$language->getLanguageCode($lang)) {
+ $args[] = $lang;
+ $lang = null;
+ }
} elseif ($numargs === 2 && is_array($args[1])) {
$subs = array_pop($args);
$args = array_merge($args, $subs);
@@ -1354,7 +1381,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
*/
public function vardumpFunc($var)
{
- var_dump($var);
+ dump($var);
}
/**
@@ -1418,7 +1445,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
* @param array $context Twig Context
* @param string $var variable to be found (using dot notation)
* @param null $default the default value to be used as last resort
- * @param null $page an optional page to use for the current page
+ * @param PageInterface|null $page an optional page to use for the current page
* @param bool $exists toggle to simply return the page where the variable is set, else null
* @return mixed
*/
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..6b2a86b 100644
--- a/system/src/Grav/Common/Twig/TwigEnvironment.php
+++ b/system/src/Grav/Common/Twig/TwigEnvironment.php
@@ -3,13 +3,16 @@
/**
* @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\Template;
+use Twig\TemplateWrapper;
/**
* Class TwigEnvironment
@@ -18,4 +21,34 @@ 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 && !$this->getLoader()->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 4735342..71e7f9b 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;
@@ -57,6 +58,7 @@ class User extends Data implements UserInterface
* @param string $offset
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
$value = parent::offsetExists($offset);
@@ -73,6 +75,7 @@ class User extends Data implements UserInterface
* @param string $offset
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
$value = parent::offsetGet($offset);
@@ -175,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);
}
}
@@ -293,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 5be5386..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.
*/
@@ -27,7 +27,7 @@ class Group extends Data
* @return array
* @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead
*/
- private static function groups()
+ protected static function groups()
{
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED);
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..0608caf 100644
--- a/system/src/Grav/Common/User/Traits/UserTrait.php
+++ b/system/src/Grav/Common/User/Traits/UserTrait.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/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 f843a0c..64c81a9 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.
*/
@@ -21,6 +21,7 @@ use Grav\Common\Page\Markdown\Excerpts;
use Grav\Common\Page\Pages;
use Grav\Framework\Flex\Flex;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
+use Grav\Framework\Media\Interfaces\MediaInterface;
use InvalidArgumentException;
use Negotiation\Accept;
use Negotiation\Negotiator;
@@ -150,7 +151,7 @@ abstract class Utils
$domain = $domain ?: $grav['config']->get('system.absolute_urls', false);
- return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?? '');
+ return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?: '');
}
/**
@@ -652,16 +653,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
@@ -679,7 +681,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
@@ -703,7 +705,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);
@@ -829,6 +831,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
@@ -899,7 +926,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);
}
/**
@@ -944,7 +971,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.
@@ -958,6 +985,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(string $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(string $path, string $suffix = ''): string
+ {
+ return rawurldecode(basename(str_replace(['%2F', '%5C'], '/', rawurlencode($path)), $suffix));
+ }
+
/**
* Normalize path by processing relative `.` and `..` syntax and merging path
*
@@ -1566,7 +1633,7 @@ abstract class Utils
switch ($matches[0]) {
case 'self':
- if (null === $object) {
+ if (!$object instanceof MediaInterface) {
throw new RuntimeException(sprintf('Page not available for self@ reference: %s', $path));
}
@@ -1593,8 +1660,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 = '';
@@ -1640,7 +1707,7 @@ abstract class Utils
* @param string $path
* @return string[]|null
*/
- private static function resolveTokenPath(string $path): ?array
+ protected static function resolveTokenPath(string $path): ?array
{
if (strpos($path, '@') !== false) {
$regex = '/^(@\w+|\w+@|@\w+@)([^:]*)(.*)$/u';
@@ -1774,7 +1841,7 @@ abstract class Utils
*
* @param string $string
* @param bool $block Block or Line processing
- * @param null $page
+ * @param PageInterface|null $page
* @return string
* @throws Exception
*/
diff --git a/system/src/Grav/Common/Yaml.php b/system/src/Grav/Common/Yaml.php
index 5adbd0c..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.
*/
@@ -17,8 +17,8 @@ use Grav\Framework\File\Formatter\YamlFormatter;
*/
abstract class Yaml
{
- /** @var YamlFormatter */
- private static $yaml;
+ /** @var YamlFormatter|null */
+ protected static $yaml;
/**
* @param string $data
@@ -51,7 +51,7 @@ abstract class Yaml
/**
* @return void
*/
- private static function init()
+ protected static function init()
{
$config = [
'inline' => 5,
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 64d3597..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.
*/
@@ -200,7 +200,6 @@ class IndexCommand extends GpmCommand
*/
private function installed(Package $package): string
{
- $package = $list[$package->slug] ?? $package;
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
$method = 'is' . $type . 'Installed';
$installed = $this->gpm->{$method}($package->slug);
@@ -214,7 +213,6 @@ class IndexCommand extends GpmCommand
*/
private function enabled(Package $package): string
{
- $package = $list[$package->slug] ?? $package;
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
$method = 'is' . $type . 'Installed';
$installed = $this->gpm->{$method}($package->slug);
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 2c38afb..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.
*/
@@ -21,7 +21,7 @@ use function is_array;
class PermissionsReader
{
/** @var array */
- private static $types;
+ protected static $types;
/**
* @param string $filename
@@ -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;
@@ -131,7 +133,7 @@ class PermissionsReader
*/
protected static function getDependencies(array $dependencies): array
{
- $list = [];
+ $list = [[]];
foreach ($dependencies as $name => $deps) {
$current = $deps ? static::getDependencies($deps) : [];
$current[] = $name;
@@ -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 f892267..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.
*/
@@ -25,9 +25,9 @@ use function array_slice;
*
* @package Grav\Framework\Collection
* @template TKey of array-key
- * @template T
+ * @template T of object
* @extends AbstractLazyCollection
- * @mplements FileCollectionInterface
+ * @implements FileCollectionInterface
*/
class AbstractFileCollection extends AbstractLazyCollection implements FileCollectionInterface
{
@@ -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 6a8861e..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;
@@ -22,6 +23,7 @@ use function count;
* Abstract Index Collection.
* @template TKey of array-key
* @template T
+ * @template C of CollectionInterface
* @implements CollectionInterface
*/
abstract class AbstractIndexCollection implements CollectionInterface
@@ -78,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);
@@ -100,6 +102,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function current()
{
$value = current($this->entries);
@@ -130,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;
}
@@ -142,45 +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)
{
- return $this->remove($offset);
+ if ($offset !== null) {
+ /** @phpstan-ignore-next-line phpstan bug? */
+ $this->remove($offset);
+ }
}
/**
@@ -250,6 +272,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* {@inheritDoc}
*/
+ #[\ReturnTypeWillChange]
public function count()
{
return count($this->entries);
@@ -293,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());
@@ -336,6 +361,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return __CLASS__ . '@' . spl_object_hash($this);
@@ -361,7 +387,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* @param int $start
* @param int|null $limit
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
public function limit($start, $limit = null)
{
@@ -372,7 +398,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Reverse the order of the items.
*
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
public function reverse()
{
@@ -383,14 +409,14 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Shuffle items.
*
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
public function shuffle()
{
$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));
}
/**
@@ -400,7 +426,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
public function select(array $keys)
{
@@ -419,7 +445,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
public function unselect(array $keys)
{
@@ -431,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);
}
@@ -461,6 +489,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->loadCollection()->jsonSerialize();
@@ -474,7 +503,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $entries Elements.
* @return static
- * @phpstan-return static
+ * @phpstan-return static
*/
protected function createFrom(array $entries)
{
@@ -527,7 +556,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* @param array|null $entries
* @return CollectionInterface
- * @phpstan-return T
+ * @phpstan-return C
*/
abstract protected function loadCollection(array $entries = null): CollectionInterface;
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 42414ce..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.
*/
@@ -26,7 +26,7 @@ interface CollectionInterface extends Collection, JsonSerializable
* Reverse the order of the items.
*
* @return CollectionInterface
- * @phpstan-return CollectionInterface
+ * @phpstan-return static
*/
public function reverse();
@@ -34,7 +34,7 @@ interface CollectionInterface extends Collection, JsonSerializable
* Shuffle items.
*
* @return CollectionInterface
- * @phpstan-return CollectionInterface
+ * @phpstan-return static
*/
public function shuffle();
@@ -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);
@@ -53,7 +54,7 @@ interface CollectionInterface extends Collection, JsonSerializable
*
* @param array $keys
* @return CollectionInterface
- * @phpstan-return CollectionInterface
+ * @phpstan-return static
*/
public function select(array $keys);
@@ -62,7 +63,7 @@ interface CollectionInterface extends Collection, JsonSerializable
*
* @param array $keys
* @return CollectionInterface
- * @phpstan-return CollectionInterface
+ * @phpstan-return static
*/
public function unselect(array $keys);
}
diff --git a/system/src/Grav/Framework/Collection/FileCollection.php b/system/src/Grav/Framework/Collection/FileCollection.php
index 59df221..bae0e7b 100644
--- a/system/src/Grav/Framework/Collection/FileCollection.php
+++ b/system/src/Grav/Framework/Collection/FileCollection.php
@@ -3,19 +3,19 @@
/**
* @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.
*/
namespace Grav\Framework\Collection;
+use stdClass;
+
/**
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
- * @template TKey of array-key
- * @template T
- * @extends AbstractFileCollection
+ * @extends AbstractFileCollection
*/
class FileCollection extends AbstractFileCollection
{
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 62ed3e1..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.
*/
@@ -12,12 +12,14 @@ declare(strict_types=1);
namespace Grav\Framework\Controller\Traits;
use Grav\Common\Config\Config;
+use Grav\Common\Data\ValidationException;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Framework\Psr7\Response;
use Grav\Framework\RequestHandler\Exception\RequestException;
use Grav\Framework\Route\Route;
+use JsonSerializable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
@@ -95,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']);
@@ -138,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]);
}
@@ -203,15 +205,23 @@ trait ControllerResponseTrait
protected function getErrorJson(Throwable $e): array
{
$code = $this->getErrorCode($e instanceof RequestException ? $e->getHttpCode() : $e->getCode());
- $message = $e->getMessage();
+ if ($e instanceof ValidationException) {
+ $message = $e->getMessage();
+ } else {
+ $message = htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_HTML5, 'UTF-8');
+ }
+
+ $extra = $e instanceof JsonSerializable ? $e->jsonSerialize() : [];
+
$response = [
'code' => $code,
'status' => 'error',
'message' => $message,
+ 'redirect' => null,
'error' => [
'code' => $code,
'message' => $message
- ]
+ ] + $extra
];
/** @var Debugger $debugger */
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 8739282..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 = [];
@@ -256,7 +258,7 @@ class Flex implements FlexInterface
}
// Remove missing objects if not asked to keep them.
- if (empty($option['keep_missing'])) {
+ if (empty($options['keep_missing'])) {
$list = array_filter($list);
}
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 a225967..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.
*/
@@ -15,6 +15,7 @@ use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Twig\Twig;
+use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexDirectoryFormInterface;
use Grav\Framework\Flex\Interfaces\FlexFormInterface;
use Grav\Framework\Form\Interfaces\FormFlashInterface;
@@ -94,9 +95,14 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
$uniqueId = md5($directory->getFlexType() . '-directory-' . $this->name);
}
$this->setUniqueId($uniqueId);
+
$this->setFlashLookupFolder($directory->getDirectoryBlueprint()->get('form/flash_folder') ?? 'tmp://forms/[SESSIONID]');
$this->form = $options['form'] ?? null;
+ if (Utils::isPositive($this->form['disabled'] ?? false)) {
+ $this->disable();
+ }
+
$this->initialize();
}
@@ -352,6 +358,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __get($name)
{
$method = "get{$name}";
@@ -369,6 +376,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value)
{
$method = "set{$name}";
@@ -381,6 +389,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($name)
{
$method = "get{$name}";
@@ -397,6 +406,7 @@ class FlexDirectoryForm implements FlexDirectoryFormInterface, JsonSerializable
* @param string $name
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($name)
{
}
@@ -487,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 4fb8daf..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.
*/
@@ -15,6 +15,7 @@ use Grav\Common\Data\Blueprint;
use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Twig\Twig;
+use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexFormInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectFormInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
@@ -125,10 +126,15 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
$uniqueId = md5($uniqueId);
}
$this->setUniqueId($uniqueId);
+
$directory = $object->getFlexDirectory();
$this->setFlashLookupFolder($options['flash_folder'] ?? $directory->getBlueprint()->get('form/flash_folder') ?? 'tmp://forms/[SESSIONID]');
$this->form = $options['form'] ?? null;
+ if (Utils::isPositive($this->items['disabled'] ?? $this->form['disabled'] ?? false)) {
+ $this->disable();
+ }
+
if (!empty($options['reset'])) {
$this->getFlash()->delete();
}
@@ -438,6 +444,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function __get($name)
{
$method = "get{$name}";
@@ -455,6 +462,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param mixed $value
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __set($name, $value)
{
$method = "set{$name}";
@@ -467,6 +475,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return bool
*/
+ #[\ReturnTypeWillChange]
public function __isset($name)
{
$method = "get{$name}";
@@ -483,6 +492,7 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
* @param string $name
* @return void
*/
+ #[\ReturnTypeWillChange]
public function __unset($name)
{
}
@@ -588,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 1df5c4d..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;
@@ -35,18 +36,18 @@ use function in_array;
* @package Grav\Framework\Flex
* @template T of FlexObjectInterface
* @template C of FlexCollectionInterface
- * @extends ObjectIndex
+ * @extends ObjectIndex
* @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 945f5ad..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.
*/
@@ -12,6 +12,7 @@ namespace Grav\Framework\Flex;
use ArrayAccess;
use Exception;
use Grav\Common\Data\Blueprint;
+use Grav\Common\Data\Data;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Common\Inflector;
@@ -68,15 +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 array */
- protected $_changes;
- /** @var string */
+ /** @var string|null */
protected $storage_key;
- /** @var int */
+ /** @var int|null */
protected $storage_timestamp;
/**
@@ -164,6 +163,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*/
public function getFlexFeatures(): array
{
+ /** @var array $implements */
$implements = class_implements($this);
$list = [];
@@ -454,13 +454,50 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
}
/**
- * Get any changes based on data sent to update
+ * Get diff array from the object.
+ *
+ * @return array
+ */
+ public function getDiff(): array
+ {
+ $blueprint = $this->getBlueprint();
+
+ $flattenOriginal = $blueprint->flattenData($this->getOriginalData());
+ $flattenElements = $blueprint->flattenData($this->getElements());
+ $removedElements = array_diff_key($flattenOriginal, $flattenElements);
+ $diff = [];
+
+ // Include all added or changed keys.
+ foreach ($flattenElements as $key => $value) {
+ $orig = $flattenOriginal[$key] ?? null;
+ if ($orig !== $value) {
+ $diff[$key] = ['old' => $orig, 'new' => $value];
+ }
+ }
+
+ // Include all removed keys.
+ foreach ($removedElements as $key => $value) {
+ $diff[$key] = ['old' => $value, 'new' => null];
+ }
+
+ return $diff;
+ }
+
+ /**
+ * Get any changes from the object.
*
* @return array
*/
public function getChanges(): array
{
- return $this->_changes ?? [];
+ $diff = $this->getDiff();
+
+ $data = new Data();
+ foreach ($diff as $key => $change) {
+ $data->set($key, $change['new']);
+ }
+
+ return $data->toArray();
}
/**
@@ -620,6 +657,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->getElements();
@@ -641,14 +679,19 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
public function update(array $data, array $files = [])
{
if ($data) {
+ // Get currently stored data.
+ $elements = $this->getElements();
+
+ // Store original version of the object.
+ if ($this->_original === null) {
+ $this->_original = $elements;
+ }
+
$blueprint = $this->getBlueprint();
// Process updated data through the object filters.
$this->filterElements($data);
- // Get currently stored data.
- $elements = $this->getElements();
-
// Merge existing object to the test data to be validated.
$test = $blueprint->mergeData($elements, $data);
@@ -657,17 +700,14 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
$data = $blueprint->filter($data, true, true);
// Finally update the object.
- foreach ($blueprint->flattenData($data) as $key => $value) {
+ $flattenData = $blueprint->flattenData($data);
+ foreach ($flattenData as $key => $value) {
if ($value === null) {
$this->unsetNestedProperty($key);
} else {
$this->setNestedProperty($key, $value);
}
}
-
- // Store the changes
- $this->_original = $this->getElements();
- $this->_changes = Utils::arrayDiffMultidimensional($this->_original, $elements);
}
if ($files && method_exists($this, 'setUpdatedMedia')) {
@@ -737,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;
@@ -849,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();
@@ -912,6 +952,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
*
* @return string
*/
+ #[\ReturnTypeWillChange]
public function __toString()
{
return $this->getFlexKey();
@@ -920,6 +961,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function __debugInfo()
{
return [
@@ -935,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 5b4f9f3..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.
*/
@@ -224,6 +224,7 @@ class FolderStorage extends AbstractFilesystemStorage
* @param string $src
* @param string $dst
* @return bool
+ * @throws RuntimeException
*/
public function copyRow(string $src, string $dst): bool
{
@@ -247,6 +248,7 @@ class FolderStorage extends AbstractFilesystemStorage
/**
* {@inheritdoc}
* @see FlexStorageInterface::renameRow()
+ * @throws RuntimeException
*/
public function renameRow(string $src, string $dst): bool
{
@@ -350,7 +352,7 @@ class FolderStorage extends AbstractFilesystemStorage
*/
protected function getKeyFromPath(string $path): string
{
- return basename($path);
+ return Utils::basename($path);
}
/**
@@ -634,7 +636,7 @@ class FolderStorage extends AbstractFilesystemStorage
$flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS;
$iterator = new FilesystemIterator($path, $flags);
- $list = [];
+ $list = [[]];
/** @var SplFileInfo $info */
foreach ($iterator as $filename => $info) {
if (!$info->isDir() || strpos($info->getFilename(), '.') === 0) {
@@ -644,11 +646,7 @@ class FolderStorage extends AbstractFilesystemStorage
$list[] = $this->buildIndexFromFilesystem($filename);
}
- if (!$list) {
- return [];
- }
-
- return count($list) > 1 ? array_merge(...$list) : $list[0];
+ return array_merge(...$list);
}
/**
@@ -690,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..6c99599 100644
--- a/system/src/Grav/Framework/Form/FormFlashFile.php
+++ b/system/src/Grav/Framework/Form/FormFlashFile.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.
*/
@@ -11,6 +11,7 @@ namespace Grav\Framework\Form;
use Grav\Framework\Psr7\Stream;
use InvalidArgumentException;
+use JsonSerializable;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use RuntimeException;
@@ -23,7 +24,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,6 +176,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
/**
* @return array
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->upload;
@@ -199,6 +201,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 8dfed19..f4be9e7 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.
*/
@@ -57,16 +57,18 @@ trait FormTrait
private $name;
/** @var string */
private $id;
+ /** @var bool */
+ private $enabled = true;
/** @var string */
private $uniqueid;
/** @var string */
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 */
@@ -90,6 +92,30 @@ trait FormTrait
$this->id = $id;
}
+ /**
+ * @return void
+ */
+ public function disable(): void
+ {
+ $this->enabled = false;
+ }
+
+ /**
+ * @return void
+ */
+ public function enable(): void
+ {
+ $this->enabled = true;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
/**
* @return string
*/
@@ -177,7 +203,7 @@ trait FormTrait
*/
public function getFiles(): array
{
- return $this->files ?? [];
+ return $this->files;
}
/**
@@ -195,8 +221,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();
@@ -666,7 +692,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();
@@ -685,7 +711,7 @@ trait FormTrait
return [
$data,
- $files ?? []
+ $files
];
}
@@ -695,6 +721,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
@@ -709,6 +736,7 @@ trait FormTrait
*
* @param ArrayAccess|Data|null $data
* @return void
+ * @phpstan-param ArrayAccess|Data|null $data
*/
protected function filterData($data = null): void
{
@@ -771,9 +799,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
new file mode 100644
index 0000000..f0ebef1
--- /dev/null
+++ b/system/src/Grav/Framework/Logger/Processors/UserProcessor.php
@@ -0,0 +1,34 @@
+exists()) {
+ $record['extra']['user'] = ['username' => $user->username, 'email' => $user->email];
+ }
+
+ return $record;
+ }
+}
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 de5cc7a..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.
*/
@@ -21,6 +21,7 @@ trait ArrayAccessTrait
* @param mixed $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->hasProperty($offset);
@@ -32,6 +33,7 @@ trait ArrayAccessTrait
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->getProperty($offset);
@@ -44,6 +46,7 @@ trait ArrayAccessTrait
* @param mixed $value The value to set.
* @return void
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->setProperty($offset, $value);
@@ -55,6 +58,7 @@ trait ArrayAccessTrait
* @param mixed $offset The offset to unset.
* @return void
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->unsetProperty($offset);
diff --git a/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php b/system/src/Grav/Framework/Object/Access/NestedArrayAccessTrait.php
index e048565..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.
*/
@@ -21,6 +21,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->hasNestedProperty($offset);
@@ -32,6 +33,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->getNestedProperty($offset);
@@ -44,6 +46,7 @@ trait NestedArrayAccessTrait
* @param mixed $value The value to set.
* @return void
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->setNestedProperty($offset, $value);
@@ -55,6 +58,7 @@ trait NestedArrayAccessTrait
* @param mixed $offset The offset to unset.
* @return void
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->unsetNestedProperty($offset);
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 b7b416d..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.
*/
@@ -24,8 +24,9 @@ use function is_object;
* order to use the class.
*
* @template TKey of array-key
- * @template T
- * @extends AbstractIndexCollection
+ * @template T of \Grav\Framework\Object\Interfaces\ObjectInterface
+ * @template C of ObjectCollectionInterface
+ * @extends AbstractIndexCollection
* @implements NestedObjectCollectionInterface
*/
abstract class ObjectIndex extends AbstractIndexCollection implements NestedObjectCollectionInterface
@@ -34,7 +35,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
protected static $type;
/** @var string */
- private $_key;
+ protected $_key;
/**
* @param bool $prefix
@@ -94,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)
{
@@ -104,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)
{
@@ -113,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)
{
@@ -145,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)
{
@@ -156,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)
{
@@ -166,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)
{
@@ -176,15 +183,17 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
- * @return static
+ * @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);
}
@@ -199,6 +208,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
/**
* @param array $ordering
* @return ObjectCollectionInterface
+ * @phpstan-return C
*/
public function orderBy(array $ordering)
{
@@ -231,6 +241,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
*
* @param string $property
* @return ObjectCollectionInterface[]
+ * @phpstan-return C[]
*/
public function collectionGroup($property)
{
@@ -238,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;
}
/**
@@ -253,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 a9935ee..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.
*/
@@ -11,9 +11,12 @@ declare(strict_types=1);
namespace Grav\Framework\RequestHandler\Middlewares;
+use Grav\Common\Data\ValidationException;
use Grav\Common\Debugger;
use Grav\Common\Grav;
use Grav\Framework\Psr7\Response;
+use JsonException;
+use JsonSerializable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@@ -27,16 +30,34 @@ use function get_class;
*/
class Exceptions implements MiddlewareInterface
{
+ /**
+ * @param ServerRequestInterface $request
+ * @param RequestHandlerInterface $handler
+ * @return ResponseInterface
+ * @throws JsonException
+ */
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $handler->handle($request);
} catch (Throwable $exception) {
+ $code = $exception->getCode();
+ if ($exception instanceof ValidationException) {
+ $message = $exception->getMessage();
+ } else {
+ $message = htmlspecialchars($exception->getMessage(), ENT_QUOTES | ENT_HTML5, 'UTF-8');
+ }
+
+ $extra = $exception instanceof JsonSerializable ? $exception->jsonSerialize() : [];
+
$response = [
+ 'code' => $code,
+ 'status' => 'error',
+ 'message' => $message,
'error' => [
- 'code' => $exception->getCode(),
- 'message' => $exception->getMessage(),
- ]
+ 'code' => $code,
+ 'message' => $message,
+ ] + $extra
];
/** @var Debugger $debugger */
@@ -51,9 +72,9 @@ class Exceptions implements MiddlewareInterface
}
/** @var string $json */
- $json = json_encode($response);
+ $json = json_encode($response, JSON_THROW_ON_ERROR);
- return new Response($exception->getCode() ?: 500, ['Content-Type' => 'application/json'], $json);
+ return new Response($code ?: 500, ['Content-Type' => 'application/json'], $json);
}
}
}
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/tmp/forms/ma7jev9sc9l2lbinlr2fk21s6o/a4f153b35cbb7417c5038f5663e60d53/index.yaml b/tmp/forms/ma7jev9sc9l2lbinlr2fk21s6o/a4f153b35cbb7417c5038f5663e60d53/index.yaml
deleted file mode 100644
index ebc68fc..0000000
--- a/tmp/forms/ma7jev9sc9l2lbinlr2fk21s6o/a4f153b35cbb7417c5038f5663e60d53/index.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-form: flex-pages
-unique_id: a4f153b35cbb7417c5038f5663e60d53
-url: '/pages/home/evenements/_intervenants/_table-ronde-1/:add'
-user:
- username: admin
- email: ouidade@figureslibres.io
-timestamps:
- created: 1633076732
- updated: 1633076732
-data: null
-files: { }
-object:
- type: pages
- key: home/evenements/_intervenants/_table-ronde-1
- storage_key: ''
- timestamp: 0
- serialized:
- __META: { }
- storage_key: ''
- parent_key: 01.home/06.evenements/03._intervenants
- order: false
- folder: _table-ronde-1
- template: personnes
- lang: ''
- root: false
- route: /home/evenements/_intervenants
- name: modular/personnes
- modular: '1'
- header:
- title: 'Table ronde 1'
- body_classes: modular
- frontmatter: "title: 'Table ronde 1'\nbody_classes: modular\n"
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 @@
-
+
-
+