Skip to content

Commit 93d1394

Browse files
committed
CS fix
1 parent b5ac4c1 commit 93d1394

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/ApiPlatform/Metadata/Resource/RoutableResourceMetadataCollectionFactory.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RoutableResourceMetadataCollectionFactory implements ResourceMetadataColle
2828
{
2929
private ResourceMetadataCollectionFactoryInterface $decorated;
3030

31-
public function __construct(ResourceMetadataCollectionFactoryInterface $decorated)
31+
public function __construct(ResourceMetadataCollectionFactoryInterface $decorated, private readonly ?string $securityStr = null)
3232
{
3333
$this->decorated = $decorated;
3434
}
@@ -50,12 +50,23 @@ public function create(string $resourceClass): ResourceMetadataCollection
5050
if ($operations) {
5151
/** @var Operation $operation */
5252
foreach ($operations as $i => $operation) {
53-
if (
54-
HttpOperation::METHOD_POST !== $operation->getMethod()
55-
&& !$operation instanceof CollectionOperationInterface
56-
&& !$operation->getSecurity()) {
53+
if ($operation->getSecurity()) {
54+
$newOperations[$i] = $operation;
55+
continue;
56+
}
57+
58+
if (HttpOperation::METHOD_POST === $operation->getMethod()) {
59+
// POST (creation) — apply securityStr directly since the voter cannot
60+
// check the subject pre-denormalize. No restriction if securityStr is null.
61+
if ($this->securityStr) {
62+
$operation = $operation->withSecurity($this->securityStr);
63+
}
64+
} elseif (!$operation instanceof CollectionOperationInterface) {
65+
// Item operations (GET, PATCH, DELETE, PUT) — delegate to the routable voter
66+
// which checks the route or falls back to securityStr.
5767
$operation = $operation->withSecurity(\sprintf("is_granted('%s', object)", AbstractRoutableVoter::READ_ROUTABLE));
5868
}
69+
5970
$newOperations[$i] = $operation;
6071
}
6172
}

src/DependencyInjection/SilverbackApiComponentsExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Silverback\ApiComponentsBundle\DependencyInjection;
1313

1414
use Ramsey\Uuid\Doctrine\UuidType;
15+
use Silverback\ApiComponentsBundle\ApiPlatform\Metadata\Resource\RoutableResourceMetadataCollectionFactory;
1516
use Silverback\ApiComponentsBundle\AttributeReader\UploadableAttributeReader;
1617
use Silverback\ApiComponentsBundle\Doctrine\Extension\ORM\RoutableExtension;
1718
use Silverback\ApiComponentsBundle\Doctrine\Extension\ORM\RouteExtension;
@@ -155,6 +156,9 @@ public function load(array $configs, ContainerBuilder $container): void
155156
$definition = $container->getDefinition(RoutableVoter::class);
156157
$definition->setArgument('$securityStr', $config['routable_security']);
157158

159+
$definition = $container->getDefinition(RoutableResourceMetadataCollectionFactory::class);
160+
$definition->setArgument('$securityStr', $config['routable_security']);
161+
158162
$definition = $container->getDefinition(MercureAuthorization::class);
159163
$definition->setArgument('$cookieSameSite', $config['mercure']['cookie']['samesite']);
160164
$definition->setArgument('$hubName', $config['mercure']['hub_name']);

src/Serializer/Normalizer/ComponentGroupNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
*/
3636
class ComponentGroupNormalizer implements NormalizerInterface, NormalizerAwareInterface, DenormalizerInterface, DenormalizerAwareInterface
3737
{
38-
use NormalizerAwareTrait;
3938
use DenormalizerAwareTrait;
39+
use NormalizerAwareTrait;
4040

4141
private const ALREADY_CALLED = 'COMPONENT_GROUP_NORMALIZER_ALREADY_CALLED';
4242

@@ -99,6 +99,7 @@ function (string $value): string {
9999
if (!str_contains($value, '\\')) {
100100
return $value;
101101
}
102+
102103
return $this->iriConverter->getIriFromResource(
103104
$value,
104105
UrlGeneratorInterface::ABS_PATH,

0 commit comments

Comments
 (0)