8000 Move queue job resource classes into a resource provider · CodingSeo/laravel-json-api@51df5f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51df5f3

Browse files
committed
Move queue job resource classes into a resource provider
1 parent 6360d00 commit 51df5f3

File tree

13 files changed

+233
-232
lines changed

13 files changed

+233
-232
lines changed

src/Api/AbstractProvider.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2018 Cloud Creativity Limited
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+
namespace CloudCreativity\LaravelJsonApi\Api;
20+
21+
use CloudCreativity\LaravelJsonApi\Contracts\Resolver\ResolverInterface;
22+
use CloudCreativity\LaravelJsonApi\Resolver\NamespaceResolver;
23+
use CloudCreativity\LaravelJsonApi\Routing\ApiGroup;
24+
use Illuminate\Contracts\Routing\Registrar;
25+
26+
/**
27+
* Class ResourceProvider
28+
*
29+
* @package CloudCreativity\LaravelJsonApi
30+
*/
31+
abstract class AbstractProvider
32+
{
33+
34+
/**
35+
* @var array
36+
*/
37+
protected $resources = [];
38+
39+
/**
40+
* @var bool
41+
*/
42+
protected $byResource = true;
43+
44+
/**
45+
* @var array
46+
* @deprecated 2.0.0 use package translations instead.
47+
*/
48+
protected $errors = [];
49+
50+
/**
51+
* Mount routes onto the provided API.
52+
*
53+
* @param ApiGroup $api
54+
* @param Registrar $router
55+
* @return void
56+
*/
57+
abstract public function mount(ApiGroup $api, Registrar $router);
58+
59+
/**
60+
* @return string
61+
*/
62+
abstract protected function getRootNamespace();
63+
64+
/**
65+
* @return ResolverInterface
66+
*/
67+
public function getResolver()
68+
{
69+
return new NamespaceResolver($this->getRootNamespace(), $this->resources, $this->byResource);
70+
}
71+
72+
/**
73+
* @return array
74+
* @deprecated 2.0.0
75+
*/
76+
public function getErrors()
77+
{
78+
return $this->errors;
79+
}
80+
81+
}

src/Api/Api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ public function validators()
374374
/**
375375
* Register a resource provider with this API.
376376
*
377-
* @param ResourceProvider $provider
377+
* @param AbstractProvider $provider
378378
* @return void
379379
*/
380-
public function register(ResourceProvider $provider)
380+
public function register(AbstractProvider $provider)
381381
{
382382
$this->resolver->attach($provider->getResolver());
383383
$this->errors = array_replace($provider->getErrors(), $this->errors);

src/Api/Repository.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
use CloudCreativity\LaravelJsonApi\Exceptions\RuntimeException;
2222
use CloudCreativity\LaravelJsonApi\Factories\Factory;
23-
use CloudCreativity\LaravelJsonApi\Queue;
2423
use CloudCreativity\LaravelJsonApi\Resolver\AggregateResolver;
25-
use CloudCreativity\LaravelJsonApi\Resolver\StaticResolver;
2624
use Illuminate\Contracts\Config\Repository as Config;
2725

2826
/**
@@ -89,17 +87,6 @@ public function createApi($apiName, $host = null)
8987
/** Attach resource providers to the API. */
9088
$this->createProviders($apiName)->registerAll($api);
9189

92-
/** @todo tidy this up... maybe do it using a resource provider? */
93-
$resolver->attach((new StaticResolver([
94-
'queue-jobs' => Queue\ClientJob::class,
95-
]))->setAdapter(
96-
'queue-jobs', Queue\ClientJobAdapter::class
97-
)->setSchema(
98-
'queue-jobs', Queue\ClientJobSchema::class
99-
)->setValidators(
100-
'queue-jobs', Queue\ClientJobValidators::class
101-
));
102-
10390
return $api;
10491
}
10592

src/Api/ResourceProvider.php

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,12 @@
1818

1919
namespace CloudCreativity\LaravelJsonApi\Api;
2020

21-
use CloudCreativity\LaravelJsonApi\Contracts\Resolver\ResolverInterface;
22-
use CloudCreativity\LaravelJsonApi\Resolver\NamespaceResolver;
23-
use CloudCreativity\LaravelJsonApi\Routing\ApiGroup;
24-
use Illuminate\Contracts\Routing\Registrar;
25-
2621
/**
2722
* Class ResourceProvider
2823
*
2924
* @package CloudCreativity\LaravelJsonApi
25+
* @deprecated 2.0.0 extend AbstractProvider directly.
3026
*/
31-
abstract class ResourceProvider
27+
abstract class ResourceProvider extends AbstractProvider
3228
{
33-
34-
/**
35-
* @var array
36-
*/
37-
protected $resources = [];
38-
39-
/**
40-
* @var bool
41-
*/
42-
protected $byResource = true;
43-
44-
/**
45-
* @var array
46-
* @deprecated 2.0.0 use package translations instead.
47-
*/
48-
protected $errors = [];
49-
50-
/**
51-
* Mount routes onto the provided API.
52-
*
53-
* @param ApiGroup $api
54-
* @param Registrar $router
55-
* @return void
56-
*/
57-
abstract public function mount(ApiGroup $api, Registrar $router);
58-
59-
/**
60-
* @return string
61-
*/
62-
abstract protected function getRootNamespace();
63-
64-
/**
65-
* @return ResolverInterface
66-
*/
67-
public function getResolver()
68-
{
69-
return new NamespaceResolver($this->getRootNamespace(), $this->resources, $this->byResource);
70-
}
71-
72-
/**
73-
* @return array
74-
* @deprecated 2.0.0
75-
*/
76-
public function getErrors()
77-
{
78-
return $this->errors;
79-
}
80-
8129
}

src/Factories/Factory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace CloudCreativity\LaravelJsonApi\Factories;
2020

21+
use CloudCreativity\LaravelJsonApi\Api\AbstractProvider;
2122
use CloudCreativity\LaravelJsonApi\Api\LinkGenerator;
2223
use CloudCreativity\LaravelJsonApi\Api\ResourceProvider;
2324
use CloudCreativity\LaravelJsonApi\Api\Url;
@@ -289,7 +290,7 @@ public function createResourceProvider($fqn)
289290
{
290291
$provider = $this->container->make($fqn);
291292

292-
if (!$provider instanceof ResourceProvider) {
293+
if (!$provider instanceof AbstractProvider) {
293294
throw new RuntimeException("Expecting $fqn to resolve to a resource provider instance.");
294295
}
295296

src/Queue/ClientJobAdapter.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Queue/ClientJobValidators.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Resolver/StaticResolver.php

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0