Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_entrypoint', '/{index}.{_format}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could put index in the path, since there is a requirements index=index, but it turns out that index is optional. This route matches /

->controller('api_platform.action.entrypoint')
->methods(['GET', 'HEAD'])
->defaults([
'_format' => null,
'_api_respond' => true,
'index' => 'index',
])
->requirements([
'index' => 'index',
]);
};
16 changes: 0 additions & 16 deletions src/Symfony/Bundle/Resources/config/routing/api.xml

This file was deleted.

24 changes: 24 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/docs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_doc', '/docs.{_format}')
->controller('api_platform.action.documentation')
->methods(['GET', 'HEAD'])
->defaults([
'_format' => null,
'_api_respond' => true,
]);
};
14 changes: 0 additions & 14 deletions src/Symfony/Bundle/Resources/config/routing/docs.xml

This file was deleted.

20 changes: 20 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_validation_errors', '/validation_errors/{id}')
->controller('api_platform.action.not_exposed')
->methods(['GET', 'HEAD']);
};
11 changes: 0 additions & 11 deletions src/Symfony/Bundle/Resources/config/routing/errors.xml

This file was deleted.

23 changes: 23 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/genid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_genid', '/.well-known/genid/{id}')
->controller('api_platform.action.not_exposed')
->methods(['GET', 'HEAD'])
->defaults([
'_api_respond' => true,
]);
};
13 changes: 0 additions & 13 deletions src/Symfony/Bundle/Resources/config/routing/genid.xml

This file was deleted.

20 changes: 20 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/graphql/graphiql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_graphql_graphiql', '/graphql/graphiql')
->controller('api_platform.graphql.action.graphiql')
->methods(['GET', 'HEAD']);
};
12 changes: 0 additions & 12 deletions src/Symfony/Bundle/Resources/config/routing/graphql/graphiql.xml

This file was deleted.

19 changes: 19 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/graphql/graphql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_graphql_entrypoint', '/graphql')
->controller('api_platform.graphql.action.entrypoint');
};
12 changes: 0 additions & 12 deletions src/Symfony/Bundle/Resources/config/routing/graphql/graphql.xml

This file was deleted.

28 changes: 28 additions & 0 deletions src/Symfony/Bundle/Resources/config/routing/jsonld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\Routing\Loader\Configurator;

return function (RoutingConfigurator $routes) {
$routes->add('api_jsonld_context', '/contexts/{shortName}.{_format}')
->controller('api_platform.jsonld.action.context')
->methods(['GET', 'HEAD'])
->defaults([
'_format' => 'jsonld',
'_api_respond' => true,
])
->requirements([
'shortName' => '[^.]+',
'_format' => 'jsonld',
]);
};
17 changes: 0 additions & 17 deletions src/Symfony/Bundle/Resources/config/routing/jsonld.xml

This file was deleted.

20 changes: 10 additions & 10 deletions src/Symfony/Routing/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Loader\XmlFileLoader;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

Expand All @@ -35,12 +35,12 @@ final class ApiLoader extends Loader
{
public const DEFAULT_ACTION_PATTERN = 'api_platform.action.';

private readonly XmlFileLoader $fileLoader;
private readonly PhpFileLoader $fileLoader;

public function __construct(KernelInterface $kernel, private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly ContainerInterface $container, private readonly array $formats, private readonly array $resourceClassDirectories = [], private readonly bool $graphqlEnabled = false, private readonly bool $entrypointEnabled = true, public readonly bool $docsEnabled = true, private readonly bool $graphiQlEnabled = false)
{
$paths = $kernel->locateResource('@ApiPlatformBundle/Resources/config/routing');
$this->fileLoader = new XmlFileLoader(new FileLocator($paths));
$this->fileLoader = new PhpFileLoader(new FileLocator($paths));
}

/**
Expand Down Expand Up @@ -127,28 +127,28 @@ public function supports(mixed $resource, ?string $type = null): bool
*/
private function loadExternalFiles(RouteCollection $routeCollection): void
{
$routeCollection->addCollection($this->fileLoader->load('docs.xml'));
$routeCollection->addCollection($this->fileLoader->load('genid.xml'));
$routeCollection->addCollection($this->fileLoader->load('errors.xml'));
$routeCollection->addCollection($this->fileLoader->load('docs.php'));
$routeCollection->addCollection($this->fileLoader->load('genid.php'));
$routeCollection->addCollection($this->fileLoader->load('errors.php'));

if ($this->entrypointEnabled) {
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
$routeCollection->addCollection($this->fileLoader->load('api.php'));
}

if ($this->graphqlEnabled) {
$graphqlCollection = $this->fileLoader->load('graphql/graphql.xml');
$graphqlCollection = $this->fileLoader->load('graphql/graphql.php');
$graphqlCollection->addDefaults(['_graphql' => true]);
$routeCollection->addCollection($graphqlCollection);
}

if ($this->graphiQlEnabled) {
$graphiQlCollection = $this->fileLoader->load('graphql/graphiql.xml');
$graphiQlCollection = $this->fileLoader->load('graphql/graphiql.php');
$graphiQlCollection->addDefaults(['_graphql' => true]);
$routeCollection->addCollection($graphiQlCollection);
}

if (isset($this->formats['jsonld'])) {
$routeCollection->addCollection($this->fileLoader->load('jsonld.xml'));
$routeCollection->addCollection($this->fileLoader->load('jsonld.php'));
}
}
}
Loading