Skip to content

Commit

Permalink
TASK: Adjust to flow psr controller change
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Sep 12, 2024
1 parent 40d20cd commit d82f947
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,47 @@

namespace Neos\TestNodeTypes\Application\RemoveAdditionalSettings\Controller;

use GuzzleHttp\Psr7\Response;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\ControllerInterface;
use Neos\TestNodeTypes\Application\RemoveAdditionalSettings\RemoveAdditionalSettingsCommand;
use Neos\TestNodeTypes\Application\RemoveAdditionalSettings\RemoveAdditionalSettingsCommandHandler;
use Psr\Http\Message\ResponseInterface;

#[Flow\Scope("singleton")]
final class RemoveAdditionalSettingsController implements ControllerInterface
{
#[Flow\Inject]
protected RemoveAdditionalSettingsCommandHandler $commandHandler;

public function processRequest(ActionRequest $request, ActionResponse $response)
public function processRequest(ActionRequest $request): ResponseInterface
{
$request->setDispatched(true);
$response->setContentType('application/json');

try {
$command = RemoveAdditionalSettingsCommand::fromArray($request->getArguments());
$this->commandHandler->handle($command);

$response->setStatusCode(200);
$response->setContent(
json_encode(
['success' => true],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 200, headers: ['Content-Type' => 'application/json'], body: json_encode(
['success' => true],
JSON_THROW_ON_ERROR
));
} catch (\InvalidArgumentException $e) {
$response->setStatusCode(400);
$response->setContent(
json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 400, headers: ['Content-Type' => 'application/json'], body: json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
));
} catch (\Exception $e) {
$response->setStatusCode(500);
$response->setContent(
json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 500, headers: ['Content-Type' => 'application/json'], body: json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,47 @@

namespace Neos\TestNodeTypes\Application\WriteAdditionalSettings\Controller;

use GuzzleHttp\Psr7\Response;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\ControllerInterface;
use Neos\TestNodeTypes\Application\WriteAdditionalSettings\WriteAdditionalSettingsCommand;
use Neos\TestNodeTypes\Application\WriteAdditionalSettings\WriteAdditionalSettingsCommandHandler;
use Psr\Http\Message\ResponseInterface;

#[Flow\Scope("singleton")]
final class WriteAdditionalSettingsController implements ControllerInterface
{
#[Flow\Inject]
protected WriteAdditionalSettingsCommandHandler $commandHandler;

public function processRequest(ActionRequest $request, ActionResponse $response)
public function processRequest(ActionRequest $request): ResponseInterface
{
$request->setDispatched(true);
$response->setContentType('application/json');

try {
$command = WriteAdditionalSettingsCommand::fromArray($request->getArguments());
$this->commandHandler->handle($command);

$response->setStatusCode(200);
$response->setContent(
json_encode(
['success' => true],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 200, headers: ['Content-Type' => 'application/json'], body: json_encode(
['success' => true],
JSON_THROW_ON_ERROR
));
} catch (\InvalidArgumentException $e) {
$response->setStatusCode(400);
$response->setContent(
json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 400, headers: ['Content-Type' => 'application/json'], body: json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
));
} catch (\Exception $e) {
$response->setStatusCode(500);
$response->setContent(
json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
)
);
return new Response(status: 500, headers: ['Content-Type' => 'application/json'], body: json_encode(
['error' => [
'type' => $e::class,
'code' => $e->getCode(),
'message' => $e->getMessage(),
]],
JSON_THROW_ON_ERROR
));
}
}
}

0 comments on commit d82f947

Please sign in to comment.