From 7f80e650b15cd1096b726a4adaa7f963f591902a Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 11 Sep 2020 14:13:06 +0300 Subject: [PATCH 1/4] Improve Media classes --- CHANGELOG.md | 1 + system/src/Grav/Framework/Psr7/Stream.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3317ff64..b28e6c5cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#bugfix) * Fixed `Security::sanitizeSVG()` creating an empty file if SVG file cannot be parsed * Fixed infinite loop in blueprints with `extend@` to a parent stream + * Added missing `Stream::create()` method # v1.7.0-rc.16 ## 09/01/2020 diff --git a/system/src/Grav/Framework/Psr7/Stream.php b/system/src/Grav/Framework/Psr7/Stream.php index 45a040fee..1dda9c05a 100644 --- a/system/src/Grav/Framework/Psr7/Stream.php +++ b/system/src/Grav/Framework/Psr7/Stream.php @@ -18,6 +18,15 @@ class Stream implements StreamInterface { use StreamDecoratorTrait; + /** + * @param string $body + * @return static + */ + public static function create($body = '') + { + return new static($body); + } + /** * Stream constructor. * From fdfd6558f28165549e055aa40b933540b0253658 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 18 Sep 2020 09:17:28 +0300 Subject: [PATCH 2/4] Composer update --- composer.lock | 291 ++++---------------------------------------------- 1 file changed, 18 insertions(+), 273 deletions(-) diff --git a/composer.lock b/composer.lock index d6a238be4..2a8b3e31f 100644 --- a/composer.lock +++ b/composer.lock @@ -305,16 +305,6 @@ "user agent", "useragent" ], - "funding": [ - { - "url": "https://www.paypal.me/donatj/15", - "type": "custom" - }, - { - "url": "https://github.com/donatj", - "type": "github" - } - ], "time": "2020-09-01T16:13:00+00:00" }, { @@ -724,16 +714,16 @@ }, { "name": "itsgoingd/clockwork", - "version": "v4.1.7", + "version": "v4.1.8", "source": { "type": "git", "url": "https://github.com/itsgoingd/clockwork.git", - "reference": "49c28d7c43f6021eca4c290f620f13ee7d15f668" + "reference": "0dc2e5be39de88b18719bb4f3cdacfa605ad2146" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/49c28d7c43f6021eca4c290f620f13ee7d15f668", - "reference": "49c28d7c43f6021eca4c290f620f13ee7d15f668", + "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/0dc2e5be39de88b18719bb4f3cdacfa605ad2146", + "reference": "0dc2e5be39de88b18719bb4f3cdacfa605ad2146", "shasum": "" }, "require": { @@ -779,7 +769,7 @@ "profiling", "slim" ], - "time": "2020-08-25T20:05:21+00:00" + "time": "2020-09-17T19:21:25+00:00" }, { "name": "kodus/psr7-server", @@ -2019,20 +2009,6 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-09-02T07:07:21+00:00" }, { @@ -2110,20 +2086,6 @@ "interoperability", "standards" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-09-02T16:08:58+00:00" }, { @@ -2194,20 +2156,6 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-13T14:18:44+00:00" }, { @@ -2276,20 +2224,6 @@ ], "description": "Symfony HttpClient component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-09-02T08:01:15+00:00" }, { @@ -2714,20 +2648,6 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-23T08:31:43+00:00" }, { @@ -2805,20 +2725,6 @@ "debug", "dump" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-17T07:31:35+00:00" }, { @@ -2878,20 +2784,6 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-26T08:30:46+00:00" }, { @@ -3289,20 +3181,6 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], "time": "2020-08-25T05:50:16+00:00" }, { @@ -3347,20 +3225,6 @@ "Xdebug", "performance" ], - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], "time": "2020-08-19T10:27:58+00:00" }, { @@ -3417,20 +3281,6 @@ "constructor", "instantiate" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", - "type": "tidelift" - } - ], "time": "2020-05-29T17:27:14+00:00" }, { @@ -3664,24 +3514,24 @@ }, { "name": "jean85/pretty-package-versions", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "e9f4324e88b8664be386d90cf60fbc202e1f7fc9" + "reference": "a917488320c20057da87f67d0d40543dd9427f7a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/e9f4324e88b8664be386d90cf60fbc202e1f7fc9", - "reference": "e9f4324e88b8664be386d90cf60fbc202e1f7fc9", + "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/a917488320c20057da87f67d0d40543dd9427f7a", + "reference": "a917488320c20057da87f67d0d40543dd9427f7a", "shasum": "" }, "require": { "composer/package-versions-deprecated": "^1.8.0", - "php": "^7.0" + "php": "^7.0|^8.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.0|^8.5|^9.2" }, "type": "library", "extra": { @@ -3711,7 +3561,7 @@ "release", "versions" ], - "time": "2020-06-23T06:23:06+00:00" + "time": "2020-09-14T08:43:34+00:00" }, { "name": "myclabs/deep-copy", @@ -3759,12 +3609,6 @@ "object", "object graph" ], - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], "time": "2020-06-29T13:22:24+00:00" }, { @@ -4106,16 +3950,16 @@ }, { "name": "nette/robot-loader", - "version": "v3.3.0", + "version": "v3.3.1", "source": { "type": "git", "url": "https://github.com/nette/robot-loader.git", - "reference": "737ff8ee1709eff053d9cc27e6c661d82395bd8b" + "reference": "15c1ecd0e6e69e8d908dfc4cca7b14f3b850a96b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/robot-loader/zipball/737ff8ee1709eff053d9cc27e6c661d82395bd8b", - "reference": "737ff8ee1709eff053d9cc27e6c661d82395bd8b", + "url": "https://api.github.com/repos/nette/robot-loader/zipball/15c1ecd0e6e69e8d908dfc4cca7b14f3b850a96b", + "reference": "15c1ecd0e6e69e8d908dfc4cca7b14f3b850a96b", "shasum": "" }, "require": { @@ -4165,7 +4009,7 @@ "nette", "trait" ], - "time": "2020-07-28T13:34:12+00:00" + "time": "2020-09-15T15:14:17+00:00" }, { "name": "nette/schema", @@ -5844,20 +5688,6 @@ ], "description": "Symfony BrowserKit Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-05-22T17:28:00+00:00" }, { @@ -5911,20 +5741,6 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-05T09:39:30+00:00" }, { @@ -5986,20 +5802,6 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-12T06:20:35+00:00" }, { @@ -6049,20 +5851,6 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-17T09:56:45+00:00" }, { @@ -6134,20 +5922,6 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-08-04T06:02:08+00:00" }, { @@ -6215,20 +5989,6 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-14T12:35:20+00:00" }, { @@ -6292,20 +6052,6 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-07-14T12:35:20+00:00" }, { @@ -6464,6 +6210,5 @@ "platform-dev": [], "platform-overrides": { "php": "7.1.3" - }, - "plugin-api-version": "1.1.0" + } } From fe53dc88e50635b51ce747dfafb5568391084f22 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 18 Sep 2020 09:20:27 +0300 Subject: [PATCH 3/4] Improve Media classes --- CHANGELOG.md | 2 + .../Interfaces/MediaCollectionInterface.php | 71 +++++++++++++++++++ .../Common/Media/Traits/MediaUploadTrait.php | 19 ++++- system/src/Grav/Common/Page/Media.php | 8 +-- .../Grav/Common/Page/Medium/AbstractMedia.php | 37 +++++++++- .../Grav/Common/Page/Medium/GlobalMedia.php | 12 ++++ 6 files changed, 141 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b28e6c5cc..28835141a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.7.0-rc.17 ## mm/dd/2020 +1. [](#improved) + * Improve Media classes 1. [](#bugfix) * Fixed `Security::sanitizeSVG()` creating an empty file if SVG file cannot be parsed * Fixed infinite loop in blueprints with `extend@` to a parent stream diff --git a/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php index 543471655..28d0fd402 100644 --- a/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php +++ b/system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.php @@ -9,6 +9,10 @@ namespace Grav\Common\Media\Interfaces; +use Grav\Common\Data\Blueprint; +use Grav\Common\Page\Medium\ImageFile; +use Grav\Common\Page\Medium\Medium; + /** * Class implements media collection interface. */ @@ -21,6 +25,20 @@ interface MediaCollectionInterface extends \Grav\Framework\Media\Interfaces\Medi */ public function getPath(); + /** + * @param string|null $path + * @return void + */ + public function setPath(?string $path); + + /** + * Get medium by filename. + * + * @param string $filename + * @return Medium|null + */ + public function get($filename); + /** * Get a list of all media. * @@ -28,6 +46,34 @@ interface MediaCollectionInterface extends \Grav\Framework\Media\Interfaces\Medi */ public function all(); + /** + * Get a list of all image media. + * + * @return MediaObjectInterface[] + */ + public function images(); + + /** + * Get a list of all video media. + * + * @return MediaObjectInterface[] + */ + public function videos(); + + /** + * Get a list of all audio media. + * + * @return MediaObjectInterface[] + */ + public function audios(); + + /** + * Get a list of all file media. + * + * @return MediaObjectInterface[] + */ + public function files(); + /** * Set file modification timestamps (query params) for all the media files. * @@ -39,6 +85,31 @@ interface MediaCollectionInterface extends \Grav\Framework\Media\Interfaces\Medi /** * @param string $name * @param MediaObjectInterface $file + * @return void */ public function add($name, $file); + + /** + * Create Medium from a file. + * + * @param string $file + * @param array $params + * @return Medium|null + */ + public function createFromFile($file, array $params = []); + + /** + * Create Medium from array of parameters + * + * @param array $items + * @param Blueprint|null $blueprint + * @return Medium|null + */ + public function createFromArray(array $items = [], Blueprint $blueprint = null); + + /** + * @param MediaObjectInterface $mediaObject + * @return ImageFile + */ + public function getImageFileObject(MediaObjectInterface $mediaObject): ImageFile; } diff --git a/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php b/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php index 6f861e2fb..48589a143 100644 --- a/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php +++ b/system/src/Grav/Common/Media/Traits/MediaUploadTrait.php @@ -13,6 +13,7 @@ use Grav\Common\Config\Config; use Grav\Common\Filesystem\Folder; use Grav\Common\Grav; use Grav\Common\Language\Language; +use Grav\Common\Page\Medium\Medium; use Grav\Common\Page\Medium\MediumFactory; use Grav\Common\Security; use Grav\Common\Utils; @@ -39,6 +40,18 @@ trait MediaUploadTrait 'destination' => null // Destination path, if empty, exception is thrown. ]; + /** + * Create Medium from an uploaded file. + * + * @param UploadedFileInterface $uploadedFile + * @param array $params + * @return Medium|null + */ + public function createFromUploadedFile(UploadedFileInterface $uploadedFile, array $params = []) + { + return MediumFactory::fromUploadedFile($uploadedFile, $params); + } + /** * Checks that uploaded file meets the requirements. Returns new filename. * @@ -187,10 +200,9 @@ trait MediaUploadTrait * WARNING: Always check uploaded file before copying it! * * @example - * $filename = null; // Override filename if needed (ignored if randomizing filenames). * $settings = ['destination' => 'user://pages/media']; // Settings from the form field. * $filename = $media->checkUploadedFile($uploadedFile, $filename, $settings); - * $media->copyUploadedFile($uploadedFile, $filename); + * $media->copyUploadedFile($uploadedFile, $filename, $settings); * * @param UploadedFileInterface $uploadedFile * @param string $filename @@ -208,7 +220,7 @@ trait MediaUploadTrait } $path = $settings['destination'] ?? $this->getPath(); - if (!$path) { + if (!$path || !$filename) { throw new RuntimeException($this->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE'), 400); } @@ -406,6 +418,7 @@ trait MediaUploadTrait throw new RuntimeException('File could not be renamed: ' . $from, 500); } + // TODO: Add missing logic to handle retina files. if (is_file($fromPath . '.meta.yaml')) { $result = rename($fromPath . '.meta.yaml', $toPath . '.meta.yaml'); if (!$result) { diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index 3191c5354..655bb1262 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -46,9 +46,9 @@ class Media extends AbstractMedia */ public function __wakeup() { - if (!isset(static::$global)) { + if (null === static::$global) { // Add fallback to global media. - static::$global = new GlobalMedia(); + static::$global = GlobalMedia::getInstance(); } } @@ -122,7 +122,7 @@ class Media extends AbstractMedia * @var array $alt */ foreach ($types['alternative'] as $ratio => &$alt) { - $alt['file'] = MediumFactory::fromFile($alt['file']); + $alt['file'] = $this->createFromFile($alt['file']); if (empty($alt['file'])) { unset($types['alternative'][$ratio]); @@ -146,7 +146,7 @@ class Media extends AbstractMedia $file_path = $medium->path(); $medium = MediumFactory::scaledFromMedium($medium, $max, 1)['file']; } else { - $medium = MediumFactory::fromFile($types['base']['file']); + $medium = $this->createFromFile($types['base']['file']); if ($medium) { $medium->set('size', $types['base']['size']); $file_path = $medium->path(); diff --git a/system/src/Grav/Common/Page/Medium/AbstractMedia.php b/system/src/Grav/Common/Page/Medium/AbstractMedia.php index 780a991e9..8bcf3a14a 100644 --- a/system/src/Grav/Common/Page/Medium/AbstractMedia.php +++ b/system/src/Grav/Common/Page/Medium/AbstractMedia.php @@ -10,6 +10,7 @@ namespace Grav\Common\Page\Medium; use Grav\Common\Config\Config; +use Grav\Common\Data\Blueprint; use Grav\Common\Grav; use Grav\Common\Language\Language; use Grav\Common\Media\Interfaces\MediaCollectionInterface; @@ -23,6 +24,7 @@ use RocketTheme\Toolbox\ArrayTraits\Countable; use RocketTheme\Toolbox\ArrayTraits\Export; use RocketTheme\Toolbox\ArrayTraits\ExportInterface; use RocketTheme\Toolbox\ArrayTraits\Iterator; +use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; abstract class AbstractMedia implements ExportInterface, MediaCollectionInterface, MediaUploadInterface { @@ -59,6 +61,7 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac /** * @param string|null $path + * @return void */ public function setPath(?string $path): void { @@ -166,6 +169,7 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac /** * @param string $name * @param MediaObjectInterface|null $file + * @return void */ public function add($name, $file) { @@ -190,6 +194,30 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac } } + /** + * Create Medium from a file. + * + * @param string $file + * @param array $params + * @return Medium|null + */ + public function createFromFile($file, array $params = []) + { + return MediumFactory::fromFile($file, $params); + } + + /** + * Create Medium from array of parameters + * + * @param array $items + * @param Blueprint|null $blueprint + * @return Medium|null + */ + public function createFromArray(array $items = [], Blueprint $blueprint = null) + { + return MediumFactory::fromArray($items, $blueprint); + } + /** * @param MediaObjectInterface $mediaObject * @return ImageFile @@ -228,6 +256,11 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac return $media; } + protected function fileExists(string $filename, string $destination): bool + { + return file_exists("{$destination}/{$filename}"); + } + /** * Get filename, extension and meta part. * @@ -288,6 +321,8 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac protected function clearCache(): void { - // TODO: Implement clearCache() method. + /** @var UniformResourceLocator $locator */ + $locator = $this->getGrav()['locator']; + $locator->clearCache(); } } diff --git a/system/src/Grav/Common/Page/Medium/GlobalMedia.php b/system/src/Grav/Common/Page/Medium/GlobalMedia.php index 5198eed97..c7f917841 100644 --- a/system/src/Grav/Common/Page/Medium/GlobalMedia.php +++ b/system/src/Grav/Common/Page/Medium/GlobalMedia.php @@ -14,6 +14,18 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; class GlobalMedia extends AbstractMedia { + /** @var self */ + protected static $instance; + + public static function getInstance(): self + { + if (null === self::$instance) { + self::$instance = new self(); + } + + return self::$instance; + } + /** * Return media path. * From e88f9242745a070487079744cd9b54a3a91bd546 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 18 Sep 2020 09:57:56 +0300 Subject: [PATCH 4/4] Phpstan fixes --- .../src/Grav/Common/Flex/Types/Pages/PageObject.php | 2 +- .../src/Grav/Common/Flex/Types/Users/UserObject.php | 2 +- .../Media/Interfaces/MediaObjectInterface.php | 2 +- system/src/Grav/Common/Twig/TwigExtension.php | 13 ++++++------- system/src/Grav/Common/Utils.php | 2 +- system/src/Grav/Framework/Acl/PermissionsReader.php | 2 +- system/src/Grav/Framework/Filesystem/Filesystem.php | 2 +- .../Flex/Pages/Traits/PageTranslateTrait.php | 2 +- .../Grav/Framework/Flex/Traits/FlexMediaTrait.php | 3 ++- system/src/Grav/Framework/Form/FormFlashFile.php | 3 +++ system/src/Grav/Framework/Psr7/Stream.php | 4 ++-- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 73869352c..22ea92264 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -253,8 +253,8 @@ class PageObject extends FlexPageObject // Backwards compatibility with older plugins. $fireEvents = $reorder && $this->isAdminSite() && $this->getFlexDirectory()->getConfig('object.compat.events', true); + $grav = $this->getContainer(); if ($fireEvents) { - $grav = $this->getContainer(); $self = $this; $grav->fireEvent('onAdminSave', new Event(['type' => 'flex', 'directory' => $this->getFlexDirectory(), 'object' => &$self])); if ($self !== $this) { diff --git a/system/src/Grav/Common/Flex/Types/Users/UserObject.php b/system/src/Grav/Common/Flex/Types/Users/UserObject.php index 8b854df71..5179b1824 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserObject.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserObject.php @@ -553,8 +553,8 @@ class UserObject extends FlexObject implements UserInterface, \Countable // Backwards compatibility with older plugins. $fireEvents = $this->isAdminSite() && $this->getFlexDirectory()->getConfig('object.compat.events', true); + $grav = $this->getContainer(); if ($fireEvents) { - $grav = $this->getContainer(); $self = $this; $grav->fireEvent('onAdminSave', new Event(['type' => 'flex', 'directory' => $this->getFlexDirectory(), 'object' => &$self])); if ($self !== $this) { diff --git a/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php b/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php index bc2db439f..d6d5fca06 100644 --- a/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php +++ b/system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.php @@ -16,7 +16,7 @@ use Grav\Common\Data\Data; * * @property string $type */ -interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface +interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, \ArrayAccess { /** * Create a copy of this media object diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index 89b88579d..89814ca73 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -1331,12 +1331,12 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface * If still not found, will use the theme's configuration value, * If still not found, will use the $default value passed in * - * @param $context Twig Context + * @param array $context Twig Context * @param string $var variable to be found (using dot notation) * @param null $default the default value to be used as last resort * @param null $page an optional page to use for the current page * @param bool $exists toggle to simply return the page where the variable is set, else null - * @return string + * @return mixed */ public function themeVarFunc($context, $var, $default = null, $page = null, $exists = false) { @@ -1370,10 +1370,9 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface /** * Look for a page header variable in an array of pages working its way through until a value is found * - * @param $context + * @param array $context * @param string $var the variable to look for in the page header * @param string|string[]|null $pages array of pages to check (current page upwards if not null) - * @param bool $exists if true, return the page where the var is found, not the value * @return mixed * @deprecated 1.7 Use themeVarFunc() instead */ @@ -1391,7 +1390,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface * takes an array of classes, and if they are not set on body_classes * look to see if they are set in theme config * - * @param $context + * @param array $context * @param string|string[] $classes * @return string */ @@ -1416,8 +1415,8 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface /** * Returns the content of an SVG image and adds extra classes as needed * - * @param $path - * @param $classes + * @param string $path + * @param string|null $classes * @return string|string[]|null */ public static function svgImageFunction($path, $classes = null, $strip_style = false) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index ef2e16d8b..aad9b1ad2 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -134,7 +134,7 @@ abstract class Utils * Helper method to find the full path to a file, be it a stream, a relative path, or * already a full path * - * @param $path + * @param string $path * @return string */ public static function fullPath($path) diff --git a/system/src/Grav/Framework/Acl/PermissionsReader.php b/system/src/Grav/Framework/Acl/PermissionsReader.php index 47dd83df9..29b292f74 100644 --- a/system/src/Grav/Framework/Acl/PermissionsReader.php +++ b/system/src/Grav/Framework/Acl/PermissionsReader.php @@ -95,7 +95,7 @@ class PermissionsReader // Build dependency tree. foreach ($dependencies as $type => $dep) { - foreach ($dep as $k => &$val) { + foreach (get_object_vars($dep) as $k => &$val) { if (null === $val) { $val = $dependencies[$k] ?? new \stdClass(); } diff --git a/system/src/Grav/Framework/Filesystem/Filesystem.php b/system/src/Grav/Framework/Filesystem/Filesystem.php index 66f528056..a2b76d9b3 100644 --- a/system/src/Grav/Framework/Filesystem/Filesystem.php +++ b/system/src/Grav/Framework/Filesystem/Filesystem.php @@ -134,7 +134,7 @@ class Filesystem implements FilesystemInterface */ public function basename(string $path, ?string $suffix = null): string { - return basename($path, $suffix); + return $suffix ? basename($path, $suffix) : basename($path); } /** diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php index fb5046656..058c020d8 100644 --- a/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php +++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageTranslateTrait.php @@ -270,7 +270,7 @@ trait PageTranslateTrait /** @var Language $language */ $language = $grav['language']; - $languageCode = $languageCode ?? $language->getLanguage(); + $languageCode = $languageCode ?? ($language->getLanguage() ?: ''); if ($languageCode === '' && $fallback) { return $language->getFallbackLanguages(null, true); } diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index f09e7873c..8136f1776 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -159,8 +159,9 @@ trait FlexMediaTrait $list = []; foreach ($files as $field => $group) { + $field = (string)$field; // Ignore files without a field and resized images. - if ($field === '' || \strpos((string)$field, '/')) { + if ($field === '' || \strpos($field, '/')) { continue; } diff --git a/system/src/Grav/Framework/Form/FormFlashFile.php b/system/src/Grav/Framework/Form/FormFlashFile.php index 32add0c5c..4c47ec3cf 100644 --- a/system/src/Grav/Framework/Form/FormFlashFile.php +++ b/system/src/Grav/Framework/Form/FormFlashFile.php @@ -59,6 +59,9 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable } $resource = \fopen($tmpFile, 'rb'); + if (false === $resource) { + throw new \RuntimeException('No temporary file'); + } return Stream::create($resource); } diff --git a/system/src/Grav/Framework/Psr7/Stream.php b/system/src/Grav/Framework/Psr7/Stream.php index 1dda9c05a..dd0656c52 100644 --- a/system/src/Grav/Framework/Psr7/Stream.php +++ b/system/src/Grav/Framework/Psr7/Stream.php @@ -19,7 +19,7 @@ class Stream implements StreamInterface use StreamDecoratorTrait; /** - * @param string $body + * @param string|resource|StreamInterface $body * @return static */ public static function create($body = '') @@ -30,7 +30,7 @@ class Stream implements StreamInterface /** * Stream constructor. * - * @param string $body + * @param string|resource|StreamInterface $body */ public function __construct($body = '') {