forked from knuckleswtf/scribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentationConfig.php
64 lines (52 loc) · 1.54 KB
/
DocumentationConfig.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
<?php
namespace Knuckles\Scribe\Tools;
use Illuminate\Support\Str;
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
class DocumentationConfig
{
private $data;
public function __construct(array $config = [])
{
$config['router'] = $this->getRouter($config);
$this->data = $config;
}
/**
* Get a config item with dot notation.
* If the key does not exist, $default (or null) will be returned.
*
* @param string $key
* @param mixed $default
*
* @return array|mixed
*/
public function get(string $key, $default = null)
{
return data_get($this->data, $key, $default);
}
private function getRouter(array $config): string
{
if ($router = data_get($config, 'router', null)) {
if (!in_array($router, ['dingo', 'laravel'])) {
throw new \InvalidArgumentException("Unknown `router` config value: $router");
}
return $router;
}
if (class_exists(\Dingo\Api\Routing\Router::class)) {
c::info('Detected Dingo API router');
return 'dingo';
}
return 'laravel';
}
public function outputIsStatic(): bool
{
return !$this->outputRoutedThroughLaravel();
}
public function outputRoutedThroughLaravel(): bool
{
return Str::is(['laravel', 'external_laravel'], $this->get('type'));
}
public function outputIsExternal(): bool
{
return Str::is(['external_static', 'external_laravel'], $this->get('type'));
}
}