From 38a393d605f6e39b5852fefd14e6183ab82db269 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 19 Mar 2021 17:22:50 -0600 Subject: [PATCH 01/23] ignore error during `set_time_limit` in `Archiver` - fixes #3023 --- CHANGELOG.md | 6 ++++++ system/src/Grav/Common/Filesystem/Archiver.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c27430419..0901a1894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.10 +## mm/dd/2021 + +1. [](#bugfix) + * Ignore errors when using `set_time_limit` in `Archiver` class. [#3023](https://github.com/getgrav/grav/issues/3023) + # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Filesystem/Archiver.php b/system/src/Grav/Common/Filesystem/Archiver.php index 96aaa0eed..090bc13fa 100644 --- a/system/src/Grav/Common/Filesystem/Archiver.php +++ b/system/src/Grav/Common/Filesystem/Archiver.php @@ -62,7 +62,7 @@ abstract class Archiver { // Set infinite PHP execution time if possible. if (Utils::functionExists('set_time_limit')) { - set_time_limit(0); + @set_time_limit(0); } $this->options = $options + $this->options; From 802ae5b7125c18269dfb354425870fc308bb66f0 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Sat, 20 Mar 2021 08:48:30 +0200 Subject: [PATCH 02/23] Ignore errors when using `set_time_limit` also in `GPM\Response` classes [#3023] --- CHANGELOG.md | 2 +- system/src/Grav/Common/GPM/Response.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0901a1894..9932afc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## mm/dd/2021 1. [](#bugfix) - * Ignore errors when using `set_time_limit` in `Archiver` class. [#3023](https://github.com/getgrav/grav/issues/3023) + * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/GPM/Response.php b/system/src/Grav/Common/GPM/Response.php index 6f3ae4e75..47cef7c09 100644 --- a/system/src/Grav/Common/GPM/Response.php +++ b/system/src/Grav/Common/GPM/Response.php @@ -53,7 +53,7 @@ class Response // 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); + @set_time_limit(0); } } catch (Exception $e) { } From 0491bd1a762c764e4096710fd6409475b3e141a2 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 09:18:43 +0200 Subject: [PATCH 03/23] Fixed moving page to itself causing the page folder to be lost (converted to an empty file) --- CHANGELOG.md | 1 + system/src/Grav/Common/Flex/Types/Pages/PageObject.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9932afc5d..0e92b8036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#bugfix) * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) + * Fixed moving page to itself causing the page folder to be lost (converted to an empty file) # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 9ed8b671b..20788dc1e 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -204,9 +204,10 @@ class PageObject extends FlexPageObject } // Make sure page isn't being moved under itself. - $key = $this->getKey(); + $key = $this->getStorageKey(); + if ($key === $parentKey || strpos($parentKey, $key . '/') === 0) { - throw new RuntimeException(sprintf('Page /%s cannot be moved to %s', $key, $parentRoute)); + throw new RuntimeException(sprintf('Page /%s cannot be moved to %s', $this->getKey(), $parentRoute)); } /** @var PageObject|null $parent */ From eb89c00bd5d383da1b260233216f9973124f063a Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 09:20:21 +0200 Subject: [PATCH 04/23] Fixed `PageStorage` detecting files as pages --- CHANGELOG.md | 1 + system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e92b8036..a7c9a4772 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#bugfix) * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) * Fixed moving page to itself causing the page folder to be lost (converted to an empty file) + * Fixed `PageStorage` detecting files as pages # v1.7.9 ## 03/19/2021 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 0ccb85661..e02bda4ab 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php +++ b/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php @@ -534,7 +534,7 @@ class PageStorage extends FolderStorage $markdown = []; $children = []; - if (is_string($path) && file_exists($path)) { + if (is_string($path) && is_dir($path)) { $modified = filemtime($path); $iterator = new FilesystemIterator($path, $this->flags); From fa819064ef2145e2c5e7d72a6ca2284809266051 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 09:45:31 +0200 Subject: [PATCH 05/23] Improve move page into itself check --- system/src/Grav/Common/Flex/Types/Pages/PageObject.php | 4 ---- .../Common/Flex/Types/Pages/Storage/PageStorage.php | 10 +++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 20788dc1e..c8568cf74 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -206,10 +206,6 @@ class PageObject extends FlexPageObject // Make sure page isn't being moved under itself. $key = $this->getStorageKey(); - if ($key === $parentKey || strpos($parentKey, $key . '/') === 0) { - throw new RuntimeException(sprintf('Page /%s cannot be moved to %s', $this->getKey(), $parentRoute)); - } - /** @var PageObject|null $parent */ $parent = $parentKey !== false ? $this->getFlexDirectory()->getObject($parentKey, 'storage_key') : null; if (!$parent) { 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 e02bda4ab..1311e0458 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php +++ b/system/src/Grav/Common/Flex/Types/Pages/Storage/PageStorage.php @@ -373,7 +373,7 @@ class PageStorage extends FolderStorage try { if ($key === '' && empty($row['root'])) { - throw new RuntimeException('No storage key given'); + throw new RuntimeException('Page has no path'); } $grav = Grav::instance(); @@ -394,9 +394,17 @@ class PageStorage extends FolderStorage if ($oldFolder !== $newFolder && file_exists($oldFolder)) { $isCopy = $row['__META']['copy'] ?? false; if ($isCopy) { + if (strpos($newFolder, $oldFolder . '/') === 0) { + throw new RuntimeException(sprintf('Page /%s cannot be copied to itself', $oldKey)); + } + $this->copyRow($oldKey, $newKey); $debugger->addMessage("Page copied: {$oldFolder} => {$newFolder}", 'debug'); } else { + if (strpos($newFolder, $oldFolder . '/') === 0) { + throw new RuntimeException(sprintf('Page /%s cannot be moved to itself', $oldKey)); + } + $this->renameRow($oldKey, $newKey); $debugger->addMessage("Page moved: {$oldFolder} => {$newFolder}", 'debug'); } From 9eb20e37c8dadf79a8cdae65e720f90b2651b8ed Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 10:16:26 +0200 Subject: [PATCH 06/23] Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead --- CHANGELOG.md | 3 ++- system/src/Grav/Common/Filesystem/Folder.php | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c9a4772..8fd756d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ 1. [](#bugfix) * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) - * Fixed moving page to itself causing the page folder to be lost (converted to an empty file) + * Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead + * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) * Fixed `PageStorage` detecting files as pages # v1.7.9 diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index ef09cee76..6a3783b91 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -371,6 +371,10 @@ abstract class Folder return; } + if (strpos($target, $source) === 0) { + throw new RuntimeException('Cannot move folder to itself'); + } + if (file_exists($target)) { // Rename fails if target folder exists. throw new RuntimeException('Cannot move files to existing folder/file.'); @@ -383,11 +387,7 @@ abstract class Folder @rename($source, $target); // Rename function can fail while still succeeding, so let's check if the folder exists. - if (!file_exists($target) || !is_dir($target)) { - // In some rare cases rename() creates file, not a folder. Get rid of it. - if (file_exists($target)) { - @unlink($target); - } + if (is_dir($source)) { // Rename doesn't support moving folders across filesystems. Use copy instead. self::copy($source, $target); self::delete($source); From 35468bb417b734f8c2c5cebba23ad8271229b961 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 10:31:10 +0200 Subject: [PATCH 07/23] Minor docblock fix --- CHANGELOG.md | 2 +- system/src/Grav/Common/GPM/Licenses.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd756d8c..b67eaefe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) * Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) - * Fixed `PageStorage` detecting files as pages + * Fixed `PageStorage` from detecting files as pages # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/GPM/Licenses.php b/system/src/Grav/Common/GPM/Licenses.php index 662a14624..825343dd8 100644 --- a/system/src/Grav/Common/GPM/Licenses.php +++ b/system/src/Grav/Common/GPM/Licenses.php @@ -63,7 +63,7 @@ class Licenses * Returns the license for a Premium package * * @param string|null $slug - * @return array|string + * @return string[]|string */ public static function get($slug = null) { From 42084ea0cb5f3aebcb385a1a797af72000b6d1e1 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 23 Mar 2021 12:58:11 +0200 Subject: [PATCH 08/23] Fixed `UserIndex` not implementing `UserCollectionInterface` --- CHANGELOG.md | 1 + .../Common/Flex/Types/Users/UserIndex.php | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b67eaefe3..7267f3877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) * Fixed `PageStorage` from detecting files as pages + * Fixed `UserIndex` not implementing `UserCollectionInterface` # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php index 4735c933e..68bbb780e 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php @@ -15,6 +15,7 @@ use Grav\Common\Debugger; use Grav\Common\File\CompiledYamlFile; use Grav\Common\Flex\FlexIndex; use Grav\Common\Grav; +use Grav\Common\User\Interfaces\UserCollectionInterface; use Grav\Common\User\Interfaces\UserInterface; use Grav\Framework\Flex\Interfaces\FlexStorageInterface; use Monolog\Logger; @@ -28,7 +29,7 @@ use function method_exists; * * @extends FlexIndex */ -class UserIndex extends FlexIndex +class UserIndex extends FlexIndex implements UserCollectionInterface { public const VERSION = parent::VERSION . '.1'; @@ -106,6 +107,24 @@ class UserIndex extends FlexIndex return $object; } + /** + * Delete user account. + * + * @param string $username + * @return bool True if user account was found and was deleted. + */ + public function delete($username): bool + { + $user = $this->load($username); + + $exists = $user->exists(); + if ($exists) { + $user->delete(); + } + + return $exists; + } + /** * Find a user by username, email, etc * From e229ab191f368302099e3afdf261ea29c9a12273 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 26 Mar 2021 10:53:14 +0200 Subject: [PATCH 09/23] Improved password handling when saving a user --- CHANGELOG.md | 2 ++ .../Grav/Common/Flex/Types/Users/UserObject.php | 15 ++++++++++----- system/src/Grav/Common/User/DataUser/User.php | 13 ++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7267f3877..5836f1a2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.7.10 ## mm/dd/2021 +1. [](#improved) + * Improved password handling when saving a user 1. [](#bugfix) * Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023) * Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead diff --git a/system/src/Grav/Common/Flex/Types/Users/UserObject.php b/system/src/Grav/Common/Flex/Types/Users/UserObject.php index 26da6a02e..4109eec34 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserObject.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserObject.php @@ -538,13 +538,18 @@ class UserObject extends FlexObject implements UserInterface, Countable } } - $password = $this->getProperty('password'); - if (null !== $password) { - $this->unsetProperty('password'); - $this->unsetProperty('password1'); - $this->unsetProperty('password2'); + $password = $this->getProperty('password') ?? $this->getProperty('password1'); + if (null !== $password && '' !== $password) { + $password2 = $this->getProperty('password2'); + if (!\is_string($password) || ($password2 && $password !== $password2)) { + throw new \RuntimeException('Passwords did not match.'); + } + $this->setProperty('hashed_password', Authentication::create($password)); } + $this->unsetProperty('password'); + $this->unsetProperty('password1'); + $this->unsetProperty('password2'); // Backwards compatibility with older plugins. $fireEvents = $this->isAdminSite() && $this->getFlexDirectory()->getConfig('object.compat.events', true); diff --git a/system/src/Grav/Common/User/DataUser/User.php b/system/src/Grav/Common/User/DataUser/User.php index d81381777..47353425d 100644 --- a/system/src/Grav/Common/User/DataUser/User.php +++ b/system/src/Grav/Common/User/DataUser/User.php @@ -131,11 +131,18 @@ class User extends Data implements UserInterface } // if plain text password, hash it and remove plain text - $password = $this->get('password'); - if ($password) { + $password = $this->get('password') ?? $this->get('password1'); + if (null !== $password && '' !== $password) { + $password2 = $this->get('password2'); + if (!\is_string($password) || ($password2 && $password !== $password2)) { + throw new \RuntimeException('Passwords did not match.'); + } + $this->set('hashed_password', Authentication::create($password)); - $this->undef('password'); } + $this->undef('password'); + $this->undef('password1'); + $this->undef('password2'); $data = $this->items; if ($username === $data['username']) { From 1b9fd6276eed8fa00e73b183e16ec8263ec57716 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 30 Mar 2021 16:58:19 +0300 Subject: [PATCH 10/23] Added initial support for running Grav library from outside the webroot [#3297] --- CHANGELOG.md | 2 ++ system/defines.php | 21 ++++++++++++------- system/src/Grav/Common/Assets/BaseAsset.php | 12 +++++------ system/src/Grav/Common/Config/Setup.php | 11 +++++----- .../Common/Processors/InitializeProcessor.php | 2 +- .../Common/Service/StreamsServiceProvider.php | 2 +- system/src/Grav/Installer/Install.php | 4 ++-- system/src/Grav/Installer/Versions.php | 2 +- 8 files changed, 33 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5836f1a2e..77ae84781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.7.10 ## mm/dd/2021 +1. [](#new) + * Added initial support for running Grav library from outside the webroot [#3297](https://github.com/getgrav/grav/issues/3297) 1. [](#improved) * Improved password handling when saving a user 1. [](#bugfix) diff --git a/system/defines.php b/system/defines.php index e7f365a01..353703825 100644 --- a/system/defines.php +++ b/system/defines.php @@ -27,10 +27,17 @@ if (!defined('GRAV_ROOT')) { $path = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, getenv('GRAV_ROOT') ?: getcwd()), DS); define('GRAV_ROOT', $path); } +if (!defined('GRAV_WEBROOT')) { + define('GRAV_WEBROOT', GRAV_ROOT); +} if (!defined('GRAV_USER_PATH')) { $path = rtrim(getenv('GRAV_USER_PATH') ?: 'user', DS); define('GRAV_USER_PATH', $path); } +if (!defined('GRAV_SYSTEM_PATH')) { + $path = rtrim(getenv('GRAV_SYSTEM_PATH') ?: 'system', DS); + define('GRAV_SYSTEM_PATH', $path); +} if (!defined('GRAV_CACHE_PATH')) { $path = rtrim(getenv('GRAV_CACHE_PATH') ?: 'cache', DS); define('GRAV_CACHE_PATH', $path); @@ -52,21 +59,21 @@ unset($path); define('USER_PATH', GRAV_USER_PATH . DS); define('CACHE_PATH', GRAV_CACHE_PATH . DS); define('ROOT_DIR', GRAV_ROOT . DS); -define('USER_DIR', ROOT_DIR . USER_PATH); -define('CACHE_DIR', ROOT_DIR . CACHE_PATH); +define('USER_DIR', (!str_starts_with(USER_PATH, '/') ? GRAV_WEBROOT . '/' : '') . USER_PATH); +define('CACHE_DIR', (!str_starts_with(CACHE_PATH, '/') ? ROOT_DIR : '') . CACHE_PATH); // DEPRECATED: Do not use! -define('ASSETS_DIR', ROOT_DIR . 'assets/'); -define('IMAGES_DIR', ROOT_DIR . 'images/'); +define('ASSETS_DIR', GRAV_WEBROOT . '/assets/'); +define('IMAGES_DIR', GRAV_WEBROOT . '/images/'); define('ACCOUNTS_DIR', USER_DIR .'accounts/'); define('PAGES_DIR', USER_DIR .'pages/'); define('DATA_DIR', USER_DIR .'data/'); -define('SYSTEM_DIR', ROOT_DIR .'system/'); -define('LIB_DIR', SYSTEM_DIR .'src/'); define('PLUGINS_DIR', USER_DIR .'plugins/'); define('THEMES_DIR', USER_DIR .'themes/'); +define('SYSTEM_DIR', (!str_starts_with(GRAV_SYSTEM_PATH, '/') ? ROOT_DIR : '') . GRAV_SYSTEM_PATH); +define('LIB_DIR', SYSTEM_DIR .'src/'); define('VENDOR_DIR', ROOT_DIR .'vendor/'); -define('LOG_DIR', ROOT_DIR . GRAV_LOG_PATH . DS); +define('LOG_DIR', (!str_starts_with(GRAV_LOG_PATH, '/') ? ROOT_DIR : '') . GRAV_LOG_PATH . DS); // END DEPRECATED // Some extensions diff --git a/system/src/Grav/Common/Assets/BaseAsset.php b/system/src/Grav/Common/Assets/BaseAsset.php index 423c84236..6d1f9015e 100644 --- a/system/src/Grav/Common/Assets/BaseAsset.php +++ b/system/src/Grav/Common/Assets/BaseAsset.php @@ -125,7 +125,7 @@ abstract class BaseAsset extends PropertyObject if ($locator->isStream($asset)) { $path = $locator->findResource($asset, true); } else { - $path = GRAV_ROOT . $asset; + $path = GRAV_WEBROOT . $asset; } // If local file is missing return @@ -172,10 +172,10 @@ abstract class BaseAsset extends PropertyObject return $this; } - + /** * Receive asset location and return the SRI integrity hash - * + * * @param $input * * @return string @@ -188,7 +188,7 @@ abstract class BaseAsset extends PropertyObject if ( !empty($assetsConfig['enable_asset_sri']) && $assetsConfig['enable_asset_sri'] ) { - $dataToHash = file_get_contents( GRAV_ROOT . $input); + $dataToHash = file_get_contents( GRAV_WEBROOT . $input); $hash = hash('sha256', $dataToHash, true); $hash_base64 = base64_encode($hash); @@ -209,7 +209,7 @@ abstract class BaseAsset extends PropertyObject */ // protected function getLastModificationTime($asset) // { -// $file = GRAV_ROOT . $asset; +// $file = GRAV_WEBROOT . $asset; // if (Grav::instance()['locator']->isStream($asset)) { // $file = $this->buildLocalLink($asset, true); // } @@ -228,7 +228,7 @@ abstract class BaseAsset extends PropertyObject protected function buildLocalLink($asset) { if ($asset) { - return $this->base_url . ltrim(Utils::replaceFirstOccurrence(GRAV_ROOT, '', $asset), '/'); + return $this->base_url . ltrim(Utils::replaceFirstOccurrence(GRAV_WEBROOT, '', $asset), '/'); } return false; } diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php index ef2176a3e..e01f50eb5 100644 --- a/system/src/Grav/Common/Config/Setup.php +++ b/system/src/Grav/Common/Config/Setup.php @@ -164,6 +164,7 @@ class Setup extends Data public function __construct($container) { // Configure main streams. + $this->streams['system']['prefixes'][''] = [GRAV_SYSTEM_PATH]; $this->streams['user']['prefixes'][''] = [GRAV_USER_PATH]; $this->streams['cache']['prefixes'][''] = [GRAV_CACHE_PATH]; $this->streams['log']['prefixes'][''] = [GRAV_LOG_PATH]; @@ -197,16 +198,16 @@ class Setup extends Data if (null !== $setupFile) { // Make sure that the custom setup file exists. Terminates the script if not. if (!str_starts_with($setupFile, '/')) { - $setupFile = GRAV_ROOT . '/' . $setupFile; + $setupFile = GRAV_WEBROOT . '/' . $setupFile; } if (!is_file($setupFile)) { echo 'GRAV_SETUP_PATH is defined but does not point to existing setup file.'; exit(1); } } else { - $setupFile = GRAV_ROOT . '/setup.php'; + $setupFile = GRAV_WEBROOT . '/setup.php'; if (!is_file($setupFile)) { - $setupFile = GRAV_ROOT . '/' . GRAV_USER_PATH . '/setup.php'; + $setupFile = GRAV_WEBROOT . '/' . GRAV_USER_PATH . '/setup.php'; } if (!is_file($setupFile)) { $setupFile = null; @@ -234,7 +235,7 @@ class Setup extends Data $envPath .= '/'; } else { // Use default location. Start with Grav 1.7 default. - $envPath = GRAV_ROOT. '/' . GRAV_USER_PATH . '/env'; + $envPath = GRAV_WEBROOT. '/' . GRAV_USER_PATH . '/env'; if (is_dir($envPath)) { $envPath = 'user://env/'; } else { @@ -257,7 +258,7 @@ class Setup extends Data */ public function init() { - $locator = new UniformResourceLocator(GRAV_ROOT); + $locator = new UniformResourceLocator(GRAV_WEBROOT); $files = []; $guard = 5; diff --git a/system/src/Grav/Common/Processors/InitializeProcessor.php b/system/src/Grav/Common/Processors/InitializeProcessor.php index ea23fa880..0f8567fcf 100644 --- a/system/src/Grav/Common/Processors/InitializeProcessor.php +++ b/system/src/Grav/Common/Processors/InitializeProcessor.php @@ -178,7 +178,7 @@ class InitializeProcessor extends ProcessorBase $grav['plugins']->setup(); if (defined('GRAV_SCHEMA') && $config->get('versions') === null) { - $filename = GRAV_ROOT . '/user/config/versions.yaml'; + $filename = USER_DIR . 'config/versions.yaml'; if (!is_file($filename)) { $versions = [ 'core' => [ diff --git a/system/src/Grav/Common/Service/StreamsServiceProvider.php b/system/src/Grav/Common/Service/StreamsServiceProvider.php index 2099d06d1..edde09ad5 100644 --- a/system/src/Grav/Common/Service/StreamsServiceProvider.php +++ b/system/src/Grav/Common/Service/StreamsServiceProvider.php @@ -30,7 +30,7 @@ class StreamsServiceProvider implements ServiceProviderInterface public function register(Container $container) { $container['locator'] = function (Container $container) { - $locator = new UniformResourceLocator(GRAV_ROOT); + $locator = new UniformResourceLocator(GRAV_WEBROOT); /** @var Setup $setup */ $setup = $container['setup']; diff --git a/system/src/Grav/Installer/Install.php b/system/src/Grav/Installer/Install.php index def3446dc..4df9dcd56 100644 --- a/system/src/Grav/Installer/Install.php +++ b/system/src/Grav/Installer/Install.php @@ -232,7 +232,7 @@ ERR; $this->location = dirname($location, 4); - $versions = Versions::instance(GRAV_ROOT . '/user/config/versions.yaml'); + $versions = Versions::instance(USER_DIR . 'config/versions.yaml'); $this->updater = new VersionUpdater('core/grav', __DIR__ . '/updates', $this->getVersion(), $versions); $this->updater->preflight(); @@ -280,7 +280,7 @@ ERR; { // Finalize can be run without installing Grav first. if (!$this->updater) { - $versions = Versions::instance(GRAV_ROOT . '/user/config/versions.yaml'); + $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/Versions.php b/system/src/Grav/Installer/Versions.php index cc2687504..03f3b0b0f 100644 --- a/system/src/Grav/Installer/Versions.php +++ b/system/src/Grav/Installer/Versions.php @@ -36,7 +36,7 @@ final class Versions */ public static function instance(string $filename = null): self { - $filename = $filename ?? GRAV_ROOT . '/user/config/versions.yaml'; + $filename = $filename ?? USER_DIR . 'config/versions.yaml'; if (!isset(self::$instance[$filename])) { self::$instance[$filename] = new self($filename); From a8e6aedd043107a3eb2dc47bc7e2509ffb6b6db5 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 30 Mar 2021 19:14:49 +0300 Subject: [PATCH 11/23] Fixed missing `onAdminAfterDelete` event call in `Flex Pages` --- CHANGELOG.md | 1 + .../Grav/Common/Flex/Types/Pages/PageObject.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ae84781..234dba339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) * Fixed `PageStorage` from detecting files as pages * Fixed `UserIndex` not implementing `UserCollectionInterface` + * Fixed missing `onAdminAfterDelete` event call in `Flex Pages` # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index c8568cf74..63f4cd4d4 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -298,6 +298,22 @@ class PageObject extends FlexPageObject return $instance; } + /** + * @return PageObject + */ + public function delete() + { + $result = parent::delete(); + + // Backwards compatibility with older plugins. + $fireEvents = $this->isAdminSite() && $this->getFlexDirectory()->getConfig('object.compat.events', true); + if ($fireEvents) { + $this->grav->fireEvent('onAdminAfterDelete', new Event(['object' => $this])); + } + + return $result; + } + /** * Prepare move page to new location. Moves also everything that's under the current page. * From bbddb0a036e5697abdf13b2c0d3eb5bcb3c02601 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 30 Mar 2021 11:53:27 -0600 Subject: [PATCH 12/23] system blueprints not getting scanned. Fixes #3296 --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Types.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ae84781..cbc058537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) * Fixed `PageStorage` from detecting files as pages * Fixed `UserIndex` not implementing `UserCollectionInterface` + * Fixed system templates not getting scanned [#3296](https://github.com/getgrav/grav/issues/3296) # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index b9d8f9551..c7183680e 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -61,7 +61,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable */ public function init() { - if (null === $this->systemBlueprints) { + if (empty($this->systemBlueprints)) { // Register all blueprints from the blueprints stream. $this->systemBlueprints = $this->findBlueprints('blueprints://pages'); foreach ($this->systemBlueprints as $type => $blueprint) { From 2a4376b7cbbd825a88feb8fd83d4210dfbd10f0a Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 08:55:19 +0300 Subject: [PATCH 13/23] Fixed undefined variable (regression) --- system/src/Grav/Common/Flex/Types/Pages/PageObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 63f4cd4d4..933a00a32 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -308,7 +308,7 @@ class PageObject extends FlexPageObject // Backwards compatibility with older plugins. $fireEvents = $this->isAdminSite() && $this->getFlexDirectory()->getConfig('object.compat.events', true); if ($fireEvents) { - $this->grav->fireEvent('onAdminAfterDelete', new Event(['object' => $this])); + $this->getContainer()->fireEvent('onAdminAfterDelete', new Event(['object' => $this])); } return $result; From 4f0f7876a8cb3a19db64b125e7256df0c9b8e281 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 10:26:46 +0300 Subject: [PATCH 14/23] Better support absolute GRAV_SYSTEM_PATH [#3297] --- CHANGELOG.md | 3 +-- system/src/Grav/Common/Config/Setup.php | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bea26204..10d38ffe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,8 @@ * Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227) * Fixed `PageStorage` from detecting files as pages * Fixed `UserIndex` not implementing `UserCollectionInterface` - * Fixed system templates not getting scanned [#3296](https://github.com/getgrav/grav/issues/3296) * Fixed missing `onAdminAfterDelete` event call in `Flex Pages` ->>>>>>> a8e6aedd043107a3eb2dc47bc7e2509ffb6b6db5 + * Fixed system templates not getting scanned [#3296](https://github.com/getgrav/grav/issues/3296) # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php index e01f50eb5..5693a921f 100644 --- a/system/src/Grav/Common/Config/Setup.php +++ b/system/src/Grav/Common/Config/Setup.php @@ -164,7 +164,8 @@ class Setup extends Data public function __construct($container) { // Configure main streams. - $this->streams['system']['prefixes'][''] = [GRAV_SYSTEM_PATH]; + $abs = str_starts_with(GRAV_SYSTEM_PATH, '/'); + $this->streams['system']['prefixes'][''] = $abs ? ['system', GRAV_SYSTEM_PATH] : ['system']; $this->streams['user']['prefixes'][''] = [GRAV_USER_PATH]; $this->streams['cache']['prefixes'][''] = [GRAV_CACHE_PATH]; $this->streams['log']['prefixes'][''] = [GRAV_LOG_PATH]; From f78debe768758e98da3f641f41bab7005bb41807 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 14:02:57 +0300 Subject: [PATCH 15/23] Plugin class phpstan fix --- system/src/Grav/Common/Plugin.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 65b11dba1..122ac2460 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -36,7 +36,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess /** @var Grav */ protected $grav; - /** @var Config|null */ + /** @var Config */ protected $config; /** @var bool */ protected $active = true; @@ -74,9 +74,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess $this->name = $name; $this->grav = $grav; - if ($config) { - $this->setConfig($config); - } + $this->setConfig($config ?? $grav['config']); } /** @@ -97,7 +95,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess */ public function config() { - return null !== $this->config ? $this->config["plugins.{$this->name}"] : []; + return $this->config["plugins.{$this->name}"]; } /** @@ -132,8 +130,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess /** @var Uri $uri */ $uri = $this->grav['uri']; - /** @var Config $config */ - $config = $this->config ?? $this->grav['config']; + $config = $this->config; if (strpos($uri->path(), $config->get('plugins.admin.route') . '/' . $plugin_route) === false) { $active = false; @@ -307,8 +304,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess */ protected function mergeConfig(PageInterface $page, $deep = false, $params = [], $type = 'plugins') { - /** @var Config $config */ - $config = $this->config ?? $this->grav['config']; + $config = $this->config; $class_name = $this->name; $class_name_merged = $class_name . '.merged'; From edafa684148b81a7468b3055e05d633744eefe13 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 14:29:50 +0300 Subject: [PATCH 16/23] Revert "Plugin class phpstan fix" This reverts commit f78debe7 --- system/src/Grav/Common/Plugin.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 122ac2460..65b11dba1 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -36,7 +36,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess /** @var Grav */ protected $grav; - /** @var Config */ + /** @var Config|null */ protected $config; /** @var bool */ protected $active = true; @@ -74,7 +74,9 @@ class Plugin implements EventSubscriberInterface, ArrayAccess $this->name = $name; $this->grav = $grav; - $this->setConfig($config ?? $grav['config']); + if ($config) { + $this->setConfig($config); + } } /** @@ -95,7 +97,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess */ public function config() { - return $this->config["plugins.{$this->name}"]; + return null !== $this->config ? $this->config["plugins.{$this->name}"] : []; } /** @@ -130,7 +132,8 @@ class Plugin implements EventSubscriberInterface, ArrayAccess /** @var Uri $uri */ $uri = $this->grav['uri']; - $config = $this->config; + /** @var Config $config */ + $config = $this->config ?? $this->grav['config']; if (strpos($uri->path(), $config->get('plugins.admin.route') . '/' . $plugin_route) === false) { $active = false; @@ -304,7 +307,8 @@ class Plugin implements EventSubscriberInterface, ArrayAccess */ protected function mergeConfig(PageInterface $page, $deep = false, $params = [], $type = 'plugins') { - $config = $this->config; + /** @var Config $config */ + $config = $this->config ?? $this->grav['config']; $class_name = $this->name; $class_name_merged = $class_name . '.merged'; From 0af33850a68dd2e9d3e3a9e1bd2d25215b958eb5 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 20:08:39 +0300 Subject: [PATCH 17/23] Fixed incorrect routing if url path looks like a domain name [#2184] --- CHANGELOG.md | 1 + system/src/Grav/Common/Uri.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10d38ffe2..9bbfbd4d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fixed `UserIndex` not implementing `UserCollectionInterface` * Fixed missing `onAdminAfterDelete` event call in `Flex Pages` * Fixed system templates not getting scanned [#3296](https://github.com/getgrav/grav/issues/3296) + * Fixed incorrect routing if url path looks like a domain name [#2184](https://github.com/getgrav/grav/issues/2184) # v1.7.9 ## 03/19/2021 diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index f7046083d..d0d6ad5e0 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -205,8 +205,8 @@ class Uri // set active language $uri = $language->setActiveFromUri($uri); - // split the URL and params - $bits = parse_url($uri); + // split the URL and params (and make sure that the path isn't seen as domain) + $bits = parse_url('http://domain.com' . $uri); //process fragment if (isset($bits['fragment'])) { From 38b1556ee052e5b271c5abcab66e831c6bf8345e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 21:29:59 +0300 Subject: [PATCH 18/23] Fix unit test #2184 --- tests/unit/Grav/Common/UriTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/Grav/Common/UriTest.php b/tests/unit/Grav/Common/UriTest.php index 8f1601a6f..3e52ef877 100644 --- a/tests/unit/Grav/Common/UriTest.php +++ b/tests/unit/Grav/Common/UriTest.php @@ -697,14 +697,14 @@ class UriTest extends \Codeception\TestCase\Test 'password' => null, 'host' => null, 'port' => null, - 'path' => '%22%3E%3Cscript%3Ealert%3C/localhost', + 'path' => '/localhost', 'query' => '', 'fragment' => null, - 'route' => '/%22%3E%3Cscript%3Ealert%3C/localhost', - 'paths' => ['%22%3E%3Cscript%3Ealert%3C', 'localhost'], + 'route' => '/localhost', + 'paths' => ['localhost'], 'params' => '/script%3E:', - 'url' => '%22%3E%3Cscript%3Ealert%3C//localhost', + 'url' => '//localhost', 'environment' => 'unknown', 'basename' => 'localhost', 'base' => '', @@ -712,7 +712,7 @@ class UriTest extends \Codeception\TestCase\Test 'rootUrl' => '', 'extension' => null, //'addNonce' => '%22%3E%3Cscript%3Ealert%3C/localhost/script%3E:/nonce:{{nonce}}', // FIXME <- - 'toOriginalString' => '%22%3E%3Cscript%3Ealert%3C/localhost/script%3E:' // FIXME <- + 'toOriginalString' => '/localhost/script%3E:' // FIXME <- ], 'http://">' => [ 'scheme' => 'http://', From 770bf15342268092fe3973245d73194ea49caafd Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 22:09:19 +0300 Subject: [PATCH 19/23] Composer update --- composer.lock | 149 +++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 74 deletions(-) diff --git a/composer.lock b/composer.lock index 13fa1823e..350b627b3 100644 --- a/composer.lock +++ b/composer.lock @@ -642,16 +642,16 @@ }, { "name": "filp/whoops", - "version": "2.10.0", + "version": "2.12.0", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "6ecda5217bf048088b891f7403b262906be5a957" + "reference": "d501fd2658d55491a2295ff600ae5978eaad7403" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/6ecda5217bf048088b891f7403b262906be5a957", - "reference": "6ecda5217bf048088b891f7403b262906be5a957", + "url": "https://api.github.com/repos/filp/whoops/zipball/d501fd2658d55491a2295ff600ae5978eaad7403", + "reference": "d501fd2658d55491a2295ff600ae5978eaad7403", "shasum": "" }, "require": { @@ -701,7 +701,7 @@ ], "support": { "issues": "https://github.com/filp/whoops/issues", - "source": "https://github.com/filp/whoops/tree/2.10.0" + "source": "https://github.com/filp/whoops/tree/2.12.0" }, "funding": [ { @@ -709,7 +709,7 @@ "type": "github" } ], - "time": "2021-03-16T12:00:00+00:00" + "time": "2021-03-30T12:00:00+00:00" }, { "name": "gregwar/cache", @@ -812,16 +812,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", "shasum": "" }, "require": { @@ -881,9 +881,9 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.7.0" + "source": "https://github.com/guzzle/psr7/tree/1.8.1" }, - "time": "2020-09-30T07:37:11+00:00" + "time": "2021-03-21T16:25:00+00:00" }, { "name": "itsgoingd/clockwork", @@ -2246,16 +2246,16 @@ }, { "name": "symfony/console", - "version": "v4.4.20", + "version": "v4.4.21", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c98349bda966c70d6c08b4cd8658377c94166492" + "reference": "1ba4560dbbb9fcf5ae28b61f71f49c678086cf23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c98349bda966c70d6c08b4cd8658377c94166492", - "reference": "c98349bda966c70d6c08b4cd8658377c94166492", + "url": "https://api.github.com/repos/symfony/console/zipball/1ba4560dbbb9fcf5ae28b61f71f49c678086cf23", + "reference": "1ba4560dbbb9fcf5ae28b61f71f49c678086cf23", "shasum": "" }, "require": { @@ -2315,7 +2315,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.20" + "source": "https://github.com/symfony/console/tree/v4.4.21" }, "funding": [ { @@ -2331,7 +2331,7 @@ "type": "tidelift" } ], - "time": "2021-02-22T18:44:15+00:00" + "time": "2021-03-26T09:23:24+00:00" }, { "name": "symfony/contracts", @@ -2512,16 +2512,16 @@ }, { "name": "symfony/http-client", - "version": "v4.4.20", + "version": "v4.4.21", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "67c5af7489b3c2eea771abd973243f5c58f5fb40" + "reference": "911177e186b82e5b9a9f41c13af53699b6745657" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/67c5af7489b3c2eea771abd973243f5c58f5fb40", - "reference": "67c5af7489b3c2eea771abd973243f5c58f5fb40", + "url": "https://api.github.com/repos/symfony/http-client/zipball/911177e186b82e5b9a9f41c13af53699b6745657", + "reference": "911177e186b82e5b9a9f41c13af53699b6745657", "shasum": "" }, "require": { @@ -2572,7 +2572,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.20" + "source": "https://github.com/symfony/http-client/tree/v4.4.21" }, "funding": [ { @@ -2588,7 +2588,7 @@ "type": "tidelift" } ], - "time": "2021-02-25T18:06:45+00:00" + "time": "2021-03-25T17:52:07+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3055,16 +3055,16 @@ }, { "name": "symfony/var-dumper", - "version": "v4.4.20", + "version": "v4.4.21", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "a1eab2f69906dc83c5ddba4632180260d0ab4f7f" + "reference": "0da0e174f728996f5d5072d6a9f0a42259dbc806" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/a1eab2f69906dc83c5ddba4632180260d0ab4f7f", - "reference": "a1eab2f69906dc83c5ddba4632180260d0ab4f7f", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/0da0e174f728996f5d5072d6a9f0a42259dbc806", + "reference": "0da0e174f728996f5d5072d6a9f0a42259dbc806", "shasum": "" }, "require": { @@ -3124,7 +3124,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v4.4.20" + "source": "https://github.com/symfony/var-dumper/tree/v4.4.21" }, "funding": [ { @@ -3140,20 +3140,20 @@ "type": "tidelift" } ], - "time": "2021-01-27T09:09:26+00:00" + "time": "2021-03-27T19:49:03+00:00" }, { "name": "symfony/yaml", - "version": "v4.4.20", + "version": "v4.4.21", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "29e61305e1c79d25f71060903982ead8f533e267" + "reference": "3871c720871029f008928244e56cf43497da7e9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/29e61305e1c79d25f71060903982ead8f533e267", - "reference": "29e61305e1c79d25f71060903982ead8f533e267", + "url": "https://api.github.com/repos/symfony/yaml/zipball/3871c720871029f008928244e56cf43497da7e9d", + "reference": "3871c720871029f008928244e56cf43497da7e9d", "shasum": "" }, "require": { @@ -3195,7 +3195,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v4.4.20" + "source": "https://github.com/symfony/yaml/tree/v4.4.21" }, "funding": [ { @@ -3211,7 +3211,7 @@ "type": "tidelift" } ], - "time": "2021-02-22T15:36:50+00:00" + "time": "2021-03-05T17:58:50+00:00" }, { "name": "twig/twig", @@ -3415,16 +3415,16 @@ }, { "name": "codeception/codeception", - "version": "4.1.18", + "version": "4.1.19", "source": { "type": "git", "url": "https://github.com/Codeception/Codeception.git", - "reference": "f47547bac347dfb5ea5351ff91148cbcc08e6818" + "reference": "138dc9345a81ec994dcd6b9680c501a752a37b00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/Codeception/zipball/f47547bac347dfb5ea5351ff91148cbcc08e6818", - "reference": "f47547bac347dfb5ea5351ff91148cbcc08e6818", + "url": "https://api.github.com/repos/Codeception/Codeception/zipball/138dc9345a81ec994dcd6b9680c501a752a37b00", + "reference": "138dc9345a81ec994dcd6b9680c501a752a37b00", "shasum": "" }, "require": { @@ -3498,7 +3498,7 @@ ], "support": { "issues": "https://github.com/Codeception/Codeception/issues", - "source": "https://github.com/Codeception/Codeception/tree/4.1.18" + "source": "https://github.com/Codeception/Codeception/tree/4.1.19" }, "funding": [ { @@ -3506,7 +3506,7 @@ "type": "open_collective" } ], - "time": "2021-02-23T17:11:42+00:00" + "time": "2021-03-28T13:26:08+00:00" }, { "name": "codeception/lib-asserts", @@ -3893,22 +3893,22 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.2.0", + "version": "7.3.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79" + "reference": "7008573787b430c1c1f650e3722d9bba59967628" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0aa74dfb41ae110835923ef10a9d803a22d50e79", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", + "reference": "7008573787b430c1c1f650e3722d9bba59967628", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.4", - "guzzlehttp/psr7": "^1.7", + "guzzlehttp/psr7": "^1.7 || ^2.0", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0" }, @@ -3916,6 +3916,7 @@ "psr/http-client-implementation": "1.0" }, "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", "ext-curl": "*", "php-http/client-integration-tests": "^3.0", "phpunit/phpunit": "^8.5.5 || ^9.3.5", @@ -3929,7 +3930,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.1-dev" + "dev-master": "7.3-dev" } }, "autoload": { @@ -3971,7 +3972,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.2.0" + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" }, "funding": [ { @@ -3991,7 +3992,7 @@ "type": "github" } ], - "time": "2020-10-10T11:47:56+00:00" + "time": "2021-03-23T11:33:13+00:00" }, { "name": "guzzlehttp/promises", @@ -4433,16 +4434,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.2", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "245710e971a030f42e08f4912863805570f23d39" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", - "reference": "245710e971a030f42e08f4912863805570f23d39", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { @@ -4494,22 +4495,22 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.2" + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" }, - "time": "2020-12-19T10:15:11+00:00" + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.81", + "version": "0.12.82", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8" + "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", - "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3920f0fb0aff39263d3a4cb0bca120a67a1a6a11", + "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11", "shasum": "" }, "require": { @@ -4540,7 +4541,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.81" + "source": "https://github.com/phpstan/phpstan/tree/0.12.82" }, "funding": [ { @@ -4556,7 +4557,7 @@ "type": "tidelift" } ], - "time": "2021-03-08T22:03:02+00:00" + "time": "2021-03-19T06:08:17+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -4611,16 +4612,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { @@ -4676,7 +4677,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" }, "funding": [ { @@ -4684,7 +4685,7 @@ "type": "github" } ], - "time": "2020-11-28T06:44:49+00:00" + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", @@ -4929,16 +4930,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.3", + "version": "9.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "27241ac75fc37ecf862b6e002bf713b6566cbe41" + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/27241ac75fc37ecf862b6e002bf713b6566cbe41", - "reference": "27241ac75fc37ecf862b6e002bf713b6566cbe41", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", "shasum": "" }, "require": { @@ -5016,7 +5017,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" }, "funding": [ { @@ -5028,7 +5029,7 @@ "type": "github" } ], - "time": "2021-03-17T07:30:34+00:00" + "time": "2021-03-23T07:16:29+00:00" }, { "name": "psr/http-client", From e97fe9de86f8f048f1074b53de2cd12a248d0f80 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 22:11:11 +0300 Subject: [PATCH 20/23] Fixed phpstan generics --- system/src/Grav/Common/Flex/FlexCollection.php | 3 +-- system/src/Grav/Common/Flex/FlexIndex.php | 3 +-- .../Flex/Types/Generic/GenericCollection.php | 2 +- .../Common/Flex/Types/Generic/GenericIndex.php | 2 +- .../Common/Flex/Types/Pages/PageCollection.php | 2 +- .../Grav/Common/Flex/Types/Pages/PageIndex.php | 2 +- .../Types/UserGroups/UserGroupCollection.php | 2 +- .../Flex/Types/UserGroups/UserGroupIndex.php | 2 +- .../Common/Flex/Types/Users/UserCollection.php | 2 +- .../Grav/Common/Flex/Types/Users/UserIndex.php | 3 +-- .../src/Grav/Framework/Flex/FlexCollection.php | 10 ++++------ system/src/Grav/Framework/Flex/FlexDirectory.php | 3 +-- system/src/Grav/Framework/Flex/FlexIndex.php | 12 +++++------- .../Flex/Interfaces/FlexCollectionInterface.php | 16 +++++++--------- .../Flex/Interfaces/FlexIndexInterface.php | 3 +-- .../Framework/Flex/Pages/FlexPageCollection.php | 9 ++++----- .../Grav/Framework/Flex/Pages/FlexPageIndex.php | 3 +-- .../Framework/Flex/Traits/FlexMediaTrait.php | 4 ++-- 18 files changed, 35 insertions(+), 48 deletions(-) diff --git a/system/src/Grav/Common/Flex/FlexCollection.php b/system/src/Grav/Common/Flex/FlexCollection.php index a4d1bbecd..6429c9e1e 100644 --- a/system/src/Grav/Common/Flex/FlexCollection.php +++ b/system/src/Grav/Common/Flex/FlexCollection.php @@ -18,9 +18,8 @@ use Grav\Common\Flex\Traits\FlexGravTrait; * Class FlexCollection * * @package Grav\Common\Flex - * @template TKey * @template T of \Grav\Framework\Flex\Interfaces\FlexObjectInterface - * @extends \Grav\Framework\Flex\FlexCollection + * @extends \Grav\Framework\Flex\FlexCollection */ abstract class FlexCollection extends \Grav\Framework\Flex\FlexCollection { diff --git a/system/src/Grav/Common/Flex/FlexIndex.php b/system/src/Grav/Common/Flex/FlexIndex.php index d73f010ac..44b6fdd6e 100644 --- a/system/src/Grav/Common/Flex/FlexIndex.php +++ b/system/src/Grav/Common/Flex/FlexIndex.php @@ -18,10 +18,9 @@ use Grav\Common\Flex\Traits\FlexIndexTrait; * Class FlexIndex * * @package Grav\Common\Flex - * @template TKey * @template T of \Grav\Framework\Flex\Interfaces\FlexObjectInterface * @template C of \Grav\Framework\Flex\Interfaces\FlexCollectionInterface - * @extends \Grav\Framework\Flex\FlexIndex + * @extends \Grav\Framework\Flex\FlexIndex */ abstract class FlexIndex extends \Grav\Framework\Flex\FlexIndex { diff --git a/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php b/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php index 2a6767bfe..6b2fbc1e6 100644 --- a/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php +++ b/system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php @@ -17,7 +17,7 @@ use Grav\Common\Flex\FlexCollection; * Class GenericCollection * @package Grav\Common\Flex\Generic * - * @extends FlexCollection + * @extends FlexCollection */ class GenericCollection extends FlexCollection { diff --git a/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php b/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php index 4b0c400dd..81dbf9544 100644 --- a/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php +++ b/system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php @@ -17,7 +17,7 @@ use Grav\Common\Flex\FlexIndex; * Class GenericIndex * @package Grav\Common\Flex\Generic * - * @extends FlexIndex + * @extends FlexIndex */ class GenericIndex extends FlexIndex { diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php index 1811a0e63..c75c4ce27 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php @@ -35,7 +35,7 @@ use function is_string; * Class GravPageCollection * @package Grav\Plugin\FlexObjects\Types\GravPages * - * @extends FlexPageCollection + * @extends FlexPageCollection * * Incompatibilities with Grav\Common\Page\Collection: * $page = $collection->key() will not work at all diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php index d53d7f888..b43b88602 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php @@ -38,7 +38,7 @@ use function is_string; * Class GravPageObject * @package Grav\Plugin\FlexObjects\Types\GravPages * - * @extends FlexPageIndex + * @extends FlexPageIndex * * @method PageIndex withModules(bool $bool = true) * @method PageIndex withPages(bool $bool = true) diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php index b1443a8c6..93abbf886 100644 --- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php +++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupCollection.php @@ -17,7 +17,7 @@ use Grav\Common\Flex\FlexCollection; * Class UserGroupCollection * @package Grav\Common\Flex\Types\UserGroups * - * @extends FlexCollection + * @extends FlexCollection */ class UserGroupCollection extends FlexCollection { diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php index effd27f61..4bee5ac3d 100644 --- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php +++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupIndex.php @@ -17,7 +17,7 @@ use Grav\Common\Flex\FlexIndex; * Class GroupIndex * @package Grav\Common\User\FlexUser * - * @extends FlexIndex + * @extends FlexIndex */ class UserGroupIndex extends FlexIndex { diff --git a/system/src/Grav/Common/Flex/Types/Users/UserCollection.php b/system/src/Grav/Common/Flex/Types/Users/UserCollection.php index e4e252cd4..e17525a9c 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserCollection.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserCollection.php @@ -20,7 +20,7 @@ use function is_string; * Class UserCollection * @package Grav\Common\Flex\Types\Users * - * @extends FlexCollection + * @extends FlexCollection */ class UserCollection extends FlexCollection implements UserCollectionInterface { diff --git a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php index 68bbb780e..4a3f58773 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserIndex.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserIndex.php @@ -21,13 +21,12 @@ use Grav\Framework\Flex\Interfaces\FlexStorageInterface; use Monolog\Logger; use function count; use function is_string; -use function method_exists; /** * Class UserIndex * @package Grav\Common\Flex\Types\Users * - * @extends FlexIndex + * @extends FlexIndex */ class UserIndex extends FlexIndex implements UserCollectionInterface { diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index ee56ba410..54e06654a 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -37,10 +37,9 @@ use function is_scalar; /** * Class FlexCollection * @package Grav\Framework\Flex - * @template TKey * @template T of FlexObjectInterface - * @extends ObjectCollection - * @implements FlexCollectionInterface + * @extends ObjectCollection + * @implements FlexCollectionInterface */ class FlexCollection extends ObjectCollection implements FlexCollectionInterface { @@ -460,7 +459,6 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface /** * @param string $key * @return array - * @phpstan-param TKey $key */ public function getMetaData(string $key): array { @@ -491,7 +489,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface * @param string|null $scope * @param UserInterface|null $user * @return static - * @phpstan-return static + * @phpstan-return static */ public function isAuthorized(string $action, string $scope = null, UserInterface $user = null) { @@ -559,7 +557,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface * @param array $elements Elements. * @param string|null $keyField * @return static - * @phpstan-return static + * @phpstan-return static * @throws \InvalidArgumentException */ protected function createFrom(array $elements, $keyField = null) diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index 093074806..b9c9d543b 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -46,7 +46,6 @@ use function is_callable; * Class FlexDirectory * @package Grav\Framework\Flex * @template T - * @template TKey */ class FlexDirectory implements FlexDirectoryInterface, FlexAuthorizeInterface { @@ -309,7 +308,7 @@ class FlexDirectory implements FlexDirectoryInterface, FlexAuthorizeInterface * @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 { diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index d480bc9d5..08785c28e 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -33,11 +33,10 @@ use function in_array; /** * Class FlexIndex * @package Grav\Framework\Flex - * @template TKey * @template T of FlexObjectInterface * @template C of FlexCollectionInterface - * @extends ObjectIndex - * @implements FlexIndexInterface + * @extends ObjectIndex + * @implements FlexIndexInterface * @mixin C */ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexIndexInterface @@ -54,7 +53,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde /** * @param FlexDirectory $directory * @return static - * @phpstan-return static + * @phpstan-return static */ public static function createFromStorage(FlexDirectory $directory) { @@ -343,7 +342,6 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde /** * @param string $key * @return array - * @phpstan-param TKey $key */ public function getMetaData($key): array { @@ -370,7 +368,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde /** * @param array $orderings * @return static - * @phpstan-return static + * @phpstan-return static */ public function orderBy(array $orderings) { @@ -538,7 +536,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde * @param array $entries * @param string|null $keyField * @return static - * @phpstan-return static + * @phpstan-return static */ protected function createFrom(array $entries, string $keyField = null) { diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php index 6fd81feb7..16be3d5d6 100644 --- a/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php +++ b/system/src/Grav/Framework/Flex/Interfaces/FlexCollectionInterface.php @@ -22,9 +22,8 @@ use InvalidArgumentException; * * @used-by \Grav\Framework\Flex\FlexCollection * @since 1.6 - * @template TKey * @template T - * @extends ObjectCollectionInterface + * @extends ObjectCollectionInterface */ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionInterface, NestedObjectInterface { @@ -58,7 +57,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * @param string|string[]|null $properties Properties to search for, defaults to configured properties. * @param array|null $options Search options, defaults to configured options. * @return FlexCollectionInterface Returns a Flex Collection with only matching objects. - * @phpstan-return static + * @phpstan-return static * @api */ public function search(string $search, $properties = null, array $options = null); @@ -69,7 +68,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * @param array $orderings Pair of [property => 'ASC'|'DESC', ...]. * * @return FlexCollectionInterface Returns a sorted version from the collection. - * @phpstan-return static + * @phpstan-return static */ public function sort(array $orderings); @@ -78,7 +77,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * * @param array $filters * @return FlexCollectionInterface - * @phpstan-return static + * @phpstan-return static */ public function filterBy(array $filters); @@ -114,7 +113,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * * @param string|null $keyField Switch key field of the collection. * @return FlexCollectionInterface Returns a new Flex Collection with new key field. - * @phpstan-return static + * @phpstan-return static * @api */ public function withKeyField(string $keyField = null); @@ -123,7 +122,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * Get Flex Index from the Flex Collection. * * @return FlexIndexInterface Returns a Flex Index from the current collection. - * @phpstan-return FlexIndexInterface + * @phpstan-return FlexIndexInterface */ public function getIndex(); @@ -131,7 +130,7 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * Load all the objects into memory, * * @return FlexCollectionInterface - * @phpstan-return static + * @phpstan-return static */ public function getCollection(); @@ -140,7 +139,6 @@ interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionI * * @param string $key Key. * @return array - * @phpstan-param TKey $key */ public function getMetaData(string $key): array; } diff --git a/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php b/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php index 91bf14893..d751e4b40 100644 --- a/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php +++ b/system/src/Grav/Framework/Flex/Interfaces/FlexIndexInterface.php @@ -21,9 +21,8 @@ use Grav\Framework\Flex\FlexDirectory; * * @used-by \Grav\Framework\Flex\FlexIndex * @since 1.6 - * @template TKey * @template T - * @extends FlexCollectionInterface + * @extends FlexCollectionInterface */ interface FlexIndexInterface extends FlexCollectionInterface { diff --git a/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php b/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php index d5532084f..94825681c 100644 --- a/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php +++ b/system/src/Grav/Framework/Flex/Pages/FlexPageCollection.php @@ -20,9 +20,8 @@ use function is_int; /** * Class FlexPageCollection * @package Grav\Plugin\FlexObjects\Types\FlexPages - * @template TKey * @template T of \Grav\Framework\Flex\Interfaces\FlexObjectInterface - * @extends FlexCollection + * @extends FlexCollection */ class FlexPageCollection extends FlexCollection { @@ -53,7 +52,7 @@ class FlexPageCollection extends FlexCollection /** * @param bool $bool * @return static - * @phpstan-return static + * @phpstan-return static */ public function withPublished(bool $bool = true) { @@ -65,7 +64,7 @@ class FlexPageCollection extends FlexCollection /** * @param bool $bool * @return static - * @phpstan-return static + * @phpstan-return static */ public function withVisible(bool $bool = true) { @@ -77,7 +76,7 @@ class FlexPageCollection extends FlexCollection /** * @param bool $bool * @return static - * @phpstan-return static + * @phpstan-return static */ public function withRoutable(bool $bool = true) { diff --git a/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php b/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php index 47a5e066d..904d1f6da 100644 --- a/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php +++ b/system/src/Grav/Framework/Flex/Pages/FlexPageIndex.php @@ -22,10 +22,9 @@ use Grav\Framework\Flex\FlexIndex; * @method FlexPageIndex withPublished(bool $bool = true) * @method FlexPageIndex withVisible(bool $bool = true) * - * @template TKey * @template T of FlexPageObject * @template C of FlexPageCollection - * @extends FlexIndex + * @extends FlexIndex */ class FlexPageIndex extends FlexIndex { diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index c9ae58057..a6e1e102f 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -205,10 +205,10 @@ trait FlexMediaTrait $filename = $info['path'] ?? $info['name']; } - /** @var Medium|null $thumbFile */ + /** @var Medium|null $imageFile */ $imageFile = $media[$filename]; - /** @var Medium|null $thumbFile */ + /** @var Medium|null $originalFile */ $originalFile = $originalMedia ? $originalMedia[$filename] : null; $url = $imageFile ? $imageFile->url() : null; From 67f172b741448c57ce483eab1a4cf00fc9e4cadb Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 31 Mar 2021 22:11:55 +0300 Subject: [PATCH 21/23] Phpstan fixes --- system/src/Grav/Common/Assets/BaseAsset.php | 5 ++--- system/src/Grav/Common/Cache.php | 1 - system/src/Grav/Common/Data/Blueprint.php | 6 +++++- system/src/Grav/Common/Session.php | 4 ++-- system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php | 2 +- tests/phpstan/phpstan.neon | 5 +++++ 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Assets/BaseAsset.php b/system/src/Grav/Common/Assets/BaseAsset.php index 6d1f9015e..3e079746b 100644 --- a/system/src/Grav/Common/Assets/BaseAsset.php +++ b/system/src/Grav/Common/Assets/BaseAsset.php @@ -176,11 +176,10 @@ abstract class BaseAsset extends PropertyObject /** * Receive asset location and return the SRI integrity hash * - * @param $input - * + * @param string $input * @return string */ - public static function integrityHash( $input ) + public static function integrityHash($input) { $grav = Grav::instance(); diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 65270911b..a961904de 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -127,7 +127,6 @@ class Cache extends Getters */ public function init(Grav $grav) { - /** @var Config $config */ $this->config = $grav['config']; $this->now = time(); diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 25c4266e9..29a26369c 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -524,8 +524,12 @@ class Blueprint extends BlueprintForm * @param string $op * @return bool */ - protected function resolveActions(UserInterface $user, array $actions, string $op = 'and') + protected function resolveActions(?UserInterface $user, array $actions, string $op = 'and') { + if (null === $user) { + return false; + } + $c = $i = count($actions); foreach ($actions as $key => $action) { if (!is_int($key) && is_array($actions)) { diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index 6ff080a11..8856e7a0a 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -128,12 +128,12 @@ class Session extends \Grav\Framework\Session\Session /** @var Uri $uri */ $uri = $grav['uri']; /** @var Forms|null $form */ - $form = $grav['forms']->getActiveForm(); + $form = $grav['forms']->getActiveForm(); // @phpstan-ignore-line $sessionField = base64_encode($uri->url); /** @var FormFlash|null $flash */ - $flash = $form ? $form->getFlash() : null; + $flash = $form ? $form->getFlash() : null; // @phpstan-ignore-line $object = $flash && method_exists($flash, 'getLegacyFiles') ? [$sessionField => $flash->getLegacyFiles()] : null; } } diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index a6e1e102f..c3b810d1a 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -384,7 +384,7 @@ trait FlexMediaTrait $updated = true; if ($medium) { $media->add($filename, $medium); - } else { + } elseif (is_callable([$media, 'hide'])) { $media->hide($filename); } } diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 5802fe911..ff372d778 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -161,3 +161,8 @@ parameters: - '#Call to deprecated method stopPropagation\(\) of class Symfony\\Component\\EventDispatcher\\Event#' - '#Parameter \#2 \$listener of method Symfony\\Component\\EventDispatcher\\EventDispatcher::addListener\(\)#' - '#Parameter \#2 \$listener of method Symfony\\Component\\EventDispatcher\\EventDispatcher::removeListener\(\)#' + + # Installer updates + - + message: '#Variable \$this in PHPDoc tag @var does not exist#' + path: '*/system/src/Grav/Installer/updates/*' From e02d298ff446b7191546701cd74d957dfec75293 Mon Sep 17 00:00:00 2001 From: pamtbaau Date: Mon, 5 Apr 2021 19:21:03 +0200 Subject: [PATCH 22/23] Add option images.defaults.size to set default height/width (#3272) * Add option images.defaults.size to set default height/width - Add option to config/system.yaml - Add option to blueprints/config/system.yaml - Add ImageSizeTrait.php - Add ImageSizeTrait to ImageMedium.php - Add Unit tests * moved width/height to rendering phase * Add test: height/width should be of resized image. * Added optional apsect-ratio variable * more improvements * Added aspectRatio and retinaScale image functions * remove use for old trait * reset the CLS variables after calling reset on the image Co-authored-by: Andy Miller --- system/blueprints/config/system.yaml | 39 +++++++++ system/config/system.yaml | 4 + .../Common/Media/Traits/ImageMediaTrait.php | 18 ++++- .../Grav/Common/Page/Medium/ImageMedium.php | 53 +++++++++++- .../Grav/Common/Markdown/ParsedownTest.php | 80 +++++++++++++++++++ 5 files changed, 192 insertions(+), 2 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index d2be69c27..84c1dcc05 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -1282,6 +1282,45 @@ form: validate: type: commalist + section_images_cls: + type: section + title: PLUGIN_ADMIN.IMAGES_CLS_TITLE + underline: true + + images.cls.auto_sizes: + type: toggle + label: PLUGIN_ADMIN.IMAGES_CLS_AUTO_SIZES + help: PLUGIN_ADMIN.IMAGES_CLS_AUTO_SIZES_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + images.cls.aspect_ratio: + type: toggle + label: PLUGIN_ADMIN.IMAGES_CLS_ASPECT_RATIO + help: PLUGIN_ADMIN.IMAGES_CLS_ASPECT_RATIO_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + images.cls.retina_scale: + type: select + label: PLUGIN_ADMIN.IMAGES_CLS_RETINA_SCALE + help: PLUGIN_ADMIN.IMAGES_CLS_RETINA_SCALE_HELP + size: small + highlight: 1 + options: + 1: 1X + 2: 2X + 3: 3X + 4: 4X + session: type: tab title: PLUGIN_ADMIN.SESSION diff --git a/system/config/system.yaml b/system/config/system.yaml index ffb98f247..c3146141b 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -154,6 +154,10 @@ images: debug: false # Show an overlay over images indicating the pixel depth of the image when working with retina for example auto_fix_orientation: true # Automatically fix the image orientation based on the Exif data seofriendly: false # SEO-friendly processed image names + cls: # Cumulative Layout Shift: See https://web.dev/optimize-cls/ + auto_sizes: false # Automatically add height/width to image + aspect_ratio: false # Reserve space with aspect ratio style + retina_scale: 1 # scale to adjust auto-sizes for better handling of HiDPI resolutions defaults: loading: auto # Let browser pick [auto|lazy|eager] diff --git a/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php b/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php index ad168a370..6181c941e 100644 --- a/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php +++ b/system/src/Grav/Common/Media/Traits/ImageMediaTrait.php @@ -41,6 +41,16 @@ trait ImageMediaTrait /** @var bool */ protected $debug_watermarked = false; + /** @var bool */ + protected $auto_sizes; + + /** @var bool */ + protected $aspect_ratio; + + /** @var integer */ + protected $retina_scale; + + /** @var array */ public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', @@ -358,11 +368,17 @@ trait ImageMediaTrait ->setPrettyName($this->getImagePrettyName()); // Fix orientation if enabled - if (Grav::instance()['config']->get('system.images.auto_fix_orientation', false) && + $config = Grav::instance()['config']; + if ($config->get('system.images.auto_fix_orientation', false) && extension_loaded('exif') && function_exists('exif_read_data')) { $this->image->fixOrientation(); } + // Set CLS configuration + $this->auto_sizes = $config->get('system.images.cls.auto_sizes', false); + $this->aspect_ratio = $config->get('system.images.cls.aspect_ratio', false); + $this->retina_scale = $config->get('system.images.cls.retina_scale', 1); + return $this; } diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 70ab1280d..60d49977b 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -30,6 +30,11 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate use ImageMediaTrait; use ImageLoadingTrait; + /** + * @var mixed|string + */ + private $saved_image_path; + /** * Construct. * @@ -121,6 +126,12 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate $this->debug_watermarked = false; + $config = $this->getGrav()['config']; + // Set CLS configuration + $this->auto_sizes = $config->get('system.images.cls.auto_sizes', false); + $this->aspect_ratio = $config->get('system.images.cls.aspect_ratio', false); + $this->retina_scale = $config->get('system.images.cls.retina_scale', 1); + return $this; } @@ -170,7 +181,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate /** @var UniformResourceLocator $locator */ $locator = $grav['locator']; $image_path = (string)($locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true)); - $saved_image_path = $this->saveImage(); + $saved_image_path = $this->saved_image_path = $this->saveImage(); $output = preg_replace('|^' . preg_quote(GRAV_ROOT, '|') . '|', '', $saved_image_path) ?: $saved_image_path; @@ -232,6 +243,23 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate $attributes['sizes'] = $this->sizes(); } + 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]); + + $scaling_factor = $this->retina_scale > 0 ? $this->retina_scale : 1; + $attributes['width'] = intval($width / $scaling_factor); + $attributes['height'] = intval($height / $scaling_factor); + + if ($this->aspect_ratio) { + $style = ($attributes['style'] ?? ' ') . "--aspect-ratio: $width/$height;"; + $attributes['style'] = trim($style); + } + } + } + return ['name' => 'img', 'attributes' => $attributes]; } @@ -274,6 +302,29 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate return parent::lightbox($width, $height, $reset); } + public function autoSizes($enabled = 'true') + { + $enabled = $enabled === 'true' ?: false; + $this->auto_sizes = $enabled; + + return $this; + } + + public function aspectRatio($enabled = 'true') + { + $enabled = $enabled === 'true' ?: false; + $this->aspect_ratio = $enabled; + + return $this; + } + + public function retinaScale($scale = 1) + { + $this->retina_scale = intval($scale); + + return $this; + } + /** * Handle this commonly used variant * diff --git a/tests/unit/Grav/Common/Markdown/ParsedownTest.php b/tests/unit/Grav/Common/Markdown/ParsedownTest.php index 829256bd9..5706389b9 100644 --- a/tests/unit/Grav/Common/Markdown/ParsedownTest.php +++ b/tests/unit/Grav/Common/Markdown/ParsedownTest.php @@ -248,6 +248,7 @@ class ParsedownTest extends \Codeception\TestCase\Test $this->setImagesDefaults(['loading' => 'auto']); + // loading should NOT be added to image by default self::assertSame( '

', @@ -279,6 +280,85 @@ class ParsedownTest extends \Codeception\TestCase\Test '

', $this->parsedown->text('![](sample-image.jpg?loading=eager)') ); + + } + + public function testCLSAutoSizes(): void + { + $this->config->set('system.images.cls.auto_sizes', false); + $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg)') + ); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg?height=1&width=1)') + ); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg?autoSizes=true)') + ); + + $this->config->set('system.images.cls.auto_sizes', true); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg?reset)') + ); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg?height=1&width=1)') + ); + + self::assertSame( + '

', + $this->parsedown->text('![](sample-image.jpg?autoSizes=false)') + ); + + self::assertRegExp( + '/width="400" height="200"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=400,200)') + ); + + $this->config->set('system.images.cls.retina_scale', 2); + + + self::assertRegExp( + '/width="400" height="200"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=800,400)') + ); + + $this->config->set('system.images.cls.retina_scale', 4); + + self::assertRegExp( + '/width="200" height="100"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=800,400)') + ); + + self::assertRegExp( + '/width="266" height="133"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=800,400&retinaScale=3)') + ); + + $this->config->set('system.images.cls.aspect_ratio', true); + + self::assertRegExp( + '/style="--aspect-ratio: 800\/400;"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=800,400)') + ); + + $this->config->set('system.images.cls.aspect_ratio', false); + + self::assertRegExp( + '/style="--aspect-ratio: 800\/400;"/', + $this->parsedown->text('![](sample-image.jpg?reset&resize=800,400&aspectRatio=true)') + ); + } public function testRootImages(): void From aa81350b6f3f54163ecefcf01ab50214a4a7105c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 6 Apr 2021 11:16:02 -0600 Subject: [PATCH 23/23] prepare for release --- CHANGELOG.md | 2 +- system/defines.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bbfbd4d3..4e0a029e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.7.10 -## mm/dd/2021 +## 04/06/2021 1. [](#new) * Added initial support for running Grav library from outside the webroot [#3297](https://github.com/getgrav/grav/issues/3297) diff --git a/system/defines.php b/system/defines.php index 353703825..6bdcb2492 100644 --- a/system/defines.php +++ b/system/defines.php @@ -8,7 +8,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '1.7.9'); +define('GRAV_VERSION', '1.7.10'); define('GRAV_SCHEMA', '1.7.0_2020-11-20_1'); define('GRAV_TESTING', false);