8000 Merge branch 'feature/async' into async-with-cn · Hy0320/laravel-json-api@6f8c3c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f8c3c8

Browse files
committed
Merge branch 'feature/async' into async-with-cn
2 parents 8ea33b9 + 51df5f3 commit 6f8c3c8

21 files changed

+319
-314
lines changed

database/migrations/2018_10_23_000001_create_client_jobs_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function up()
1616
{
1717
Schema::create('json_api_client_jobs', function (Blueprint $table) {
1818
$table->uuid('uuid')->primary();
19-
$table->timestamps(6);
19+
$table->timestamps();
2020
$table->string('api');
2121
$table->string('resource_type');
2222
$table->string('resource_id')->nullable();

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
@@ -402,10 +402,10 @@ public function validators()
402402
/**
403403
* Register a resource provider with this API.
404404
*
405-
* @param ResourceProvider $provider
405+
* @param AbstractProvider $provider
406406
* @return void
407407
*/
408-
public function register(ResourceProvider $provider)
408+
public function register(AbstractProvider $provider)
409409
{
410410
$this->resolver->attach($provider->getResolver());
411411
$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
/**
@@ -90,17 +88,6 @@ public function createApi($apiName, $host = null)
9088
/** Attach resource providers to the API. */
9189
$this->createProviders($apiName)->registerAll($api);
9290

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

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
@@ -19,6 +19,7 @@
1919
namespace CloudCreativity\LaravelJsonApi\Factories;
2020

2121
use CloudCreativity\LaravelJsonApi\Api\Api;
22+
use CloudCreativity\LaravelJsonApi\Api\AbstractProvider;
2223
use CloudCreativity\LaravelJsonApi\Api\LinkGenerator;
2324
use CloudCreativity\LaravelJsonApi\Api\ResourceProvider;
2425
use CloudCreativity\LaravelJsonApi\Api\Url;
@@ -275,7 +276,7 @@ public function createResourceProvider($fqn)
275276
{
276277
$provider = $this->container->make($fqn);
277278

278-
if (!$provider instanceof ResourceProvider) {
279+
if (!$provider instanceof AbstractProvider) {
279280
throw new RuntimeException("Expecting $fqn to resolve to a resource provider instance.");
280281
}
281282

src/LaravelJsonApi.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace CloudCreativity\LaravelJsonApi;
4+
5+
class LaravelJsonApi
6+
{
7+
8+
/**
9+
* Indicates if Laravel JSON API migrations will be run.
10+
*
11+
* @var bool
12+
*/
13+
public static $runMigrations = true;
14+
15+
/**
16+
* Indicates if listeners will be bound to the Laravel queue events.
17+
*
18+
* @var bool
19+
*/
20+
public static $queueBindings = true;
21+
22+
/**
23+
* @return LaravelJsonApi
24+
*/
25+
public static function ignoreMigrations(): self
26+
{
27+
static::$runMigrations = false;
28+
29+
return new self();
30+
}
31+
32+
/**
33+
* @return LaravelJsonApi
34+
*/
35+
public static function skipQueueBindings(): self
36+
{
37+
static::$queueBindings = false;
38+
39+
return new self();
40+
}
41+
}

src/Queue/ClientJob.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ class ClientJob extends Model implements AsynchronousProcess
7373
'timeout_at',
7474
];
7575

76-
/**
77-
* @var string
78-
*/
79-
protected $dateFormat = 'Y-m-d H:i:s.u';
80-
8176
/**
8277
* @inheritdoc
8378
*/
@@ -184,7 +179,7 @@ public function getResource()
184179
}
185180

186181
return $this->getApi()->getStore()->find(
187-
ResourceIdentifier::create($this->resource_type, $this->resource_id)
182+
ResourceIdentifier::create($this->resource_type, (string) $this->resource_id)
188183
);
189184
}
190185

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.

0 commit comments

Comments
 (0)
0