From fddc19a5b8693415893d6a3e2584ef2520a54120 Mon Sep 17 00:00:00 2001 From: Francis Libiano Date: Sat, 20 Apr 2024 22:01:41 +0800 Subject: [PATCH 1/5] [Laravel 10] Deprecated Dates Property --- src/Concerns/HasAttributes.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Concerns/HasAttributes.php b/src/Concerns/HasAttributes.php index 880724a..0746b88 100755 --- a/src/Concerns/HasAttributes.php +++ b/src/Concerns/HasAttributes.php @@ -2,8 +2,8 @@ namespace Cristal\ApiWrapper\Concerns; -use Cristal\ApiWrapper\Model; use LogicException; +use Cristal\ApiWrapper\Model; use Cristal\ApiWrapper\Relations\RelationInterface; trait HasAttributes @@ -43,13 +43,6 @@ trait HasAttributes */ protected $appends = []; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $dates = []; - /** * The storage format of the model's date columns. * @@ -430,7 +423,8 @@ protected function asDateTime($value) // the database connection and use that format to create the Carbon object // that is returned back out to the developers after we convert it here. return \DateTime::createFromFormat( - str_replace('.v', '.u', $this->getDateFormat()), $value + str_replace('.v', '.u', $this->getDateFormat()), + $value ); } @@ -757,7 +751,8 @@ protected function addMutatedAttributesToArray(array $attributes, array $mutated // mutated attribute's actual values. After we finish mutating each of the // attributes we will return this final array of the mutated attributes. $attributes[$key] = $this->mutateAttributeForArray( - $key, $attributes[$key] + $key, + $attributes[$key] ); } From 919237d9921e8bf84317fb84847d7adab4e541cd Mon Sep 17 00:00:00 2001 From: Francis Libiano Date: Sat, 20 Apr 2024 22:05:02 +0800 Subject: [PATCH 2/5] [Laravel 10] Update Dependencies Return type of Curl\CaseInsensitiveArray::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-curl-class/php-curl-class/src/Curl/CaseInsensitiveArray.php on line 197 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6c1688e..9296152 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require" : { - "php-curl-class/php-curl-class": "^8.3", + "php-curl-class/php-curl-class": "^9.0", "psr/cache": "^1.0 || ^2.0 || ^3.0" }, "suggest": { From a1aacc84a8702893b9bd3ebc249f1ac9d3e25cee Mon Sep 17 00:00:00 2001 From: Francis Libiano Date: Sat, 20 Apr 2024 22:07:30 +0800 Subject: [PATCH 3/5] [Laravel 10] Allow From Diff Versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9296152..c7f686b 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require" : { - "php-curl-class/php-curl-class": "^9.0", + "php-curl-class/php-curl-class": "^8.3 || ^9.0", "psr/cache": "^1.0 || ^2.0 || ^3.0" }, "suggest": { From d0d27215f188dabb8de4182dec9970b50adc7972 Mon Sep 17 00:00:00 2001 From: Francis Libiano Date: Sat, 20 Apr 2024 22:24:03 +0800 Subject: [PATCH 4/5] Revert "[Laravel 10] Deprecated Dates Property" This reverts commit fddc19a5b8693415893d6a3e2584ef2520a54120. --- src/Concerns/HasAttributes.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Concerns/HasAttributes.php b/src/Concerns/HasAttributes.php index 0746b88..880724a 100755 --- a/src/Concerns/HasAttributes.php +++ b/src/Concerns/HasAttributes.php @@ -2,8 +2,8 @@ namespace Cristal\ApiWrapper\Concerns; -use LogicException; use Cristal\ApiWrapper\Model; +use LogicException; use Cristal\ApiWrapper\Relations\RelationInterface; trait HasAttributes @@ -43,6 +43,13 @@ trait HasAttributes */ protected $appends = []; + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = []; + /** * The storage format of the model's date columns. * @@ -423,8 +430,7 @@ protected function asDateTime($value) // the database connection and use that format to create the Carbon object // that is returned back out to the developers after we convert it here. return \DateTime::createFromFormat( - str_replace('.v', '.u', $this->getDateFormat()), - $value + str_replace('.v', '.u', $this->getDateFormat()), $value ); } @@ -751,8 +757,7 @@ protected function addMutatedAttributesToArray(array $attributes, array $mutated // mutated attribute's actual values. After we finish mutating each of the // attributes we will return this final array of the mutated attributes. $attributes[$key] = $this->mutateAttributeForArray( - $key, - $attributes[$key] + $key, $attributes[$key] ); } From e1769731c831c255372f28645ce0a30446e5a89b Mon Sep 17 00:00:00 2001 From: Francis Libiano Date: Wed, 24 Apr 2024 01:52:29 +0800 Subject: [PATCH 5/5] Return Type Compatibility with L10 --- src/Model.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Model.php b/src/Model.php index 5bd4722..bfb4605 100755 --- a/src/Model.php +++ b/src/Model.php @@ -2,16 +2,16 @@ namespace Cristal\ApiWrapper; -use ArrayAccess; use Closure; +use Exception; +use ArrayAccess; +use JsonSerializable; use Cristal\ApiWrapper\Concerns\HasAttributes; -use Cristal\ApiWrapper\Concerns\HasRelationships; +use Cristal\ApiWrapper\Exceptions\ApiException; use Cristal\ApiWrapper\Concerns\HasGlobalScopes; use Cristal\ApiWrapper\Concerns\HidesAttributes; -use Cristal\ApiWrapper\Exceptions\ApiException; +use Cristal\ApiWrapper\Concerns\HasRelationships; use Cristal\ApiWrapper\Exceptions\MissingApiException; -use Exception; -use JsonSerializable; abstract class Model implements ArrayAccess, JsonSerializable { @@ -184,7 +184,8 @@ public function fill(array $attributes = []) // start_measure('fill-model', 'Création de l\'objet '.static::class); foreach ($attributes as $key => $value) { if (is_array($value) && method_exists($this, $key)) { - $this->setRelation($key, + $this->setRelation( + $key, $this->$key()->getRelationsFromArray($value) ); } else { @@ -318,7 +319,7 @@ public function toArray() * * @return array */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->toArray(); } @@ -330,7 +331,7 @@ public function jsonSerialize() * * @return bool */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return !is_null($this->getAttribute($offset)); } @@ -342,7 +343,7 @@ public function offsetExists($offset) * * @return mixed */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { return $this->getAttribute($offset); } @@ -355,7 +356,7 @@ public function offsetGet($offset) * * @return void */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->setAttribute($offset, $value); } @@ -367,7 +368,7 @@ public function offsetSet($offset, $value) * * @return void */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->attributes[$offset]); }