Skip to content

Commit eeeac83

Browse files
authored
Merge pull request #28 from sitegeist/flow9
Flow9
2 parents fd45e4e + 892e507 commit eeeac83

File tree

8 files changed

+23
-42
lines changed

8 files changed

+23
-42
lines changed

Classes/Application/OpenApiController.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,16 @@
55
namespace Sitegeist\SchemeOnYou\Application;
66

77
use Neos\Flow\Mvc\ActionRequest;
8-
use Neos\Flow\Mvc\ActionResponse;
9-
use Neos\Flow\Mvc\Controller\Arguments;
10-
use Neos\Flow\Mvc\Controller\ControllerContext;
11-
use Neos\Flow\Mvc\Controller\ControllerInterface;
12-
use Neos\Flow\Mvc\Routing\UriBuilder;
8+
use Neos\Flow\Mvc\Controller\ActionController;
9+
use Psr\Http\Message\ResponseInterface;
1310
use Sitegeist\SchemeOnYou\Domain\Metadata\Response;
1411
use Sitegeist\SchemeOnYou\Domain\Schema\SchemaNormalizer;
1512

16-
abstract class OpenApiController implements ControllerInterface
13+
abstract class OpenApiController extends ActionController
1714
{
18-
protected ActionRequest $request;
19-
20-
protected ActionResponse $response;
21-
22-
protected ControllerContext $controllerContext;
23-
24-
final public function processRequest(ActionRequest $request, ActionResponse $response): void
15+
final public function processRequest(ActionRequest $request): ResponseInterface
2516
{
2617
$this->request = $request;
27-
$this->request->setDispatched(true);
28-
$this->response = $response;
29-
$this->response->setContentType('application/json');
30-
$uriBuilder = new UriBuilder();
31-
$uriBuilder->setRequest($this->request);
32-
$this->controllerContext = new ControllerContext(
33-
$this->request,
34-
$this->response,
35-
new Arguments([]),
36-
$uriBuilder
37-
);
3818

3919
$actionName = $request->getControllerActionName() . 'Action';
4020
if (!method_exists($this, $actionName)) {
@@ -49,8 +29,13 @@ final public function processRequest(ActionRequest $request, ActionResponse $res
4929
$result = $this->$actionName(...$parameters);
5030

5131
$responseMetadata = Response::fromReflectionClass(new \ReflectionClass($result));
52-
$this->response->setStatusCode($responseMetadata->statusCode);
5332

54-
$this->response->setContent(json_encode(SchemaNormalizer::normalizeValue($result), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
33+
return new \GuzzleHttp\Psr7\Response(
34+
$responseMetadata->statusCode,
35+
[
36+
'Content-Type' => 'application/json',
37+
],
38+
\json_encode(SchemaNormalizer::normalizeValue($result), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
39+
);
5540
}
5641
}

Classes/Controller/OpenApiDocumentController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66

77
use Neos\Flow\Annotations as Flow;
88
use Neos\Flow\Mvc\Controller\ActionController;
9-
use Neos\Flow\Mvc\View\JsonView;
109
use Sitegeist\SchemeOnYou\Domain\OpenApiDocumentRepository;
1110

1211
class OpenApiDocumentController extends ActionController
1312
{
14-
protected $defaultViewObjectName = JsonView::class;
15-
1613
#[Flow\Inject]
1714
protected OpenApiDocumentRepository $documentRepository;
1815

1916
public function renderAction(string $name): string
2017
{
2118
$schema = $this->documentRepository->findDocumentByName($name);
2219
$this->response->setContentType('application\json');
20+
2321
return \json_encode(
2422
$schema,
2523
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE

Classes/Domain/OpenApiDocument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function __construct(
4040
*/
4141
public static function createFromConfiguration(
4242
array $configuration,
43-
OpenApiPathCollection $paths = null,
44-
OpenApiComponents $components = null,
43+
?OpenApiPathCollection $paths = null,
44+
?OpenApiComponents $components = null,
4545
): self {
4646
return new self(
4747
$configuration['openapi'],

Classes/Domain/OpenApiDocumentFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Neos\Flow\Mvc\Routing\Dto\ResolveContext;
88
use Neos\Flow\Mvc\Routing\Dto\RouteParameters;
9+
use Neos\Flow\Mvc\Routing\RoutesProviderInterface;
910
use Neos\Flow\ObjectManagement\ObjectManager;
1011
use Neos\Flow\ObjectManagement\Proxy\ProxyInterface;
1112
use Neos\Flow\Reflection\ClassReflection;
@@ -26,13 +27,12 @@
2627
use Sitegeist\SchemeOnYou\Domain\Path\PathDefinition;
2728
use Sitegeist\SchemeOnYou\Domain\Schema\IsSupportedInSchema;
2829
use Sitegeist\SchemeOnYou\Domain\Schema\OpenApiSchemaCollection;
29-
use Neos\Flow\Mvc\Routing\Router;
3030

3131
class OpenApiDocumentFactory
3232
{
3333
public function __construct(
3434
private readonly ReflectionService $reflectionService,
35-
private readonly Router $router,
35+
private readonly RoutesProviderInterface $routesProvider,
3636
private readonly ObjectManager $objectManager,
3737
private readonly UriFactoryInterface $uriFactory,
3838
) {
@@ -135,7 +135,7 @@ private function createPathsFromPathAndMethodReflection(ClassReflection $classRe
135135
if (!$controllerObjectName) {
136136
throw new \DomainException('Class ' . $className . ' is unknown to the object manager and thus cannot be processed');
137137
}
138-
$controllerPackageKey = $this->objectManager->getPackageKeyByObjectName($controllerObjectName);
138+
$controllerPackageKey = $this->objectManager->getPackageKeyByObjectName($controllerObjectName) ?: '';
139139
$controllerPackageNamespace = str_replace('.', '\\', $controllerPackageKey);
140140
if (!str_ends_with($className, 'Controller')) {
141141
throw new \DomainException('Only for controller classes');
@@ -214,7 +214,7 @@ private function createPathsFromPathAndMethodReflection(ClassReflection $classRe
214214
}
215215
}
216216

217-
foreach ($this->router->getRoutes() as $route) {
217+
foreach ($this->routesProvider->getRoutes() as $route) {
218218
if ($route->resolves($resolveContext)) {
219219
$path = str_replace(
220220
['{@package}', '{@subpackage}', '{@controller}', '{@action}'],

Classes/Domain/Schema/OpenApiSchema.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public static function fromReflectionParameter(\ReflectionParameter $reflection)
8686
'bool' => 'boolean',
8787
'string' => 'string',
8888
'float' => 'number',
89-
default => throw new \DomainException('Unsupported type ' . $typeName)
9089
},
9190
format: match ($typeName) {
9291
'string' => StringProperty::tryfromReflectionParameter($reflection)?->format ?: null,

Configuration/Settings.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ Sitegeist:
2222
# the separate dictionaries that may be rendered
2323
# example: {name: string, classNames: [string]}
2424
documents: []
25-
26-

Tests/Unit/Domain/OpenApiDocumentFactoryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Neos\Flow\Mvc\Routing\Dto\ResolveContext;
99
use Neos\Flow\Mvc\Routing\Route;
1010
use Neos\Flow\Mvc\Routing\Router;
11+
use Neos\Flow\Mvc\Routing\RoutesProviderInterface;
1112
use Neos\Flow\ObjectManagement\ObjectManager;
1213
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
1314
use Neos\Flow\Reflection\ReflectionService;
@@ -76,10 +77,10 @@ public function setUp(): void
7677
->method('convertObjectsToIdentityArrays')
7778
->willReturnCallback(fn (array $input): array => $input);
7879

79-
$mockRouter = $this->getMockBuilder(Router::class)
80+
$mockRoutesProvider = $this->getMockBuilder(RoutesProviderInterface::class)
8081
->onlyMethods(['getRoutes'])
8182
->getMock();
82-
$mockRouter->expects($this->any())
83+
$mockRoutesProvider->expects($this->any())
8384
->method('getRoutes')
8485
->willReturn([
8586
$this->createMockRoute(
@@ -132,7 +133,7 @@ public function setUp(): void
132133

133134
$this->subject = new OpenApiDocumentFactory(
134135
$mockReflectionService,
135-
$mockRouter,
136+
$mockRoutesProvider,
136137
$mockObjectManager,
137138
new UriFactory()
138139
);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "LGPL-3.0",
66
"require": {
77
"php": "^8.2",
8-
"neos/flow": "^8.0"
8+
"neos/flow": "^9.0"
99
},
1010
"require-dev": {
1111
"phpunit/phpunit": "^10.0",

0 commit comments

Comments
 (0)