1 | <?php namespace Limoncello\Flute; |
||
46 | class Factory implements FactoryInterface |
||
47 | { |
||
48 | use HasContainerTrait; |
||
49 | |||
50 | /** |
||
51 | * @var JsonApiFactoryInterface |
||
52 | */ |
||
53 | private $jsonApiFactory = null; |
||
54 | |||
55 | /** |
||
56 | * @param ContainerInterface $container |
||
57 | */ |
||
58 | 95 | public function __construct(ContainerInterface $container) |
|
59 | { |
||
60 | 95 | $this->setContainer($container); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * @return JsonApiFactoryInterface |
||
65 | */ |
||
66 | 55 | public function getJsonApiFactory() |
|
67 | { |
||
68 | 55 | if ($this->jsonApiFactory === null) { |
|
69 | 55 | $this->jsonApiFactory = new JsonApiFactory(); |
|
70 | } |
||
71 | |||
72 | 55 | return $this->jsonApiFactory; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 29 | public function createModelQueryBuilder( |
|
79 | Connection $connection, |
||
80 | string $modelClass, |
||
81 | ModelSchemaInfoInterface $modelSchemas |
||
82 | ): ModelQueryBuilder { |
||
83 | 29 | return new ModelQueryBuilder($connection, $modelClass, $modelSchemas); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param mixed $data |
||
88 | * |
||
89 | * @return PaginatedDataInterface |
||
90 | */ |
||
91 | 16 | public function createPaginatedData($data): PaginatedDataInterface |
|
92 | { |
||
93 | 16 | return new PaginatedData($data); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * @inheritdoc |
||
98 | */ |
||
99 | public function createErrorCollection(): ErrorCollection |
||
100 | { |
||
101 | return new ErrorCollection(); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @inheritdoc |
||
106 | */ |
||
107 | 7 | public function createModelStorage(ModelSchemaInfoInterface $modelSchemas): ModelStorageInterface |
|
108 | { |
||
109 | 7 | return new ModelStorage($modelSchemas); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * @inheritdoc |
||
114 | */ |
||
115 | 7 | public function createTagStorage(): TagStorageInterface |
|
116 | { |
||
117 | 7 | return new TagStorage(); |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | 55 | public function createJsonSchemas( |
|
124 | array $modelToSchemaMap, |
||
125 | array $typeToSchemaMap, |
||
126 | ModelSchemaInfoInterface $modelSchemas |
||
127 | ): JsonSchemasInterface { |
||
128 | 55 | return new JsonSchemas($this->getJsonApiFactory(), $modelToSchemaMap, $typeToSchemaMap, $modelSchemas); |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function createEncoder(JsonSchemasInterface $schemas): EncoderInterface |
||
135 | { |
||
136 | return new Encoder($this->getJsonApiFactory(), $schemas); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @inheritdoc |
||
141 | */ |
||
142 | 1 | public function createApi(string $apiClass): CrudInterface |
|
148 | } |
||
149 |