Skip to content
Open
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
14 changes: 8 additions & 6 deletions EventListener/ParamFetcherListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ private function isParamFetcherType(\ReflectionParameter $controllerParam): bool
{
$type = $controllerParam->getType();
foreach ($type instanceof \ReflectionUnionType ? $type->getTypes() : [$type] as $type) {
if (null === $type || $type->isBuiltin() || !$type instanceof \ReflectionNamedType) {
continue;
}
foreach ($type instanceof \ReflectionIntersectionType ? $type->getTypes() : [$type] as $type) {
if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()) {
continue;
}

$class = new \ReflectionClass($type->getName());
$class = new \ReflectionClass($type->getName());

if ($class->implementsInterface(ParamFetcherInterface::class)) {
return true;
if ($class->implementsInterface(ParamFetcherInterface::class)) {
return true;
}
}
}

Expand Down
20 changes: 19 additions & 1 deletion Tests/EventListener/ParamFetcherListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use FOS\RestBundle\Request\ParamFetcher;
use FOS\RestBundle\Request\ParamReaderInterface;
use FOS\RestBundle\Tests\Fixtures\Controller\ParamFetcherController;
use FOS\RestBundle\Tests\Fixtures\Controller\ParamFetcherDnfTypeController;
use FOS\RestBundle\Tests\Fixtures\Controller\ParamFetcherIntersectionTypeController;
use FOS\RestBundle\Tests\Fixtures\Controller\ParamFetcherUnionTypeController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -141,14 +143,30 @@ public function setParamFetcherByTypehintProvider()
$paramFetcher[] = ['byUnionTypeAction', 'pfu'];
}

if (\PHP_VERSION_ID >= 80100) {
$paramFetcher[] = ['byIntersectionTypeAction', 'pfi'];
}

if (\PHP_VERSION_ID >= 80200) {
$paramFetcher[] = ['byDnfTypeAction', 'pfd'];
}

return $paramFetcher;
}

protected function getEvent(Request $request, $actionMethod = 'byNameAction')
{
$this->requestStack->push($request);

$controller = \PHP_VERSION_ID < 80000 ? new ParamFetcherController() : new ParamFetcherUnionTypeController();
if (\PHP_VERSION_ID >= 80200) {
$controller = new ParamFetcherDnfTypeController();
} elseif (\PHP_VERSION_ID >= 80100) {
$controller = new ParamFetcherIntersectionTypeController();
} elseif (\PHP_VERSION_ID >= 80000) {
$controller = new ParamFetcherUnionTypeController();
} else {
$controller = new ParamFetcherController();
}
$callable = $actionMethod ? [$controller, $actionMethod] : $controller;
$kernel = $this->createMock(HttpKernelInterface::class);

Expand Down
28 changes: 28 additions & 0 deletions Tests/Fixtures/Controller/ParamFetcherDnfTypeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\RestBundle\Tests\Fixtures\Controller;

use FOS\RestBundle\Request\ParamFetcherInterface;

/**
* Fixture for testing whether the ParamFetcher can be injected into
* a disjunctive normal form type-hinted controller method.
*/
class ParamFetcherDnfTypeController extends ParamFetcherIntersectionTypeController
{
/**
* Make sure the ParamFetcher can be injected according to the DNF typehint.
*/
public function byDnfTypeAction((ParamFetcherInterface&ParamFetcherIntersectionTypeMarkerInterface)|null $pfd)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\RestBundle\Tests\Fixtures\Controller;

use FOS\RestBundle\Request\ParamFetcherInterface;

/**
* Fixture for testing whether the ParamFetcher can be injected into
* an intersection type-hinted controller method.
*/
class ParamFetcherIntersectionTypeController extends ParamFetcherUnionTypeController
{
/**
* Make sure the ParamFetcher can be injected according to the intersection typehint.
*/
public function byIntersectionTypeAction(ParamFetcherInterface&ParamFetcherIntersectionTypeMarkerInterface $pfi)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\RestBundle\Tests\Fixtures\Controller;

interface ParamFetcherIntersectionTypeMarkerInterface
{
}
Loading