Skip to content

Commit e1f92d0

Browse files
authored
Merge pull request #2289 from Toflar/use-security-expression-language
Use framework expression language service instead of custom one
2 parents bf1cb5e + 22d350d commit e1f92d0

File tree

24 files changed

+78
-35
lines changed

24 files changed

+78
-35
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
4848
"phpdocumentor/type-resolver": "^0.3 || ^0.4",
4949
"phpspec/prophecy": "^1.8",
50-
"phpunit/phpunit": "^7.5.2",
50+
"phpunit/phpunit": "^7.5.4",
5151
"psr/log": "^1.0",
5252
"ramsey/uuid": "^3.7",
5353
"ramsey/uuid-doctrine": "^1.4",

src/Api/FormatsProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function getOperationFormats(array $annotationFormats): array
9292
if (!\is_string($value)) {
9393
throw new InvalidArgumentException(sprintf("The 'formats' attributes value must be a string when trying to include an already configured format, %s given.", \gettype($value)));
9494
}
95-
if (array_key_exists($value, $this->configuredFormats)) {
95+
if (\array_key_exists($value, $this->configuredFormats)) {
9696
$resourceFormats[$value] = $this->configuredFormats[$value];
9797
continue;
9898
}

src/Bridge/Doctrine/MongoDbOdm/Filter/AbstractFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ protected function isPropertyEnabled(string $property, string $resourceClass): b
8585
return !$this->isPropertyNested($property, $resourceClass);
8686
}
8787

88-
return array_key_exists($property, $this->properties);
88+
return \array_key_exists($property, $this->properties);
8989
}
9090
}

src/Bridge/Doctrine/MongoDbOdm/Paginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function count(): int
136136
private function getFacetInfo(string $field): array
137137
{
138138
foreach ($this->pipeline as $indexStage => $infoStage) {
139-
if (array_key_exists('$facet', $infoStage)) {
139+
if (\array_key_exists('$facet', $infoStage)) {
140140
if (!isset($this->pipeline[$indexStage]['$facet'][$field])) {
141141
throw new InvalidArgumentException("\"$field\" facet was not applied to the aggregation pipeline.");
142142
}

src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
252252
}
253253

254254
// If it's an embedded property see below
255-
if (!array_key_exists($property, $targetClassMetadata->embeddedClasses)) {
255+
if (!\array_key_exists($property, $targetClassMetadata->embeddedClasses)) {
256256
//the field test allows to add methods to a Resource which do not reflect real database fields
257257
if ($targetClassMetadata->hasField($property) && (true === $propertyMetadata->getAttribute('fetchable') || $propertyMetadata->isReadable())) {
258258
$select[] = $property;

src/Bridge/Doctrine/Orm/Extension/PaginationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct(ManagerRegistry $managerRegistry, /* ResourceMetadat
8181
];
8282

8383
foreach ($legacyPaginationArgs as $pos => $arg) {
84-
if (array_key_exists($pos, $args)) {
84+
if (\array_key_exists($pos, $args)) {
8585
@trigger_error(sprintf('Passing "$%s" arguments is deprecated since API Platform 2.4 and will not be possible anymore in API Platform 3. Pass an instance of "%s" as third argument instead.', implode('", "$', array_column($legacyPaginationArgs, 'arg_name')), Paginator::class), E_USER_DEPRECATED);
8686

8787
if (!((null === $arg['default'] && null === $args[$pos]) || \call_user_func("is_{$arg['type']}", $args[$pos]))) {
@@ -261,7 +261,7 @@ private function isPaginationEnabled(Request $request, ResourceMetadata $resourc
261261
private function getPaginationParameter(Request $request, string $parameterName, $default = null)
262262
{
263263
if (null !== $paginationAttribute = $request->attributes->get('_api_pagination')) {
264-
return array_key_exists($parameterName, $paginationAttribute) ? $paginationAttribute[$parameterName] : $default;
264+
return \array_key_exists($parameterName, $paginationAttribute) ? $paginationAttribute[$parameterName] : $default;
265265
}
266266

267267
return $request->query->get($parameterName, $default);

src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function isPropertyEnabled(string $property/*, string $resourceClass*/
115115
return !$this->isPropertyNested($property, $resourceClass);
116116
}
117117

118-
return array_key_exists($property, $this->properties);
118+
return \array_key_exists($property, $this->properties);
119119
}
120120

121121
/**

src/Bridge/Elasticsearch/DataProvider/Paginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getIterator(): \Traversable
9999
foreach ($this->documents['hits']['hits'] ?? [] as $document) {
100100
$cacheKey = isset($document['_index'], $document['_type'], $document['_id']) ? md5("${document['_index']}_${document['_type']}_${document['_id']}") : null;
101101

102-
if ($cacheKey && array_key_exists($cacheKey, $this->cachedDenormalizedDocuments)) {
102+
if ($cacheKey && \array_key_exists($cacheKey, $this->cachedDenormalizedDocuments)) {
103103
$object = $this->cachedDenormalizedDocuments[$cacheKey];
104104
} else {
105105
$object = $this->denormalizer->denormalize(

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use Symfony\Component\DependencyInjection\ContainerBuilder;
3939
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
4040
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
41-
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
4241
use Symfony\Component\Finder\Finder;
4342
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
4443
use Symfony\Component\Messenger\MessageBusInterface;
@@ -120,9 +119,6 @@ public function load(array $configs, ContainerBuilder $container)
120119

121120
$bundles = $container->getParameter('kernel.bundles');
122121
if (isset($bundles['SecurityBundle'])) {
123-
if (class_exists(ExpressionLanguage::class)) {
124-
$loader->load('security_expression_language.xml');
125-
}
126122
$loader->load('security.xml');
127123
}
128124

src/Bridge/Symfony/Bundle/Resources/config/security.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8+
<service id="api_platform.security.expression_language" alias="security.expression_language" />
9+
810
<service id="api_platform.security.resource_access_checker" class="ApiPlatform\Core\Security\ResourceAccessChecker" public="false">
911
<argument type="service" id="api_platform.security.expression_language" on-invalid="null" />
1012
<argument type="service" id="security.authentication.trust_resolver" on-invalid="null" />
@@ -21,6 +23,10 @@
2123
<!-- This listener must be executed only when the current object is available -->
2224
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="1" />
2325
</service>
26+
27+
<service id="api_platform.security.expression_language_provider" class="ApiPlatform\Core\Security\Core\Authorization\ExpressionLanguageProvider" public="false">
28+
<tag name="security.expression_language_provider" />
29+
</service>
2430
</services>
2531

2632
</container>

0 commit comments

Comments
 (0)