Make the new relationships code to work in PHP 7.3

This commit is contained in:
Matias Griese
2022-06-13 17:25:32 +03:00
parent b5ab00639b
commit 00cb9c3540
18 changed files with 213 additions and 172 deletions

View File

@@ -12,7 +12,7 @@
"homepage": "https://getgrav.org",
"license": "MIT",
"require": {
"php": "^7.4.1 || ^8.0",
"php": "^7.3.6 || ^8.0",
"ext-json": "*",
"ext-openssl": "*",
"ext-curl": "*",
@@ -89,7 +89,7 @@
"config": {
"apcu-autoloader": true,
"platform": {
"php": "7.4.1"
"php": "7.3.6"
}
},
"autoload": {

177
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7645535ce7348e38bad6dad9ce8b2fdb",
"content-hash": "f0530b0fd3e574fef0852376653da5a0",
"packages": [
{
"name": "composer/ca-bundle",
@@ -731,16 +731,16 @@
},
{
"name": "guzzlehttp/psr7",
"version": "1.8.5",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268"
"reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/337e3ad8e5716c15f9657bd214d16cc5e69df268",
"reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/e98e3e6d4f86621a9b75f623996e6bbdeb4b9318",
"reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318",
"shasum": ""
},
"require": {
@@ -761,7 +761,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.9-dev"
}
},
"autoload": {
@@ -821,7 +821,7 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/1.8.5"
"source": "https://github.com/guzzle/psr7/tree/1.9.0"
},
"funding": [
{
@@ -837,7 +837,7 @@
"type": "tidelift"
}
],
"time": "2022-03-20T21:51:18+00:00"
"time": "2022-06-20T21:43:03+00:00"
},
{
"name": "itsgoingd/clockwork",
@@ -909,27 +909,27 @@
},
{
"name": "league/climate",
"version": "3.8.1",
"version": "3.8.2",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/climate.git",
"reference": "22243322c6f049240e0fa6ad6c3873343b6f6055"
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/climate/zipball/22243322c6f049240e0fa6ad6c3873343b6f6055",
"reference": "22243322c6f049240e0fa6ad6c3873343b6f6055",
"url": "https://api.github.com/repos/thephpleague/climate/zipball/a785a3ac8f584eed4abd45e4e16fe64c46659a28",
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28",
"shasum": ""
},
"require": {
"php": "^7.3 || ^8.0",
"psr/log": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"seld/cli-prompt": "^1.0"
},
"require-dev": {
"mikey179/vfsstream": "^1.4",
"mikey179/vfsstream": "^1.6.10",
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.5.0"
"phpunit/phpunit": "^9.5.10"
},
"suggest": {
"ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring"
@@ -968,9 +968,9 @@
],
"support": {
"issues": "https://github.com/thephpleague/climate/issues",
"source": "https://github.com/thephpleague/climate/tree/3.8.1"
"source": "https://github.com/thephpleague/climate/tree/3.8.2"
},
"time": "2022-01-23T14:38:49+00:00"
"time": "2022-06-18T14:42:08+00:00"
},
{
"name": "matthiasmullie/minify",
@@ -1356,16 +1356,16 @@
},
{
"name": "nyholm/psr7",
"version": "1.5.0",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/Nyholm/psr7.git",
"reference": "1461e07a0f2a975a52082ca3b769ca912b816226"
"reference": "f734364e38a876a23be4d906a2a089e1315be18a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Nyholm/psr7/zipball/1461e07a0f2a975a52082ca3b769ca912b816226",
"reference": "1461e07a0f2a975a52082ca3b769ca912b816226",
"url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a",
"reference": "f734364e38a876a23be4d906a2a089e1315be18a",
"shasum": ""
},
"require": {
@@ -1417,7 +1417,7 @@
],
"support": {
"issues": "https://github.com/Nyholm/psr7/issues",
"source": "https://github.com/Nyholm/psr7/tree/1.5.0"
"source": "https://github.com/Nyholm/psr7/tree/1.5.1"
},
"funding": [
{
@@ -1429,7 +1429,7 @@
"type": "github"
}
],
"time": "2022-02-02T18:37:57+00:00"
"time": "2022-06-22T07:13:36+00:00"
},
{
"name": "nyholm/psr7-server",
@@ -1655,20 +1655,20 @@
},
{
"name": "psr/container",
"version": "1.1.2",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf",
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
"php": ">=7.2.0"
},
"type": "library",
"autoload": {
@@ -1697,9 +1697,9 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/1.1.2"
"source": "https://github.com/php-fig/container/tree/1.1.1"
},
"time": "2021-11-05T16:50:12+00:00"
"time": "2021-03-05T17:36:06+00:00"
},
{
"name": "psr/http-factory",
@@ -2224,16 +2224,16 @@
},
{
"name": "symfony/console",
"version": "v4.4.42",
"version": "v4.4.43",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "cce7a9f99e22937a71a16b23afa762558808d587"
"reference": "8a2628d2d5639f35113dc1b833ecd91e1ed1cf46"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/cce7a9f99e22937a71a16b23afa762558808d587",
"reference": "cce7a9f99e22937a71a16b23afa762558808d587",
"url": "https://api.github.com/repos/symfony/console/zipball/8a2628d2d5639f35113dc1b833ecd91e1ed1cf46",
"reference": "8a2628d2d5639f35113dc1b833ecd91e1ed1cf46",
"shasum": ""
},
"require": {
@@ -2294,7 +2294,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.42"
"source": "https://github.com/symfony/console/tree/v4.4.43"
},
"funding": [
{
@@ -2310,20 +2310,20 @@
"type": "tidelift"
}
],
"time": "2022-05-14T12:35:33+00:00"
"time": "2022-06-23T12:22:25+00:00"
},
{
"name": "symfony/contracts",
"version": "v1.1.12",
"version": "v1.1.13",
"source": {
"type": "git",
"url": "https://github.com/symfony/contracts.git",
"reference": "5236c15b24aeeecee4b9c6ad4b22f6331f2cbdcb"
"reference": "9e27f5c175ecbd6fff554d839ff4a432da797168"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/contracts/zipball/5236c15b24aeeecee4b9c6ad4b22f6331f2cbdcb",
"reference": "5236c15b24aeeecee4b9c6ad4b22f6331f2cbdcb",
"url": "https://api.github.com/repos/symfony/contracts/zipball/9e27f5c175ecbd6fff554d839ff4a432da797168",
"reference": "9e27f5c175ecbd6fff554d839ff4a432da797168",
"shasum": ""
},
"require": {
@@ -2388,7 +2388,7 @@
"standards"
],
"support": {
"source": "https://github.com/symfony/contracts/tree/v1.1.12"
"source": "https://github.com/symfony/contracts/tree/v1.1.13"
},
"funding": [
{
@@ -2404,7 +2404,7 @@
"type": "tidelift"
}
],
"time": "2022-03-09T17:53:12+00:00"
"time": "2022-06-27T13:16:42+00:00"
},
{
"name": "symfony/event-dispatcher",
@@ -3214,16 +3214,16 @@
},
{
"name": "symfony/yaml",
"version": "v4.4.37",
"version": "v4.4.43",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "d7f637cc0f0cc14beb0984f2bb50da560b271311"
"reference": "07e392f0ef78376d080d5353c081a5e5704835bd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/d7f637cc0f0cc14beb0984f2bb50da560b271311",
"reference": "d7f637cc0f0cc14beb0984f2bb50da560b271311",
"url": "https://api.github.com/repos/symfony/yaml/zipball/07e392f0ef78376d080d5353c081a5e5704835bd",
"reference": "07e392f0ef78376d080d5353c081a5e5704835bd",
"shasum": ""
},
"require": {
@@ -3265,7 +3265,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v4.4.37"
"source": "https://github.com/symfony/yaml/tree/v4.4.43"
},
"funding": [
{
@@ -3281,7 +3281,7 @@
"type": "tidelift"
}
],
"time": "2022-01-24T20:11:01+00:00"
"time": "2022-06-20T08:31:17+00:00"
},
{
"name": "twig/twig",
@@ -3484,16 +3484,16 @@
},
{
"name": "codeception/codeception",
"version": "4.1.31",
"version": "4.2.1",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
"reference": "15524571ae0686a7facc2eb1f40f600e5bbce9e5"
"reference": "77b3e2003fd4446b35826cb9dc397129c521c888"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/15524571ae0686a7facc2eb1f40f600e5bbce9e5",
"reference": "15524571ae0686a7facc2eb1f40f600e5bbce9e5",
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/77b3e2003fd4446b35826cb9dc397129c521c888",
"reference": "77b3e2003fd4446b35826cb9dc397129c521c888",
"shasum": ""
},
"require": {
@@ -3556,11 +3556,11 @@
{
"name": "Michael Bodnarchuk",
"email": "davert@mail.ua",
"homepage": "http://codegyre.com"
"homepage": "https://codegyre.com"
}
],
"description": "BDD-style testing framework",
"homepage": "http://codeception.com/",
"homepage": "https://codeception.com/",
"keywords": [
"BDD",
"TDD",
@@ -3570,7 +3570,7 @@
],
"support": {
"issues": "https://github.com/Codeception/Codeception/issues",
"source": "https://github.com/Codeception/Codeception/tree/4.1.31"
"source": "https://github.com/Codeception/Codeception/tree/4.2.1"
},
"funding": [
{
@@ -3578,7 +3578,7 @@
"type": "open_collective"
}
],
"time": "2022-03-13T17:07:08+00:00"
"time": "2022-06-22T06:18:59+00:00"
},
{
"name": "codeception/lib-asserts",
@@ -3862,24 +3862,20 @@
},
{
"name": "codeception/stub",
"version": "4.0.2",
"version": "3.7.0",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Stub.git",
"reference": "18a148dacd293fc7b044042f5aa63a82b08bff5d"
"reference": "468dd5fe659f131fc997f5196aad87512f9b1304"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Stub/zipball/18a148dacd293fc7b044042f5aa63a82b08bff5d",
"reference": "18a148dacd293fc7b044042f5aa63a82b08bff5d",
"url": "https://api.github.com/repos/Codeception/Stub/zipball/468dd5fe659f131fc997f5196aad87512f9b1304",
"reference": "468dd5fe659f131fc997f5196aad87512f9b1304",
"shasum": ""
},
"require": {
"php": "^7.4 | ^8.0",
"phpunit/phpunit": "^8.4 | ^9.0 | ^10.0 | 10.0.x-dev"
},
"require-dev": {
"consolidation/robo": "^3.0"
"phpunit/phpunit": "^8.4 | ^9.0"
},
"type": "library",
"autoload": {
@@ -3894,9 +3890,9 @@
"description": "Flexible Stub wrapper for PHPUnit's Mock Builder",
"support": {
"issues": "https://github.com/Codeception/Stub/issues",
"source": "https://github.com/Codeception/Stub/tree/4.0.2"
"source": "https://github.com/Codeception/Stub/tree/3.7.0"
},
"time": "2022-01-31T19:25:15+00:00"
"time": "2020-07-03T15:54:43+00:00"
},
{
"name": "doctrine/instantiator",
@@ -4022,22 +4018,22 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "7.4.4",
"version": "7.4.5",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8"
"reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82",
"reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.5",
"guzzlehttp/psr7": "^1.8.3 || ^2.1",
"guzzlehttp/psr7": "^1.9 || ^2.4",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
@@ -4126,7 +4122,7 @@
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.4.4"
"source": "https://github.com/guzzle/guzzle/tree/7.4.5"
},
"funding": [
{
@@ -4142,7 +4138,7 @@
"type": "tidelift"
}
],
"time": "2022-06-09T21:39:15+00:00"
"time": "2022-06-20T22:16:13+00:00"
},
{
"name": "guzzlehttp/promises",
@@ -4683,16 +4679,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.7.14",
"version": "1.7.15",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "e6f145f196a59c7ca91ea926c87ef3d936c4305f"
"reference": "cd0202ea1b1fc6d1bbe156c6e2e18a03e0ff160a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/e6f145f196a59c7ca91ea926c87ef3d936c4305f",
"reference": "e6f145f196a59c7ca91ea926c87ef3d936c4305f",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd0202ea1b1fc6d1bbe156c6e2e18a03e0ff160a",
"reference": "cd0202ea1b1fc6d1bbe156c6e2e18a03e0ff160a",
"shasum": ""
},
"require": {
@@ -4718,7 +4714,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.7.14"
"source": "https://github.com/phpstan/phpstan/tree/1.7.15"
},
"funding": [
{
@@ -4738,7 +4734,7 @@
"type": "tidelift"
}
],
"time": "2022-06-14T13:09:35+00:00"
"time": "2022-06-20T08:29:01+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
@@ -5110,16 +5106,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.20",
"version": "9.5.21",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba"
"reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba",
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0e32b76be457de00e83213528f6bb37e2a38fcb1",
"reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1",
"shasum": ""
},
"require": {
@@ -5153,7 +5149,6 @@
"sebastian/version": "^3.0.2"
},
"require-dev": {
"ext-pdo": "*",
"phpspec/prophecy-phpunit": "^2.0.1"
},
"suggest": {
@@ -5197,7 +5192,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.21"
},
"funding": [
{
@@ -5209,7 +5204,7 @@
"type": "github"
}
],
"time": "2022-04-01T12:37:26+00:00"
"time": "2022-06-19T12:14:25+00:00"
},
{
"name": "psr/http-client",
@@ -6367,7 +6362,7 @@
},
{
"name": "symfony/deprecation-contracts",
"version": "v2.5.1",
"version": "v2.5.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
@@ -6414,7 +6409,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.1"
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2"
},
"funding": [
{
@@ -6685,7 +6680,7 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.4.1 || ^8.0",
"php": "^7.3.6 || ^8.0",
"ext-json": "*",
"ext-openssl": "*",
"ext-curl": "*",
@@ -6695,7 +6690,7 @@
},
"platform-dev": [],
"platform-overrides": {
"php": "7.4.1"
"php": "7.3.6"
},
"plugin-api-version": "2.2.0"
}

View File

@@ -50,13 +50,6 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
*/
public function metadata();
/**
* Returns an array containing the file metadata
*
* @return array
*/
public function getMeta();
/**
* Add meta file for the medium.
*
@@ -165,14 +158,6 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
*/
public function thumbnail($type = 'auto');
/**
* Return URL to file.
*
* @param bool $reset
* @return string
*/
public function url($reset = true);
/**
* Turn the current Medium into a Link
*
@@ -228,18 +213,6 @@ interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObj
#[\ReturnTypeWillChange]
public function __call($method, $args);
/**
* Get value by using dot notation for nested arrays/objects.
*
* @example $value = $this->get('this.is.my.nested.variable');
*
* @param string $name Dot separated path to the requested value.
* @param mixed $default Default value (or null).
* @param string|null $separator Separator, defaults to '.'
* @return mixed Value.
*/
public function get($name, $default = null, $separator = null);
/**
* Set value by using dot notation for nested arrays/objects.
*

View File

@@ -21,7 +21,7 @@ interface RelationshipIdentifierInterface extends IdentifierInterface
/**
* Get identifier meta.
*
* @return array|ArrayAccess
* @return array<string,mixed>|ArrayAccess<string,mixed>
* @phpstan-pure
*/
public function getIdentifierMeta();

View File

@@ -13,6 +13,7 @@ use Serializable;
*
* @template T of IdentifierInterface
* @template P of IdentifierInterface
* @extends IteratorAggregate<string, T>
*/
interface RelationshipInterface extends Countable, IteratorAggregate, JsonSerializable, Serializable
{

View File

@@ -9,6 +9,11 @@ use JsonSerializable;
/**
* Interface RelationshipsInterface
*
* @template T of \Grav\Framework\Contracts\Object\IdentifierInterface
* @template P of \Grav\Framework\Contracts\Object\IdentifierInterface
* @extends ArrayAccess<string,RelationshipInterface<T,P>>
* @extends Iterator<string,RelationshipInterface<T,P>>
*/
interface RelationshipsInterface extends Countable, ArrayAccess, Iterator, JsonSerializable
{
@@ -31,12 +36,12 @@ interface RelationshipsInterface extends Countable, ArrayAccess, Iterator, JsonS
/**
* @param string $offset
* @return RelationshipInterface|null
* @return RelationshipInterface<T,P>|null
*/
public function offsetGet($offset): ?RelationshipInterface;
/**
* @return RelationshipInterface|null
* @return RelationshipInterface<T,P>|null
*/
public function current(): ?RelationshipInterface;

View File

@@ -11,15 +11,18 @@ use RuntimeException;
* Interface IdentifierInterface
*
* @template T of FlexObjectInterface
* @extends Identifier<T>
*/
class FlexIdentifier extends Identifier
{
private string $keyField;
private ?FlexObjectInterface $object = null;
/** @var string */
private $keyField;
/** @var FlexObjectInterface|null */
private $object = null;
/**
* @param FlexObjectInterface $object
* @return FlexIdentifier
* @return FlexIdentifier<T>
*/
public static function createFromObject(FlexObjectInterface $object): FlexIdentifier
{

View File

@@ -12,7 +12,6 @@ namespace Grav\Framework\Flex\Traits;
use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
use Grav\Common\Media\Interfaces\MediaObjectInterface;
use Grav\Common\Media\Interfaces\MediaUploadInterface;
use Grav\Common\Media\Traits\MediaTrait;
use Grav\Common\Page\Media;
@@ -23,6 +22,7 @@ use Grav\Framework\Cache\CacheInterface;
use Grav\Framework\Filesystem\Filesystem;
use Grav\Framework\Flex\FlexDirectory;
use Grav\Framework\Form\FormFlashFile;
use Grav\Framework\Media\Interfaces\MediaObjectInterface;
use Grav\Framework\Media\MediaObject;
use Grav\Framework\Media\UploadedMediaObject;
use Psr\Http\Message\UploadedFileInterface;
@@ -336,8 +336,9 @@ trait FlexMediaTrait
if ($medium) {
if ($medium->uploaded_file) {
$upload = $medium->uploaded_file;
$id = $upload->getId();
$list[] = new UploadedMediaObject($upload->getId(), $field, $name, $upload);
$list[] = new UploadedMediaObject($id, $field, $name, $upload);
} else {
$list[] = $this->buildMediaObject($field, $name, $medium);
}

View File

@@ -12,7 +12,8 @@ use Grav\Framework\Relationships\Relationships;
*/
trait FlexRelationshipsTrait
{
private ?RelationshipsInterface $_relationships = null;
/** @var RelationshipsInterface|null */
private $_relationships = null;
/**
* @return Relationships

View File

@@ -9,9 +9,39 @@
namespace Grav\Framework\Media\Interfaces;
use Psr\Http\Message\UploadedFileInterface;
/**
* Class implements media object interface.
*
* @property UploadedFileInterface|null $uploaded_file
*/
interface MediaObjectInterface
{
/**
* Returns an array containing the file metadata
*
* @return array
*/
public function getMeta();
/**
* Return URL to file.
*
* @param bool $reset
* @return string
*/
public function url($reset = true);
/**
* Get value by using dot notation for nested arrays/objects.
*
* @example $value = $this->get('this.is.my.nested.variable');
*
* @param string $name Dot separated path to the requested value.
* @param mixed $default Default value (or null).
* @param string|null $separator Separator, defaults to '.'
* @return mixed Value.
*/
public function get($name, $default = null, $separator = null);
}

View File

@@ -14,14 +14,16 @@ use Grav\Framework\Object\Identifiers\Identifier;
* Interface IdentifierInterface
*
* @template T of MediaObjectInterface
* @extends Identifier<T>
*/
class MediaIdentifier extends Identifier
{
private ?MediaObjectInterface $object = null;
/** @var MediaObjectInterface|null */
private $object = null;
/**
* @param MediaObjectInterface $object
* @return MediaIdentifier
* @return MediaIdentifier<T>
*/
public static function createFromObject(MediaObjectInterface $object): MediaIdentifier
{

View File

@@ -2,11 +2,12 @@
namespace Grav\Framework\Media;
use Grav\Common\Media\Interfaces\MediaObjectInterface as GravMediaObjectInterface;
use Grav\Common\Page\Medium\ImageMedium;
use Grav\Framework\Contracts\Media\MediaObjectInterface;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
use Grav\Framework\Media\Interfaces\MediaObjectInterface as GravMediaObjectInterface;
use Grav\Framework\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Throwable;
/**
@@ -14,13 +15,18 @@ use Throwable;
*/
class MediaObject implements MediaObjectInterface
{
static public string $placeholderImage = 'image://media/thumb.png';
/** @var string */
static public $placeholderImage = 'image://media/thumb.png';
public FlexObjectInterface $object;
public ?GravMediaObjectInterface $media;
/** @var FlexObjectInterface */
public $object;
/** @var GravMediaObjectInterface|null */
public $media;
private ?string $field;
private string $filename;
/** @var string|null */
private $field;
/** @var string */
private $filename;
/**
* MediaObject constructor.
@@ -108,7 +114,7 @@ class MediaObject implements MediaObjectInterface
* @param array $actions
* @return Response
*/
public function createResponse(array $actions): Response
public function createResponse(array $actions): ResponseInterface
{
if (!isset($this->media)) {
return $this->create404Response($actions);

View File

@@ -6,6 +6,7 @@ use Grav\Framework\Contracts\Media\MediaObjectInterface;
use Grav\Framework\Flex\FlexFormFlash;
use Grav\Framework\Form\Interfaces\FormFlashInterface;
use Grav\Framework\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UploadedFileInterface;
/**
@@ -13,15 +14,22 @@ use Psr\Http\Message\UploadedFileInterface;
*/
class UploadedMediaObject implements MediaObjectInterface
{
static public string $placeholderImage = 'image://media/thumb.png';
/** @var string */
static public $placeholderImage = 'image://media/thumb.png';
public FormFlashInterface $object;
/** @var FormFlashInterface */
public $object;
private string $id;
private ?string $field;
private string $filename;
private array $meta;
private ?UploadedFileInterface $uploadedFile;
/** @var string */
private $id;
/** @var string|null */
private $field;
/** @var string */
private $filename;
/** @var array */
private $meta;
/** @var UploadedFileInterface|null */
private $uploadedFile;
/**
* @param FlexFormFlash $flash
@@ -126,7 +134,7 @@ class UploadedMediaObject implements MediaObjectInterface
* @param array $actions
* @return Response
*/
public function createResponse(array $actions): Response
public function createResponse(array $actions): ResponseInterface
{
// Display placeholder image.
$filename = static::$placeholderImage;

View File

@@ -11,8 +11,10 @@ use Grav\Framework\Contracts\Object\IdentifierInterface;
*/
class Identifier implements IdentifierInterface
{
private string $id;
private string $type;
/** @var string */
private $id;
/** @var string */
private $type;
/**
* IdentifierInterface constructor.

View File

@@ -11,18 +11,24 @@ use function count;
/**
* Class Relationships
*
* @template T of \Grav\Framework\Contracts\Object\IdentifierInterface
* @template P of \Grav\Framework\Contracts\Object\IdentifierInterface
* @implements RelationshipsInterface<T,P>
*/
class Relationships implements RelationshipsInterface
{
protected IdentifierInterface $parent;
protected array $options;
/** @var P */
protected $parent;
/** @var array */
protected $options;
/** @var RelationshipInterface[] */
protected array $relationships;
/** @var RelationshipInterface<T,P>[] */
protected $relationships;
/**
* Relationships constructor.
* @param IdentifierInterface $parent
* @param P $parent
* @param array $options
*/
public function __construct(IdentifierInterface $parent, array $options)
@@ -42,7 +48,7 @@ class Relationships implements RelationshipsInterface
}
/**
* @return RelationshipInterface[]
* @return RelationshipInterface<T,P>[]
* @phpstan-pure
*/
public function getModified(): array
@@ -78,7 +84,7 @@ class Relationships implements RelationshipsInterface
/**
* @param string $offset
* @return RelationshipInterface|null
* @return RelationshipInterface<T,P>|null
*/
public function offsetGet($offset): ?RelationshipInterface
{
@@ -114,7 +120,7 @@ class Relationships implements RelationshipsInterface
}
/**
* @return RelationshipInterface|null
* @return RelationshipInterface<T,P>|null
*/
public function current(): ?RelationshipInterface
{
@@ -178,7 +184,7 @@ class Relationships implements RelationshipsInterface
/**
* @param string $name
* @param array $options
* @return RelationshipInterface
* @return ToOneRelationship|ToManyRelationship
*/
private function createRelationship(string $name, array $options): RelationshipInterface
{

View File

@@ -13,9 +13,9 @@ use function is_callable;
/**
* Class ToManyRelationship
*
* @template T of object
* @template P of object
* @template-implements ToManyRelationshipInterface<IdentifierInterface,IdentifierInterface>
* @template T of IdentifierInterface
* @template P of IdentifierInterface
* @template-implements ToManyRelationshipInterface<T,P>
*/
class ToManyRelationship implements ToManyRelationshipInterface
{
@@ -24,7 +24,7 @@ class ToManyRelationship implements ToManyRelationshipInterface
use Serializable;
/** @var IdentifierInterface[] */
protected array $identifiers = [];
protected $identifiers = [];
/**
* ToManyRelationship constructor.

View File

@@ -12,8 +12,9 @@ use function is_callable;
/**
* Class ToOneRelationship
*
* @template T of object
* @template-implements ToOneRelationshipInterface<IdentifierInterface,IdentifierInterface>
* @template T of IdentifierInterface
* @template P of IdentifierInterface
* @template-implements ToOneRelationshipInterface<T,P>
*/
class ToOneRelationship implements ToOneRelationshipInterface
{
@@ -21,7 +22,8 @@ class ToOneRelationship implements ToOneRelationshipInterface
use RelationshipTrait;
use Serializable;
protected ?IdentifierInterface $identifier = null;
/** @var IdentifierInterface|null */
protected $identifier = null;
public function __construct(IdentifierInterface $parent, string $name, array $options, IdentifierInterface $identifier = null)
{

View File

@@ -6,6 +6,7 @@ use Grav\Framework\Contracts\Object\IdentifierInterface;
use Grav\Framework\Flex\FlexIdentifier;
use Grav\Framework\Media\MediaIdentifier;
use Grav\Framework\Object\Identifiers\Identifier;
use RuntimeException;
use function get_class;
/**
@@ -15,11 +16,16 @@ use function get_class;
*/
trait RelationshipTrait
{
protected IdentifierInterface $parent;
protected string $name;
protected string $type;
protected array $options;
protected bool $modified = false;
/** @var IdentifierInterface */
protected $parent;
/** @var string */
protected $name;
/** @var string */
protected $type;
/** @var array */
protected $options;
/** @var bool */
protected $modified = false;
/**
* @return string
@@ -85,10 +91,10 @@ trait RelationshipTrait
if ($min || $max) {
$count = $this->count();
if ($min && $count < $min) {
throw new \RuntimeException(sprintf('%s relationship has too few objects in it', $this->name));
throw new RuntimeException(sprintf('%s relationship has too few objects in it', $this->name));
}
if ($max && $count > $max) {
throw new \RuntimeException(sprintf('%s relationship has too many objects in it', $this->name));
throw new RuntimeException(sprintf('%s relationship has too many objects in it', $this->name));
}
}
}
@@ -100,7 +106,7 @@ trait RelationshipTrait
private function checkIdentifier(IdentifierInterface $identifier): IdentifierInterface
{
if ($this->type !== $identifier->getType()) {
throw new \RuntimeException(sprintf('Bad identifier type %s', $identifier->getType()));
throw new RuntimeException(sprintf('Bad identifier type %s', $identifier->getType()));
}
if (get_class($identifier) !== Identifier::class) {