1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\Lumen\ContentfulSync\Providers; |
4
|
|
|
|
5
|
|
|
use Digia\Lumen\ContentfulSync\Console\Commands\SyncAssetsCommand; |
6
|
|
|
use Digia\Lumen\ContentfulSync\Console\Commands\SyncContentsCommand; |
7
|
|
|
use Digia\Lumen\ContentfulSync\Contracts\ContentfulSyncServiceContract; |
8
|
|
|
use Digia\Lumen\ContentfulSync\Http\Middleware\WebhookAuthenticationMiddleware; |
9
|
|
|
use Illuminate\Support\ServiceProvider; |
10
|
|
|
use Jalle19\Laravel\LostInterfaces\Providers\ServiceProvider as ServiceProviderInterface; |
11
|
|
|
use Laravel\Lumen\Application; |
12
|
|
|
use Nord\Lumen\Contentful\ContentfulServiceContract; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AbstractContentfulSyncServiceProvider |
16
|
|
|
* @package Digia\Lumen\ContentfulSync\Providers |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractContentfulSyncServiceProvider extends ServiceProvider implements ServiceProviderInterface |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param Application $app |
23
|
|
|
*/ |
24
|
|
|
abstract protected function registerContentfulSyncServiceBindings(Application $app); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public function register(): void |
30
|
|
|
{ |
31
|
|
|
app()->configure('contentfulSync'); |
32
|
|
|
|
33
|
|
|
// Configure how ContentfulSyncServiceContract should be built |
34
|
|
|
$this->registerContentfulSyncServiceBindings(app()); |
35
|
|
|
|
36
|
|
|
// Configure how commands should be built |
37
|
|
View Code Duplication |
app()->bind(SyncAssetsCommand::class, function (Application $app) { |
|
|
|
|
38
|
|
|
return new SyncAssetsCommand(config('contentfulSync.content_types'), |
39
|
|
|
$app->make(ContentfulServiceContract::class), |
40
|
|
|
$app->make(ContentfulSyncServiceContract::class)); |
41
|
|
|
}); |
42
|
|
|
|
43
|
|
View Code Duplication |
app()->bind(SyncContentsCommand::class, function (Application $app) { |
|
|
|
|
44
|
|
|
return new SyncContentsCommand(config('contentfulSync.content_types'), |
45
|
|
|
$app->make(ContentfulServiceContract::class), |
46
|
|
|
$app->make(ContentfulSyncServiceContract::class)); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
// Configure how middleware should be built |
50
|
|
|
app()->bind(WebhookAuthenticationMiddleware::class, function () { |
51
|
|
|
$expectedUsername = config('contentfulSync.webhookUsername'); |
52
|
|
|
$expectedPassword = config('contentfulSync.webhookPassword'); |
53
|
|
|
|
54
|
|
|
return new WebhookAuthenticationMiddleware($expectedUsername, $expectedPassword); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritDoc |
60
|
|
|
*/ |
61
|
|
|
public function boot(): void |
62
|
|
|
{ |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.