Skip to content

Commit

Permalink
Minor controller code improvements before release 1.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Poortman committed Jul 29, 2024
1 parent e5d4ecf commit 1291fc8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Controller/Post/Livewire.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php declare(strict_types=1);
<?php
/**
* Copyright © Willem Poortman 2021-present. All rights reserved.
*
* Please read the README and LICENSE files for more
* details on copyrights and license information.
*/

declare(strict_types=1);

namespace Magewirephp\Magewire\Controller\Post;

use Exception;
use Laminas\Http\AbstractMessage;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\NotFoundException;
Expand Down Expand Up @@ -64,7 +67,9 @@ public function __construct(
$this->logger = $logger;
$this->magewireViewModel = $magewireViewModel;
$this->componentResolver = $componentResolver;
$this->serializer = $serializer;

$this->serializer = $serializer
?: ObjectManager::getInstance()->get(SerializerInterface::class);
}

public function execute(): Json
Expand Down Expand Up @@ -155,10 +160,20 @@ public function getHttpResponseStatuses(): array
return $statuses;
}

/**
* Allows the Livewire Browser Plugin to modify component properties,
* which triggers an AJAX call similar to the MageWire JS API's form.set('address.country_id', 'NL').
* In such cases, the request parameters, including the fingerprint, are sent in a JSON body
* instead of traditional request parameters.
*
* This method ensures compatibility by supporting both JSON body and request parameters,
* enabling seamless interaction between the client and server.
*/
private function getRequestParams(): array
{
$content = $this->request->getContent();
if (!empty($content)) {

if (! empty($content)) {
return $this->serializer->unserialize($content);
}

Expand Down

0 comments on commit 1291fc8

Please sign in to comment.