1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace Spryker\Glue\EntityTagsRestApi\Processor\EntityTag; |
||
9 | |||
10 | use Spryker\Glue\EntityTagsRestApi\Dependency\Client\EntityTagsRestApiToEntityTagClientInterface; |
||
11 | use Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface; |
||
12 | |||
13 | class EntityTagResolver implements EntityTagResolverInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var \Spryker\Glue\EntityTagsRestApi\Processor\EntityTag\EntityTagCheckerInterface |
||
17 | */ |
||
18 | protected $entityTagChecker; |
||
19 | |||
20 | /** |
||
21 | * @var \Spryker\Glue\EntityTagsRestApi\Dependency\Client\EntityTagsRestApiToEntityTagClientInterface |
||
22 | */ |
||
23 | protected $entityTagClient; |
||
24 | |||
25 | /** |
||
26 | * @param \Spryker\Glue\EntityTagsRestApi\Processor\EntityTag\EntityTagCheckerInterface $entityTagChecker |
||
27 | * @param \Spryker\Glue\EntityTagsRestApi\Dependency\Client\EntityTagsRestApiToEntityTagClientInterface $entityTagClient |
||
28 | */ |
||
29 | public function __construct( |
||
30 | EntityTagCheckerInterface $entityTagChecker, |
||
31 | EntityTagsRestApiToEntityTagClientInterface $entityTagClient |
||
32 | ) { |
||
33 | $this->entityTagChecker = $entityTagChecker; |
||
34 | $this->entityTagClient = $entityTagClient; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface $restResource |
||
39 | * |
||
40 | * @return string|null |
||
41 | */ |
||
42 | public function resolve(RestResourceInterface $restResource): ?string |
||
43 | { |
||
44 | $entityTag = $this->entityTagClient->read($restResource->getType(), $restResource->getId()); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
45 | |||
46 | if ($entityTag) { |
||
47 | return $entityTag; |
||
48 | } |
||
49 | |||
50 | return $this->entityTagClient->write( |
||
51 | $restResource->getType(), |
||
52 | $restResource->getId(), |
||
53 | $restResource->getAttributes()->toArray(), |
||
54 | ); |
||
55 | } |
||
56 | } |
||
57 |