1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\ApiPlatform\Metadata\Resource; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
17
|
|
|
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; |
18
|
|
|
use Silverback\ApiComponentsBundle\Annotation\Publishable; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This will add an endpoint for component resources to find out usage totals. |
22
|
|
|
* |
23
|
|
|
* @author Daniel West <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class MercureResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface |
26
|
|
|
{ |
27
|
|
|
private ResourceMetadataCollectionFactoryInterface $decorated; |
28
|
|
|
|
29
|
|
|
public function __construct(ResourceMetadataCollectionFactoryInterface $decorated) |
30
|
|
|
{ |
31
|
|
|
$this->decorated = $decorated; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function create(string $resourceClass): ResourceMetadataCollection |
35
|
|
|
{ |
36
|
|
|
return $this->decorated->create($resourceClass); |
37
|
|
|
// |
38
|
|
|
// $refl = new \ReflectionClass($resourceClass); |
39
|
|
|
// $isPublishable = \count($refl->getAttributes(Publishable::class)); |
40
|
|
|
// |
41
|
|
|
// if (!$isPublishable) { |
42
|
|
|
// return $resourceMetadataCollection; |
43
|
|
|
// } |
44
|
|
|
// |
45
|
|
|
// foreach ($resourceMetadataCollection as $key => $resourceMetadata) { |
46
|
|
|
// // Do not override if it's an array |
47
|
|
|
// if (true === $resourceMetadata->getMercure()) { |
48
|
|
|
// $resourceMetadata = $resourceMetadata->withMercure(['private' => true]); |
49
|
|
|
// } |
50
|
|
|
// |
51
|
|
|
// $operations = $resourceMetadata->getOperations(); |
52
|
|
|
// foreach ($operations as $operationName => $operation) { |
53
|
|
|
// $operations->add($operationName, $operation->withMercure($resourceMetadata->getMercure())); |
54
|
|
|
// } |
55
|
|
|
// |
56
|
|
|
// $resourceMetadataCollection[$key] = $resourceMetadata->withOperations($operations); |
57
|
|
|
// } |
58
|
|
|
// |
59
|
|
|
// return $resourceMetadataCollection; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|