diff --git a/src/Controller/MagewireUpdateRoute.php b/src/Controller/MagewireUpdateRoute.php index a3af8833..a3505921 100644 --- a/src/Controller/MagewireUpdateRoute.php +++ b/src/Controller/MagewireUpdateRoute.php @@ -1,4 +1,5 @@ actionFactory, $this->logger, $this->magewireRouteValidator); } + /** + * Matches and processes Magewire update requests. + * + * Validates the request, boots Magewire in subsequent mode, and parses + * component data. Returns a forward action on failure or the matched + * action on success. + */ public function match(RequestInterface $request): ActionInterface|null { $match = parent::match($request); @@ -53,30 +68,42 @@ public function match(RequestInterface $request): ActionInterface|null return null; } - // Mark the request as a subsequent Magewire request. - $request->setParam(self::PARAM_IS_SUBSEQUENT, true); - /** - * Magewire has two trigger points for booting itself. One occurs during the updating of components. - * This is the only feasible location, after confirming we are on an update request, - * where we should attempt to boot. [2/2] + * Boot Magewire and initialize the request context. + * + * Magewire has two trigger points for initialization: + * 1. During component updates (the only feasible location after confirming an update request) + * 2. During page load via the view block observer + * + * This call marks the request as "subsequent" to distinguish between initial page loads + * and subsequent update requests, allowing system-wide determination of Magewire's state. * * @see \Magewirephp\Magewire\Observer\ViewBlockAbstractToHtmlBefore */ - $this->magewireServiceProvider->boot(); + $this->magewireServiceProvider->boot(RequestMode::SUBSEQUENT); try { $request->setParams($this->parseRequest($request)); } catch (Exception $exception) { - return $this->actionFactory->create(Forward::class); + $this->logger->critical($exception->getMessage(), ['exception' => $exception]); + + return null; } return $match; } - /** + * Parses and validates the component update request payload. + * + * Deserializes component data from the request body, verifies checksums, + * validates component prerequisites (resolver/handle), and converts + * component data to service contract objects. + * * @throws LocalizedException + * @throws FileSystemException + * @throws \Magento\Framework\Exception\RuntimeException + * @throws CorruptComponentPayloadException */ protected function parseRequest(RequestInterface $request): array { @@ -103,8 +130,17 @@ protected function parseRequest(RequestInterface $request): array throw new RuntimeException('Base component prerequisites not satisfied.'); } - // Each component request context must conform to the service contract requirements. - $input[self::PARAM_COMPONENTS][$key] = $this->serviceInputProcessor->convertValue($component, ComponentRequestContext::class); + $snapshot = $this->snapshotFactory->create([ + 'data' => $component['snapshot']['data'] ?? [], + 'memo' => $component['snapshot']['memo'] ?? [], + 'checksum' => $component['snapshot']['checksum'] ?? '', + ]); + + $input[self::PARAM_COMPONENTS][$key] = $this->componentRequestContextFactory->create([ + 'snapshot' => $snapshot, + 'calls' => $component['calls'] ?? [], + 'updates' => $component['updates'] ?? [], + ]); } /** @var Request $request */