Skip to content

Commit

Permalink
cfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jun 17, 2024
1 parent af3c642 commit b59a5ab
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ parameters:
# Backward compatibility
- '#Call to method hasCacheableSupportsMethod\(\) on an unknown class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface\.#'
- '#Class Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface not found\.#'
- '#Access to undefined constant Symfony\\Component\\HttpKernel\\HttpKernelInterface::MASTER_REQUEST\.#'
- '#Attribute class PHPUnit\\Framework\\Attributes\\DataProvider does not exist.#'
23 changes: 11 additions & 12 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
use ApiPlatform\Serializer\JsonEncoder;
use ApiPlatform\Serializer\Mapping\Factory\ClassMetadataFactory as SerializerClassMetadataFactory;
use ApiPlatform\Serializer\SerializerContextBuilder;
use ApiPlatform\State\SerializerContextBuilderInterface;
use ApiPlatform\State\CallableProcessor;
use ApiPlatform\State\CallableProvider;
use ApiPlatform\State\Pagination\Pagination;
Expand All @@ -97,6 +96,7 @@
use ApiPlatform\State\Provider\DeserializeProvider;
use ApiPlatform\State\Provider\ReadProvider;
use ApiPlatform\State\ProviderInterface;
use ApiPlatform\State\SerializerContextBuilderInterface;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerInterface;
use Illuminate\Contracts\Foundation\Application;
Expand Down Expand Up @@ -140,7 +140,7 @@ class ApiPlatformProvider extends ServiceProvider
*/
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/config/api-platform.php', 'api-platform');
$this->mergeConfigFrom(__DIR__.'/config/api-platform.php', 'api-platform');

/** @var Repository $config */
$config = $this->app['config'];
Expand Down Expand Up @@ -344,7 +344,7 @@ public function register(): void
$parts = explode('?', $request->server->get('REQUEST_URI'), 2);
$trimmedRequest->server->set(
'REQUEST_URI',
rtrim($parts[0], '/') . (isset($parts[1]) ? '?' . $parts[1] : '')
rtrim($parts[0], '/').(isset($parts[1]) ? '?'.$parts[1] : '')
);

$urlGenerator = new UrlGeneratorRouter($app->make(Router::class));
Expand Down Expand Up @@ -579,7 +579,6 @@ function (Application $app) {
$app->make(Negotiator::class)
);
}

);

// $this->app->afterResolving(
Expand All @@ -595,15 +594,15 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/config/api-platform.php' => $this->app->configPath('api-platform.php'),
__DIR__.'/config/api-platform.php' => $this->app->configPath('api-platform.php'),
], 'laravel-assets');

$this->publishes([
__DIR__ . '/public' => $this->app->publicPath('vendor/api-platform'),
__DIR__.'/public' => $this->app->publicPath('vendor/api-platform'),
], 'laravel-assets');
}

$this->loadViewsFrom(__DIR__ . '/resources/views', 'api-platform');
$this->loadViewsFrom(__DIR__.'/resources/views', 'api-platform');

if (!$this->shouldRegisterRoutes()) {
return;
Expand All @@ -615,31 +614,31 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
foreach ($resourceMetadata->getOperations() as $operation) {
$uriTemplate = $operation->getUriTemplate();
// _format is read by the middleware
$uriTemplate = $operation->getRoutePrefix() . str_replace('{._format}', '{_format?}', $uriTemplate);
$uriTemplate = $operation->getRoutePrefix().str_replace('{._format}', '{_format?}', $uriTemplate);
$route = new Route([$operation->getMethod()], $uriTemplate, [ApiPlatformController::class, '__invoke']);
$route->name($operation->getName());
// Another option then to use a middleware, not sure what's best (you then retrieve $request->getRoute() somehow ?)
// $route->??? = ['operation' => $operation];
$routeCollection->add($route)
->middleware(ApiPlatformMiddleware::class . ':' . $operation->getName());
->middleware(ApiPlatformMiddleware::class.':'.$operation->getName());
}
}
}

$prefix = $this->app['config']->get('api-platform.prefix') ?? '';
$route = new Route(['GET'], $prefix . '/contexts/{shortName?}{_format?}', [ContextAction::class, '__invoke']);
$route = new Route(['GET'], $prefix.'/contexts/{shortName?}{_format?}', [ContextAction::class, '__invoke']);
$route->name('api_jsonld_context')->middleware(ApiPlatformMiddleware::class);
$routeCollection->add($route);
// Maybe that we can alias Symfony Request to Laravel Request within the provider ?
$route = new Route(['GET'], $prefix . '/docs{_format?}', function (Request $request, Application $app) {
$route = new Route(['GET'], $prefix.'/docs{_format?}', function (Request $request, Application $app) {
$documentationAction = $app->make(DocumentationAction::class);

return $documentationAction->__invoke($request);
});
$route->name('api_doc')->middleware(ApiPlatformMiddleware::class);
$routeCollection->add($route);

$route = new Route(['GET'], $prefix . '/{index?}{_format?}', function (Request $request, Application $app) {
$route = new Route(['GET'], $prefix.'/{index?}{_format?}', function (Request $request, Application $app) {
$entrypointAction = $app->make(EntrypointAction::class);

return $entrypointAction->__invoke($request);
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/ApiResource/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Error extends \Exception implements ProblemExceptionInterface, HttpExcepti
{
/**
* @param array<string, string> $headers
* @param array<int, mixed> $originalTrace
* @param array<int, mixed> $originalTrace
*/
public function __construct(
private readonly string $title,
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Controller/ApiPlatformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ApiPlatformController extends Controller
{
/**
* @param ProviderInterface<object> $provider
* @param ProviderInterface<object> $provider
* @param ProcessorInterface<iterable<object>|object|null, Response> $processor
*/
public function __construct(
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/Eloquent/State/RemoveProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RemoveProcessor implements ProcessorInterface
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$data->delete();

return null;
}
}
12 changes: 5 additions & 7 deletions src/Laravel/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
use ApiPlatform\Symfony\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
use ApiPlatform\Validator\Exception\ValidationException;
use Illuminate\Contracts\Container\Container;
use Throwable;
use \Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler as ExceptionsHandler;
use Illuminate\Http\Request;
use Negotiation\Negotiator;
Expand Down Expand Up @@ -207,22 +205,22 @@ public static function provide(): mixed
throw new \LogicException(sprintf('We could not find the thrown exception in the %s.', self::class));
}

public function report(Throwable $e): void
public function report(\Throwable $e): void
{
$this->decorated->report($e);
}

public function shouldReport(Throwable $e): bool
public function shouldReport(\Throwable $e): bool
{
return $this->decorated->shouldReport($e);
}

public function render($request, Throwable $e): Response
public function render($request, \Throwable $e): Response
{
return $this->decorated->render($request, $e);
}

public function renderForConsole($output, Throwable $e): void
public function renderForConsole($output, \Throwable $e): void
{
$this->decorated->renderForConsole($output, $e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function getAttributes(...$args) // @phpstan-ignore-line
* {@inheritdoc}
*
* @param class-string $resourceClass
*
*/
public function create(string $resourceClass, array $options = []): PropertyNameCollection
{
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function getRouteCollection(): RouteCollection
{
/** @var \Illuminate\Routing\RouteCollection $routes */
$routes = $this->router->getRoutes();

return $routes->toSymfonyRouteCollection();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Laravel/State/SwaggerUiProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Laravel\State;

use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\OpenApi\OpenApi;
Expand All @@ -21,10 +22,10 @@
use ApiPlatform\State\ProcessorInterface;
use Illuminate\Http\Response;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use ApiPlatform\Metadata\Exception\RuntimeException;

/**
* @internal
*
* @implements ProcessorInterface<OpenApi, Response>
*/
final class SwaggerUiProcessor implements ProcessorInterface
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/State/SwaggerUiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* When an HTML request is sent we provide a swagger ui documentation.
*
* @internal
*
* @implements ProviderInterface<OpenApi|object>
*/
final class SwaggerUiProvider implements ProviderInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface PropertyMetadataFactoryInterface
* Creates a property metadata.
*
* @param array<string, mixed> $options
* @param class-string|string $resourceClass
* @param class-string|string $resourceClass
*
* @throws PropertyNotFoundException
*/
Expand Down

0 comments on commit b59a5ab

Please sign in to comment.