-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCommandTrait.php
More file actions
41 lines (35 loc) · 1.13 KB
/
CommandTrait.php
File metadata and controls
41 lines (35 loc) · 1.13 KB
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
<?php
declare(strict_types=1);
namespace SwaggerBake\Command;
use Cake\Console\Arguments;
use Cake\Core\Configure;
use Cake\Core\Exception\CakeException;
use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException;
use SwaggerBake\Lib\ExtensionLoader;
trait CommandTrait
{
/**
* Loads configuration
*
* @param \Cake\Console\Arguments $args Cli Arguments instance
* @return void
* @throws \SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException if config file not found
* @throws \RuntimeException if config var SwaggerBake not found
*/
public function loadConfig(Arguments $args): void
{
$config = (string)$args->getOption('config');
if ($config !== 'swagger_bake') {
Configure::delete('SwaggerBake');
}
try {
Configure::load($config, 'default');
} catch (CakeException $e) {
throw new SwaggerBakeRunTimeException(
"SwaggerBake config file `$config` is missing or " . get_class($e) . ' ' . $e->getMessage(),
);
}
Configure::readOrFail('SwaggerBake');
ExtensionLoader::load();
}
}