1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[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 ApiPlatform\Core\Serializer; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Exception\RuntimeException; |
17
|
|
|
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; |
18
|
|
|
use ApiPlatform\Core\Util\RequestAttributesExtractor; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
* |
24
|
|
|
* @author Kévin Dunglas <[email protected]> |
25
|
|
|
* |
26
|
|
|
* @deprecated since API Platform 2.6, use {@see \ApiPlatform\Core\Serializer\SerializerContextProvider} class instead |
27
|
|
|
*/ |
28
|
|
|
final class SerializerContextBuilder implements SerializerContextBuilderInterface |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
use ContextTrait; |
|
|
|
|
31
|
|
|
|
32
|
|
|
private $serializerContextProvider; |
33
|
|
|
|
34
|
|
|
public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, SerializerContextProviderInterface $serializerContextProvider = null) |
35
|
|
|
{ |
36
|
|
|
trigger_deprecation('API Platform', '2.6', 'Using "%s" class is deprecated, use "%s" class instead.', __CLASS__, SerializerContextProvider::class); |
37
|
|
|
|
38
|
|
|
$this->serializerContextProvider = $serializerContextProvider ?? new SerializerContextProvider($resourceMetadataFactory); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function createFromRequest(Request $request, bool $normalization, array $attributes = null): array |
45
|
|
|
{ |
46
|
|
|
trigger_deprecation('API Platform', '2.6', 'Using "%s()" method is deprecated, use "%s::create()" method instead.', __METHOD__, SerializerContextProvider::class); |
47
|
|
|
|
48
|
|
|
if (null === $attributes && !$attributes = RequestAttributesExtractor::extractAttributes($request)) { |
49
|
|
|
throw new RuntimeException('Request attributes are not valid.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$context = $this->addRequestContext($request, $attributes); |
53
|
|
|
$operationName = $this->getOperationNameFromContext($context); |
54
|
|
|
|
55
|
|
|
return $this->serializerContextProvider->create($context['resource_class'], $operationName, $normalization, $context); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.