8000 [Refactor] Initial work on upgrading neomerx dependency · CaptainVet/laravel-json-api@4f710e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f710e6

Browse files
committed
[Refactor] Initial work on upgrading neomerx dependency
1 parent bb4afc3 commit 4f710e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1318
-182
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"require": {
2525
"php": "^7.4|^8.0",
2626
"ext-json": "*",
27-
"laravel-json-api/neomerx-json-api": "^1.1",
27+
"laravel-json-api/neomerx-json-api": "^5.0",
2828
"laravel/framework": "^8.76|^9.0",
2929
"nyholm/psr7": "^1.2",
3030
"ramsey/uuid": "^3.0|^4.0",

src/Adapter/AbstractRelationshipAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
namespace CloudCreativity\LaravelJsonApi\Adapter;
1919

2020
use CloudCreativity\LaravelJsonApi\Contracts\Adapter\RelationshipAdapterInterface;
21+
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
2122
use CloudCreativity\LaravelJsonApi\Contracts\Store\StoreAwareInterface;
2223
use CloudCreativity\LaravelJsonApi\Store\StoreAwareTrait;
23-
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
2424

2525
/**
2626
* Class AbstractRelationshipAdapter

src/Adapter/AbstractResourceAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use CloudCreativity\LaravelJsonApi\Codec\ChecksMediaTypes;
2222
use CloudCreativity\LaravelJsonApi\Contracts\Adapter\RelationshipAdapterInterface;
2323
use CloudCreativity\LaravelJsonApi\Contracts\Adapter\ResourceAdapterInterface;
24+
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
2425
use CloudCreativity\LaravelJsonApi\Contracts\Queue\AsynchronousProcess;
2526
use CloudCreativity\LaravelJsonApi\Contracts\Store\StoreAwareInterface;
2627
use CloudCreativity\LaravelJsonApi\Document\ResourceObject;
@@ -29,7 +30,6 @@
2930
use CloudCreativity\LaravelJsonApi\Utils\InvokesHooks;
3031
use CloudCreativity\LaravelJsonApi\Utils\Str;
3132
use Illuminate\Support\Collection;
32-
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
3333

3434
/**
3535
* Class AbstractResourceAdaptor

src/Adapter/Concerns/FindsManyResources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use Illuminate\Support\Collection;
2121
use InvalidArgumentException;
22-
use Neomerx\JsonApi\Contracts\Document\DocumentInterface;
22+
use Neomerx\JsonApi\Contracts\Schema\DocumentInterface;
2323
use function is_array;
2424
use function is_string;
2525

src/Api/Api.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
use CloudCreativity\LaravelJsonApi\Contracts\Exceptions\ExceptionParserInterface;
2828
use CloudCreativity\LaravelJsonApi\Contracts\Resolver\ResolverInterface;
2929
use CloudCreativity\LaravelJsonApi\Contracts\Store\StoreInterface;
30+
use CloudCreativity\LaravelJsonApi\Encoder\EncoderOptions;
3031
use CloudCreativity\LaravelJsonApi\Factories\Factory;
3132
use CloudCreativity\LaravelJsonApi\Http\Responses\Responses;
3233
use CloudCreativity\LaravelJsonApi\Resolver\AggregateResolver;
3334
use CloudCreativity\LaravelJsonApi\Resolver\NamespaceResolver;
3435
use GuzzleHttp\Client;
3536
use Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface;
36-
use Neomerx\JsonApi\Contracts\Http\Headers\SupportedExtensionsInterface;
37-
use Neomerx\JsonApi\Encoder\EncoderOptions;
3837

3938
/**
4039
* Class Api
@@ -212,18 +211,6 @@ public function getStore()
212211
return $this->store;
213212
}
214213

215-
/**
216-
* @return SupportedExtensionsInterface|null
217-
*/
218-
public function getSupportedExtensions()
219-
{
220-
if ($ext = $this->config->supportedExt()) {
221-
return $this->factory->createSupportedExtensions($ext);
222-
}
223-
224-
return null;
225-
}
226-
227214
/**
228215
* @return EncodingList
229216
*/
@@ -333,7 +320,9 @@ public function encoder($options = 0, $depth = 512)
333320
$options = new EncoderOptions($options, $this->getUrl()->toString(), $depth);
334321
}
335322

336-
return $this->factory->createEncoder($this->getContainer(), $options);
323+
return $this->factory
324+
->createExtendedEncoder($this->getContainer())
325+
->withEncoderOptions($options);
337326
}
338327

339328
/**

src/Api/LinkGenerator.php

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
namespace CloudCreativity\LaravelJsonApi\Api;
2020

2121
use Illuminate\Contracts\Routing\UrlGenerator as IlluminateUrlGenerator;
22-
use Neomerx\JsonApi\Contracts\Document\LinkInterface;
23-
use Neomerx\JsonApi\Contracts\Schema\SchemaFactoryInterface;
22+
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
23+
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
2424

2525
/**
2626
* Class LinkGenerator
@@ -31,28 +31,28 @@ class LinkGenerator
3131
{
3232

3333
/**
34-
* @var SchemaFactoryInterface
34+
* @var FactoryInterface
3535
*/
36-
private $factory;
36+
private FactoryInterface $factory;
3737

3838
/**
3939
* @var UrlGenerator
4040
*/
41-
private $urls;
41+
private UrlGenerator $urls;
4242

4343
/**
4444
* @var IlluminateUrlGenerator
4545
*/
46-
private $generator;
46+
private IlluminateUrlGenerator $generator;
4747

4848
/**
4949
* LinkGenerator constructor.
5050
*
51-
* @param SchemaFactoryInterface $factory
51+
* @param FactoryInterface $factory
5252
* @param UrlGenerator $urls
5353
* @param IlluminateUrlGenerator $generator
5454
*/
55-
public function __construct(SchemaFactoryInterface $factory, UrlGenerator $urls, IlluminateUrlGenerator $generator)
55+
public function __construct(FactoryInterface $factory, UrlGenerator $urls, IlluminateUrlGenerator $generator)
5656
{
5757
$this->factory = $factory;
5858
$this->urls = $urls;
@@ -74,7 +74,7 @@ public function current($meta = null, array $queryParams = [])
7474
$url .= '?' . http_build_query($queryParams);
7575
}
7676

77-
return $this->factory->createLink($url, $meta, true);
77+
return $this->createLink($url, $meta, true);
7878
}
7979

8080
/**
@@ -87,7 +87,7 @@ public function current($meta = null, array $queryParams = [])
8787
*/
8888
public function index($resourceType, $meta = null, array $queryParams = [])
8989
{
90-
return $this->factory->createLink(
90+
return $this->createLink(
9191
$this->urls->index($resourceType, $queryParams),
9292
$meta,
9393
true< 10000 /span>
@@ -104,7 +104,7 @@ public function index($resourceType, $meta = null, array $queryParams = [])
104104
*/
105105
public function create($resourceType, $meta = null, array $queryParams = [])
106106
{
107-
return $this->factory->createLink(
107+
return $this->createLink(
108108
$this->urls->create($resourceType, $queryParams),
109109
$meta,
110110
true
@@ -122,7 +122,7 @@ public function create($resourceType, $meta = null, array $queryParams = [])
122122
*/
123123
public function read($resourceType, $id, $meta = null, array $queryParams = [])
124124
{
125-
return $this->factory->createLink(
125+
return $this->createLink(
126126
$this->urls->read($resourceType, $id, $queryParams),
127127
$meta,
128128
true
@@ -140,7 +140,7 @@ public function read($resourceType, $id, $meta = null, array $queryParams = [])
140140
*/
141141
public function update($resourceType, $id, $meta = null, array $queryParams = [])
142142
{
143-
return $this->factory->createLink(
143+
return $this->createLink(
144144
$this->urls->update($resourceType, $id, $queryParams),
145145
$meta,
146146
true
@@ -158,7 +158,7 @@ public function update($resourceType, $id, $meta = null, array $queryParams = []
158158
*/
159159
public function delete($resourceType, $id, $meta = null, array $queryParams = [])
160160
{
161-
return $this->factory->createLink(
161+
return $this->createLink(
162162
$this->urls->delete($resourceType, $id, $queryParams),
163163
$meta,
164164
true
@@ -177,7 +177,7 @@ public function delete($resourceType, $id, $meta = null, array $queryParams = []
177177
*/
178178
public function relatedResource($resourceType, $id, $relationshipKey, $meta = null, array $queryParams = [])
179179
{
180-
return $this->factory->createLink(
180+
return $this->createLink(
181181
$this->urls->relatedResource($resourceType, $id, $relationshipKey, $queryParams),
182182
$meta,
183183
true
@@ -196,7 +196,7 @@ public function relatedResource($resourceType, $id, $relationshipKey, $meta = nu
196196
*/
197197
public function readRelationship($resourceType, $id, $relationshipKey, $meta = null, array $queryParams = [])
198198
{
199-
return $this->factory->createLink(
199+
return $this->createLink(
200200
$this->urls->readRelationship($resourceType, $id, $relationshipKey, $queryParams),
201201
$meta,
202202
true
@@ -215,7 +215,7 @@ public function readRelationship($resourceType, $id, $relationshipKey, $meta = n
215215
*/
216216
public function replaceRelationship($resourceType, $id, $relationshipKey, $meta = null, array $queryParams = [])
217217
{
218-
return $this->factory->createLink(
218+
return $this->createLink(
219219
$this->urls->replaceRelationship($resourceType, $id, $relationshipKey, $queryParams),
220220
$meta,
221221
true
@@ -234,7 +234,7 @@ public function replaceRelationship($resourceType, $id, $relationshipKey, $meta
234234
*/
235235
public function addRelationship($resourceType, $id, $relationshipKey, $meta = null, array $queryParams = [])
236236
{
237-
return $this->factory->createLink(
237+
return $this->createLink(
238238
$this->urls->addRelationship($resourceType, $id, $relationshipKey, $queryParams),
239239
$meta,
240240
true
@@ -249,15 +249,35 @@ public function addRelationship($resourceType, $id, $relationshipKey, $meta = nu
249249
* @param $relationshipKey
250250
* @param array|object|null $meta
251251
* @param array $queryParams
252-
* @return string
252+
* @return LinkInterface
253253
*/
254254
public function removeRelationship($resourceType, $id, $relationshipKey, $meta = null, array $queryParams = [])
255255
{
256-
return $this->factory->createLink(
256+
return $this->createLink(
257257
$this->urls->removeRelationship($resourceType, $id, $relationshipKey, $queryParams),
258258
$meta,
259259
true
260260
);
261261
}
262262

263+
/**
264+
* Create a link.
265+
*
266+
* This method uses the old method signature for creating a link via the Neomerx factory, and converts
267+
* it to a call to the new factory method signature.
268+
*
269+
* @param string $subHref
270+
* @param array|object|null $meta
271+
* @param bool $treatAsHref
272+
* @return LinkInterface
273+
*/
274+
private function createLink(string $subHref, $meta = null, bool $treatAsHref = false): LinkInterface
275+
{
276+
return $this->factory->createLink(
277+
false === $treatAsHref,
278+
$subHref,
279+
!is_null($meta),
280+
$meta,
281+
);
282+
}
263283
}

src/Broadcasting/BroadcastsData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace CloudCreativity\LaravelJsonApi\Broadcasting;
2020

2121
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\SerializerInterface;
22-
use Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;
22+
use CloudCreativity\LaravelJsonApi\Encoder\Parameters\EncodingParameters;
2323

2424
/**
2525
* Trait BroadcastsData

src/Client/AbstractClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
use CloudCreativity\LaravelJsonApi\Contracts\Client\ClientInterface;
2121
use CloudCreativity\LaravelJsonApi\Encoder\Parameters\EncodingParameters;
2222
use CloudCreativity\LaravelJsonApi\Exceptions\ClientException;
23-
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
24-
use Neomerx\JsonApi\Contracts\Schema\ContainerInterface;
23+
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
24+
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
2525
use Neomerx\JsonApi\Http\Headers\MediaType;
2626
use Psr\Http\Message\ResponseInterface;
2727

@@ -34,9 +34,9 @@ abstract class AbstractClient implements ClientInterface
3434
{
3535

3636
/**
37-
* @var ContainerInterface
37+
* @var SchemaContainerInterface
3838
*/
39-
protected $schemas;
39+
protected SchemaContainerInterface $schemas;
4040

4141
/**
4242
* @var ClientSerializer
@@ -79,10 +79,10 @@ abstract protected function request(
7979
/**
8080
* AbstractClient constructor.
8181
*
82-
* @param ContainerInterface $schemas
82+
* @param SchemaContainerInterface $schemas
8383
* @param ClientSerializer $serializer
8484
*/
85-
public function __construct(ContainerInterface $schemas, ClientSerializer $serializer)
85+
public function __construct(SchemaContainerInterface $schemas, ClientSerializer $serializer)
8686
{
8787
$this->schemas = $schemas;
8888
$this->serializer = $serializer;
@@ -406,7 +406,7 @@ protected function resourceIdentifier($record)
406406
{
407407
$schema = $this->schemas->getSchema($record);
408408

409-
return [$schema->getResourceType(), $schema->getId($record)];
409+
return [$schema->getType(), $schema->getId($record)];
410410
}
411411

412412
/**

src/Client/ClientSerializer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
namespace CloudCreativity\LaravelJsonApi\Client;
1919

20+
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
2021
use CloudCreativity\LaravelJsonApi\Contracts\Encoder\SerializerInterface;
22+
use CloudCreativity\LaravelJsonApi\Factories\Factory;
2123
use Illuminate\Support\Collection;
22-
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
23-
use Neomerx\JsonApi\Contracts\Http\HttpFactoryInterface;
2424

2525
/**
2626
* Class ClientSerializer
@@ -36,7 +36,7 @@ class ClientSerializer
3636
protected $serializer;
3737

3838
/**
39-
* @var HttpFactoryInterface
39+
* @var Factory;
4040
*/
4141
protected $factory;
4242

@@ -64,9 +64,9 @@ class ClientSerializer
6464
* ClientSerializer constructor.
6565
*
6666
* @param SerializerInterface $serializer
67-
* @param HttpFactoryInterface $factory
67+
* @param Factory $factory
6868
*/
69-
public function __construct(SerializerInterface $serializer, HttpFactoryInterface $factory)
69+
public function __construct(SerializerInterface $serializer, Factory $factory)
7070
{
7171
$this->serializer = $serializer;
7272
$this->factory = $factory;

src/Client/GuzzleClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use GuzzleHttp\Exception\RequestException;
2424
use GuzzleHttp\Exception\TransferException;
2525
use GuzzleHttp\Psr7\Request;
26-
use Neomerx\JsonApi\Contracts\Schema\ContainerInterface;
26+
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
2727

2828
/**
2929
* Class GuzzleClient
@@ -42,12 +42,12 @@ class GuzzleClient extends AbstractClient
4242
* GuzzleClient constructor.
4343
*
4444
* @param Client $http
45-
* @param ContainerInterface $schemas
45+
* @param SchemaContainerInterface $schemas
4646
* @param ClientSerializer $serializer
4747
*/
4848
public function __construct(
4949
Client $http,
50-
ContainerInterface $schemas,
50+
SchemaContainerInterface $schemas,
5151
ClientSerializer $serializer
5252
) {
5353
parent::__construct($schemas, $serializer);

0 commit comments

Comments
 (0)
0