mirror of
https://github.com/getgrav/grav.git
synced 2026-02-09 16:17:56 +01:00
Merge branch 'release/1.7.26'
This commit is contained in:
@@ -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
|
||||
|
||||
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,3 +1,30 @@
|
||||
# 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
|
||||
|
||||
|
||||
13
README.md
13
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
[](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.
|
||||
|
||||
@@ -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)]
|
||||
|
||||
<img src="https://opencollective.com/grav/tiers/backers.svg?avatarHeight=36&width=600" />
|
||||
|
||||
|
||||
# Supporters
|
||||
Support Grav with a monthly donation to help us continue development. [[Become a supporter](https://opencollective.com/grav/contribute)]
|
||||
|
||||
<img src="https://opencollective.com/grav/tiers/supporters.svg?avatarHeight=36&width=600" />
|
||||
|
||||
|
||||
# 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)]
|
||||
|
||||
<img src="https://opencollective.com/grav/tiers/sponsors.svg?avatarHeight=36&width=600" />
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
|
||||
/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
|
||||
|
||||
@@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
|
||||
/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
|
||||
|
||||
Binary file not shown.
6
bin/gpm
6
bin/gpm
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby 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,10 +25,6 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
|
||||
|
||||
$autoload = require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
||||
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
|
||||
}
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
6
bin/grav
6
bin/grav
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby 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,10 +25,6 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
|
||||
|
||||
$autoload = require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
||||
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
|
||||
}
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby 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,10 +25,6 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
|
||||
|
||||
$autoload = require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
||||
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
|
||||
}
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
2
cache/.gitkeep
vendored
2
cache/.gitkeep
vendored
@@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
|
||||
/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"ext-zip": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-libxml": "*",
|
||||
"symfony/polyfill-mbstring": "~1.20",
|
||||
"symfony/polyfill-mbstring": "~1.23",
|
||||
"symfony/polyfill-iconv": "^1.23",
|
||||
"symfony/polyfill-php74": "^1.23",
|
||||
"symfony/polyfill-php80": "^1.23",
|
||||
@@ -27,10 +27,10 @@
|
||||
"psr/simple-cache": "^1.0",
|
||||
"psr/http-message": "^1.0",
|
||||
"psr/http-server-middleware": "^1.0",
|
||||
"psr/container": "~1.0.0",
|
||||
"psr/container": "~1.1.0",
|
||||
"nyholm/psr7-server": "^1.0",
|
||||
"nyholm/psr7": "^1.3",
|
||||
"twig/twig": "~1.44",
|
||||
"twig/twig": "~v1.44",
|
||||
"erusev/parsedown": "^1.7",
|
||||
"erusev/parsedown-extra": "~0.8",
|
||||
"symfony/contracts": "~1.1",
|
||||
@@ -48,11 +48,10 @@
|
||||
"getgrav/image": "^3.0",
|
||||
"getgrav/cache": "^2.0",
|
||||
"donatj/phpuseragentparser": "~1.1",
|
||||
"pimple/pimple": "~3.3.0",
|
||||
"pimple/pimple": "~3.5.0",
|
||||
"rockettheme/toolbox": "~1.5",
|
||||
"maximebf/debugbar": "~1.16",
|
||||
"league/climate": "^3.6",
|
||||
"antoligy/dom-string-iterators": "^1.0",
|
||||
"miljar/php-exif": "^0.6",
|
||||
"composer/ca-bundle": "^1.2",
|
||||
"dragonmantank/cron-expression": "^1.2",
|
||||
@@ -64,7 +63,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"codeception/codeception": "^4.1",
|
||||
"phpstan/phpstan": "^1.0",
|
||||
"phpstan/phpstan": "^1.2",
|
||||
"phpstan/phpstan-deprecation-rules": "^1.0",
|
||||
"phpunit/php-code-coverage": "~9.2",
|
||||
"getgrav/markdowndocs": "^2.0",
|
||||
@@ -97,9 +96,16 @@
|
||||
"Twig\\": "system/src/Twig"
|
||||
},
|
||||
"files": [
|
||||
"system/defines.php"
|
||||
"system/defines.php",
|
||||
"system/src/DOMLettersIterator.php",
|
||||
"system/src/DOMWordsIterator.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"PHPStan\\": "tests/phpstan/classes"
|
||||
}
|
||||
},
|
||||
"archive": {
|
||||
"exclude": [
|
||||
"VERSION"
|
||||
@@ -108,8 +114,8 @@
|
||||
"scripts": {
|
||||
"api-17": "vendor/bin/phpdoc-md generate system/src > 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"
|
||||
|
||||
398
composer.lock
generated
398
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
|
||||
/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
|
||||
|
||||
@@ -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 <strong>PHP %s</strong> 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;
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
/* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved. */
|
||||
/* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved. */
|
||||
|
||||
@@ -1394,6 +1394,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
|
||||
|
||||
@@ -104,7 +104,7 @@ config:
|
||||
|
||||
edit:
|
||||
title:
|
||||
template: "{% if object.root %}Root <small>( <root> ){% else %}{{ (form.value('header.title') ?? form.value('folder'))|e }} <small>( {{ (object.getRoute().toString(false) ?: '/')|e }} )</small>{% endif %}"
|
||||
template: "{% if object.root %}Root <small>( <root> )</small>{% else %}{{ (form.value('header.title') ?? form.value('folder'))|e }} <small>( {{ (object.getRoute().toString(false) ?: '/')|e }} )</small>{% endif %}"
|
||||
|
||||
# TODO: not used yet
|
||||
buttons:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -182,6 +182,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)
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
/**
|
||||
* @package Grav\Core
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
// Some standard defines
|
||||
define('GRAV', true);
|
||||
define('GRAV_VERSION', '1.7.25');
|
||||
define('GRAV_VERSION', '1.7.26');
|
||||
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
|
||||
define('GRAV_TESTING', false);
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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: '<b>Falló la validación: </b>'
|
||||
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 <b />
|
||||
TEXT_MINS: ' a <b /> minuto(s) despues de la hora'
|
||||
TEXT_MINS: ' a <b /> minuto(s) después de la hora'
|
||||
TEXT_TIME: ' a <b />:<b />'
|
||||
TEXT_DOW: ' en <b />'
|
||||
TEXT_MONTH: ' de<b />'
|
||||
TEXT_DOM: ' en<b />'
|
||||
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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @package Grav\Core
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -22,9 +22,9 @@ if ($path !== '/index.php' && is_file($root . $path)) {
|
||||
// Block all direct access for these folders
|
||||
|| preg_match('`^/(\.git|cache|bin|logs|backup|webserver-configs|tests)/`ui', $path)
|
||||
// Block access to specific file types for these system folders
|
||||
|| preg_match('`^/(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||
|| preg_match('`^/(system|vendor)/(.*)\.(txt|xml|md|html|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||
// Block access to specific file types for these user folders
|
||||
|| preg_match('`^/(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||
|| preg_match('`^/(user)/(.*)\.(txt|md|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||
// Block all direct access to .md files
|
||||
|| preg_match('`\.md$`ui', $path)
|
||||
// Block access to specific files in the root folder
|
||||
|
||||
165
system/src/DOMLettersIterator.php
Normal file
165
system/src/DOMLettersIterator.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Iterates individual characters (Unicode codepoints) of DOM text and CDATA nodes
|
||||
* while keeping track of their position in the document.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $doc = new DOMDocument();
|
||||
* $doc->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<int,string>
|
||||
*/
|
||||
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<int,string>|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();
|
||||
}
|
||||
}
|
||||
|
||||
158
system/src/DOMWordsIterator.php
Normal file
158
system/src/DOMWordsIterator.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Iterates individual words of DOM text and CDATA nodes
|
||||
* while keeping track of their position in the document.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $doc = new DOMDocument();
|
||||
* $doc->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<int,string>
|
||||
*/
|
||||
|
||||
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<int,array<int,int|string>>|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();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -248,6 +248,7 @@ abstract class BaseAsset extends PropertyObject
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return ['type' => $this->getType(), 'elements' => $this->getElements()];
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -122,7 +122,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}";
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -145,7 +145,7 @@ class Backups
|
||||
{
|
||||
$backups = static::getAvailableBackups();
|
||||
|
||||
return array_sum(array_column($backups, 'size'));
|
||||
return $backups ? array_sum(array_column($backups, 'size')) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @package Grav\Common\Data
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -115,23 +115,29 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
/**
|
||||
* Flatten data by using blueprints.
|
||||
*
|
||||
* @param array $data Data to be flattened.
|
||||
* @param bool $includeAll
|
||||
* @param array $data Data to be flattened.
|
||||
* @param bool $includeAll True if undefined properties should also be included.
|
||||
* @param string $name Property which will be flattened, useful for flattening repeating data.
|
||||
* @return array
|
||||
*/
|
||||
public function flattenData(array $data, bool $includeAll = false)
|
||||
public function flattenData(array $data, bool $includeAll = false, string $name = '')
|
||||
{
|
||||
$prefix = $name !== '' ? $name . '.' : '';
|
||||
|
||||
$list = [];
|
||||
if ($includeAll) {
|
||||
foreach ($this->items as $key => $rules) {
|
||||
$items = $name !== '' ? $this->getProperty($name)['fields'] ?? [] : $this->items;
|
||||
foreach ($items as $key => $rules) {
|
||||
$type = $rules['type'] ?? '';
|
||||
if (!str_starts_with($type, '_') && !str_contains($key, '*')) {
|
||||
$list[$key] = null;
|
||||
$list[$prefix . $key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_replace($list, $this->flattenArray($data, $this->nested, ''));
|
||||
$nested = $this->getNestedRules($name);
|
||||
|
||||
return array_replace($list, $this->flattenArray($data, $nested, $prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @package Grav\Common\Data
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -816,7 +816,7 @@ class Validation
|
||||
{
|
||||
$value = static::filterArray($value, $params, $field);
|
||||
|
||||
return Utils::arrayUnflattenDotNotation($value);
|
||||
return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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<PageObject>
|
||||
* @template T as PageObject
|
||||
* @extends FlexPageCollection<T>
|
||||
* @implements PageCollectionInterface<string,T>
|
||||
*
|
||||
* 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<T>
|
||||
*/
|
||||
public function merge(PageCollectionInterface $collection)
|
||||
{
|
||||
@@ -185,6 +182,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
*
|
||||
* @param PageCollectionInterface $collection
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
public function append($items)
|
||||
{
|
||||
@@ -252,6 +252,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
*
|
||||
* @param int $size
|
||||
* @return static[]
|
||||
* @phpstan-return static<T>[]
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
public function order($by, $dir = 'asc', $manual = null, $sort_flags = null)
|
||||
{
|
||||
@@ -441,6 +443,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
* @param string|null $endDate
|
||||
* @param string|null $field
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
* @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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
public function modules()
|
||||
{
|
||||
@@ -544,6 +551,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
* Alias of modules()
|
||||
*
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function modular()
|
||||
{
|
||||
@@ -554,6 +562,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
* Alias of pages()
|
||||
*
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
public function nonRoutable()
|
||||
{
|
||||
@@ -633,6 +646,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
*
|
||||
* @param string $type
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function ofType($type)
|
||||
{
|
||||
@@ -651,6 +665,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
*
|
||||
* @param string[] $types
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function ofOneOfTheseTypes($types)
|
||||
{
|
||||
@@ -669,6 +684,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
*
|
||||
* @param array $accessLevels
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function ofOneOfTheseAccessLevels($accessLevels)
|
||||
{
|
||||
@@ -710,6 +726,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
/**
|
||||
* @param bool $bool
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function withOrdered(bool $bool = true)
|
||||
{
|
||||
@@ -721,6 +738,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
/**
|
||||
* @param bool $bool
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
public function withModules(bool $bool = true)
|
||||
{
|
||||
@@ -732,6 +750,7 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
|
||||
/**
|
||||
* @param bool $bool
|
||||
* @return static
|
||||
* @phpstan-return static<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
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<T>
|
||||
*/
|
||||
public function filterBy(array $filters, bool $recursive = false)
|
||||
{
|
||||
|
||||
@@ -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<PageObject,PageCollection>
|
||||
* @template T of PageObject
|
||||
* @template C of PageCollection
|
||||
* @extends FlexPageIndex<T,C>
|
||||
* @implements PageCollectionInterface<string,T>
|
||||
*
|
||||
* @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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
protected function createFrom(array $entries, string $keyField = null)
|
||||
{
|
||||
@@ -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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
* @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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
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<T,C>
|
||||
*/
|
||||
public function nonRoutable()
|
||||
{
|
||||
@@ -1105,6 +1136,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
*
|
||||
* @param string $type
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T,C>
|
||||
*/
|
||||
public function ofType($type)
|
||||
{
|
||||
@@ -1118,6 +1150,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
*
|
||||
* @param string[] $types
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T,C>
|
||||
*/
|
||||
public function ofOneOfTheseTypes($types)
|
||||
{
|
||||
@@ -1131,6 +1164,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
*
|
||||
* @param array $accessLevels
|
||||
* @return static The collection
|
||||
* @phpstan-return static<T,C>
|
||||
*/
|
||||
public function ofOneOfTheseAccessLevels($accessLevels)
|
||||
{
|
||||
|
||||
@@ -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<string,PageObject>|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) {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -79,6 +79,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 +125,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 +141,14 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
parent::__construct($elements, $key, $directory, $validate);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->_access = null;
|
||||
$this->_groups = null;
|
||||
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -231,13 +242,19 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface|null $user
|
||||
* @return bool
|
||||
*/
|
||||
public function isMyself(): bool
|
||||
public function isMyself(?UserInterface $user = null): bool
|
||||
{
|
||||
$me = $this->getActiveUser();
|
||||
if (null === $user) {
|
||||
$user = $this->getActiveUser();
|
||||
if ($user && !$user->authenticated) {
|
||||
$user = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $me && $me->authenticated && $this->username === $me->username;
|
||||
return $user && $this->username === $user->username;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,8 +294,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
// Check custom application access.
|
||||
$authorizeCallable = static::$authorizeCallable;
|
||||
if ($authorizeCallable instanceof Closure) {
|
||||
$authorizeCallable->bindTo($this);
|
||||
$authorized = $authorizeCallable($action, $scope);
|
||||
$callable = $authorizeCallable->bindTo($this, $this);
|
||||
$authorized = $callable($action, $scope);
|
||||
if (is_bool($authorized)) {
|
||||
return $authorized;
|
||||
}
|
||||
@@ -683,6 +700,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';
|
||||
@@ -898,7 +925,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;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user