1
|
|
|
<?php namespace Neomerx\JsonApi\Schema; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2018 [email protected] |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; |
20
|
|
|
use Neomerx\JsonApi\Contracts\Schema\ContainerInterface; |
21
|
|
|
use Neomerx\JsonApi\Contracts\Schema\SchemaInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package Neomerx\JsonApi |
25
|
|
|
*/ |
26
|
|
|
class ResourceIdentifierContainerAdapter implements ContainerInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ContainerInterface |
30
|
|
|
*/ |
31
|
|
|
private $container; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var FactoryInterface |
35
|
|
|
*/ |
36
|
|
|
private $factory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* ResourceIdentifierContainerAdapter constructor. |
40
|
|
|
* |
41
|
|
|
* @param FactoryInterface $factory |
42
|
|
|
* @param ContainerInterface $container |
43
|
|
|
*/ |
44
|
4 |
|
public function __construct(FactoryInterface $factory, ContainerInterface $container) |
45
|
|
|
{ |
46
|
4 |
|
$this->container = $container; |
47
|
4 |
|
$this->factory = $factory; |
48
|
4 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
4 |
|
public function getSchema($resourceObject): SchemaInterface |
54
|
|
|
{ |
55
|
4 |
|
return $this->getSchemaAdapter($this->container->getSchema($resourceObject)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
3 |
|
public function hasSchema($resourceObject): bool |
62
|
|
|
{ |
63
|
3 |
|
return $this->container->hasSchema($resourceObject); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
1 |
|
public function getSchemaByType(string $type): SchemaInterface |
70
|
|
|
{ |
71
|
1 |
|
return $this->getSchemaAdapter($this->container->getSchemaByType($type)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
*/ |
77
|
4 |
|
public function getSchemaByResourceType(string $resourceType): SchemaInterface |
78
|
|
|
{ |
79
|
4 |
|
return $this->getSchemaAdapter($this->container->getSchemaByResourceType($resourceType)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param SchemaInterface $schema |
84
|
|
|
* |
85
|
|
|
* @return SchemaInterface |
86
|
|
|
*/ |
87
|
4 |
|
protected function getSchemaAdapter(SchemaInterface $schema): SchemaInterface |
88
|
|
|
{ |
89
|
4 |
|
return $this->factory->createResourceIdentifierSchemaAdapter($schema); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|