Skip to content

Commit 9544bef

Browse files
author
darylholling
authored
Merge pull request #9 from webstacknl/feat/version-3
feat: initial setup for version 3 using apiplatform 3.0, symfony 6.2 and php 8.1
2 parents 8becbe8 + cd1950d commit 9544bef

File tree

10 files changed

+198
-238
lines changed

10 files changed

+198
-238
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.4|^8.0",
15-
"api-platform/core": "^2.6",
14+
"php": "^8.1",
15+
"api-platform/core": "^3.0",
1616
"doctrine/orm": "^2.11",
1717
"ramsey/uuid-doctrine": "^1.8",
18-
"symfony/security-bundle": "^5.4|^6.0",
19-
"symfony/serializer": "^5.4|^6.0"
18+
"symfony/security-bundle": "^6.2",
19+
"symfony/serializer": "^6.2"
2020
},
2121
"require-dev": {
22-
"friendsofphp/php-cs-fixer": "^3.5",
22+
"friendsofphp/php-cs-fixer": "^3.14",
2323
"phpstan/extension-installer": "^1.1",
2424
"phpstan/phpstan": "^1.2",
2525
"phpstan/phpstan-doctrine": "^1.0",

src/DependencyInjection/WebstackApiPlatformExtensionsExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Webstack\ApiPlatformExtensionsBundle\DependencyInjection;
66

7-
use Exception;
87
use Symfony\Component\Config\FileLocator;
98
use Symfony\Component\DependencyInjection\ContainerBuilder;
109
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -13,7 +12,7 @@
1312
class WebstackApiPlatformExtensionsExtension extends Extension
1413
{
1514
/**
16-
* @throws Exception
15+
* @throws \Exception
1716
*/
1817
public function load(array $configs, ContainerBuilder $container): void
1918
{

src/EventListener/MeListener.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44

55
namespace Webstack\ApiPlatformExtensionsBundle\EventListener;
66

7-
use ApiPlatform\Core\Api\FormatMatcher;
8-
use ApiPlatform\Core\Util\ClassInfoTrait;
7+
use ApiPlatform\Api\FormatMatcher;
8+
use ApiPlatform\Util\ClassInfoTrait;
99
use Doctrine\ORM\EntityManagerInterface;
1010
use Doctrine\ORM\NonUniqueResultException;
1111
use Doctrine\ORM\NoResultException;
1212
use Doctrine\ORM\Query\ResultSetMappingBuilder;
1313
use Negotiation\Exception\Exception as NeogationException;
1414
use Negotiation\Negotiator;
15-
use ReflectionClass;
16-
use ReflectionException;
17-
use RuntimeException;
15+
use Symfony\Bundle\SecurityBundle\Security;
1816
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1917
use Symfony\Component\HttpFoundation\Request;
2018
use Symfony\Component\HttpKernel\Event\RequestEvent;
2119
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
2220
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
23-
use Symfony\Component\Security\Core\Security;
2421
use Symfony\Component\Security\Core\User\UserInterface;
2522
use Webstack\ApiPlatformExtensionsBundle\Util\MimeType\MimeTypeFlattener;
2623

@@ -44,7 +41,7 @@ public function __construct(Security $security, EntityManagerInterface $entityMa
4441
}
4542

4643
/**
47-
* @throws ReflectionException
44+
* @throws \ReflectionException
4845
* @throws NonUniqueResultException
4946
* @throws NoResultException
5047
* @throws NeogationException
@@ -57,21 +54,24 @@ public function onKernelRequest(RequestEvent $event): void
5754
return;
5855
}
5956

60-
if (null === $this->security->getToken()) {
57+
if (!$this->security->getToken() instanceof TokenInterface) {
6158
return;
6259
}
6360

6461
$user = $this->security->getToken()->getUser();
6562

63+
if (!$user instanceof UserInterface) {
64+
return;
65+
}
66+
6667
// League returns a NullUser instance when a non-user (e.g. client_credentials) is authenticated.
6768
$class = get_class($user);
68-
$isUser = $user instanceof UserInterface && $class !== 'League\Bundle\OAuth2ServerBundle\Security\User\NullUser';
6969

70-
if ($isUser) {
71-
if (method_exists($class, 'getId')) {
70+
if ('League\Bundle\OAuth2ServerBundle\Security\User\NullUser' !== $class) {
71+
if (method_exists($user, 'getId')) {
7272
$id = $user->getId();
7373
} else {
74-
throw new RuntimeException(sprintf('Could not determine the user id, class "%s" must have a getId() method', $class));
74+
throw new \RuntimeException(sprintf('Could not determine the user id, class "%s" must have a getId() method', $class));
7575
}
7676
} else {
7777
$subject = $this->getSubject($this->security->getToken());
@@ -91,7 +91,7 @@ public function onKernelRequest(RequestEvent $event): void
9191
}
9292

9393
/**
94-
* @throws ReflectionException
94+
* @throws \ReflectionException
9595
* @throws NoResultException
9696
* @throws NonUniqueResultException
9797
*/
@@ -102,7 +102,7 @@ public function getSubject(TokenInterface $token): object
102102
$rsm = new ResultSetMappingBuilder($this->entityManager);
103103
$rsm->addRootEntityFromClassMetadata($class, 'subject');
104104

105-
$reflectionClass = new ReflectionClass($class);
105+
$reflectionClass = new \ReflectionClass($class);
106106
$class = strtolower($reflectionClass->getShortName());
107107

108108
$query = $this->entityManager->createNativeQuery(sprintf('

src/Filter/AbstractOrFilter.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Filter/AliasSearchFilter.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)