This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGraphQLPlaygroundServiceProvider.php
85 lines (69 loc) · 2.06 KB
/
GraphQLPlaygroundServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace MLL\GraphQLPlayground;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
class GraphQLPlaygroundServiceProvider extends ServiceProvider
{
const CONFIG_PATH = __DIR__.'/graphql-playground.php';
const VIEW_PATH = __DIR__.'/../views';
/**
* Perform post-registration booting of services.
*
* @param \Illuminate\Contracts\Config\Repository $config
*
* @return void
*/
public function boot(ConfigRepository $config): void
{
$this->loadViewsFrom(self::VIEW_PATH, 'graphql-playground');
$this->publishes([
self::CONFIG_PATH => $this->configPath('graphql-playground.php'),
], 'graphql-playground-config');
$this->publishes([
self::VIEW_PATH => $this->resourcePath('views/vendor/graphql-playground'),
], 'graphql-playground-view');
if (! $config->get('graphql-playground.enabled', true)) {
return;
}
$this->loadRoutesFrom(__DIR__.'/routes.php');
}
/**
* Load routes from provided path.
*
* @param string $path
*
* @return void
*/
protected function loadRoutesFrom($path): void
{
if (Str::contains($this->app->version(), 'Lumen')) {
require realpath($path);
return;
}
parent::loadRoutesFrom($path);
}
/**
* Register bindings in the container.
*
* @return void
*/
public function register(): void
{
$this->mergeConfigFrom(self::CONFIG_PATH, 'graphql-playground');
if ($this->app->runningInConsole()) {
$this->commands([
\MLL\GraphQLPlayground\DownloadAssetsCommand::class,
]);
}
}
protected function configPath(string $path): string
{
return $this->app->basePath('config/'.$path);
}
protected function resourcePath(string $path): string
{
return $this->app->basePath('resources/'.$path);
}
}