|
|
@@ -4,23 +4,12 @@ declare(strict_types=1);
|
|
|
namespace App\Service\Rest\Operation;
|
|
|
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
-use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
-use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
|
|
|
/**
|
|
|
* A single update operation (a PUT request)
|
|
|
*/
|
|
|
class UpdateOperation extends BaseRestOperation
|
|
|
{
|
|
|
- protected string $entity;
|
|
|
- protected int $id;
|
|
|
- protected array $data;
|
|
|
-
|
|
|
/**
|
|
|
* @param string $label A label for the operation
|
|
|
* @param string $entityName The name of the entity to update. This will be used in the path of the request.
|
|
|
@@ -31,8 +20,15 @@ class UpdateOperation extends BaseRestOperation
|
|
|
* @param array $options
|
|
|
*/
|
|
|
#[Pure]
|
|
|
- public function __construct(string $label, string $entityName, int $id, array $data, array $initialData = [], array $parameters = [], array $options = []) {
|
|
|
- $this->data = $data;
|
|
|
+ public function __construct(
|
|
|
+ protected string $label,
|
|
|
+ protected string $entityName,
|
|
|
+ protected int $id,
|
|
|
+ protected array $data,
|
|
|
+ protected array $initialData = [],
|
|
|
+ protected array $parameters = [],
|
|
|
+ protected array $options = []
|
|
|
+ ) {
|
|
|
$options['json'] = $this->data;
|
|
|
|
|
|
parent::__construct(
|
|
|
@@ -43,17 +39,14 @@ class UpdateOperation extends BaseRestOperation
|
|
|
$parameters,
|
|
|
$options
|
|
|
);
|
|
|
-
|
|
|
- $this->entity = $entityName;
|
|
|
- $this->id = $id;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function getEntity(): string
|
|
|
+ public function getEntityName(): string
|
|
|
{
|
|
|
- return $this->entity;
|
|
|
+ return $this->entityName;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -71,25 +64,12 @@ class UpdateOperation extends BaseRestOperation
|
|
|
*/
|
|
|
public function getChangeLog(): array {
|
|
|
$messages = [
|
|
|
- '[PUT ' . $this->entity . '/' . $this->id . ']'
|
|
|
+ '[PUT ' . $this->entityName . '/' . $this->id . ']'
|
|
|
];
|
|
|
- foreach ($this->data as $field => $newValue) {
|
|
|
- if (!array_key_exists($field, $this->initialData)) {
|
|
|
- $messages[] = $field . '.' . $field . ' : ? => `' . $newValue . '`';
|
|
|
- } else if (is_array($newValue)) {
|
|
|
- foreach ($newValue as $subField => $newSubValue) {
|
|
|
- if (!array_key_exists($subField, $this->initialData[$field])) {
|
|
|
- $messages[] = $field . '.' . $subField . ' : (new sub-key) `' . $newSubValue . '`';
|
|
|
- }
|
|
|
- else if ($newSubValue !== $this->initialData[$field][$subField]) {
|
|
|
- $messages[] = $field . '.' . $subField . ' : `'. $this->initialData[$field][$subField] . '` => `' . $newSubValue . '`';
|
|
|
- }
|
|
|
- }
|
|
|
- } else if ($newValue !== $this->initialData[$field]) {
|
|
|
- $messages[] = $field . ' : `' . $this->initialData[$field] . '` => `' . $newValue . '`';
|
|
|
- }
|
|
|
- }
|
|
|
+ array_push(
|
|
|
+ $messages,
|
|
|
+ ...self::getRecursiveChangeLog($this->initialData, $this->data)
|
|
|
+ );
|
|
|
return $messages;
|
|
|
}
|
|
|
-
|
|
|
}
|