-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPublishSettings.php
More file actions
53 lines (42 loc) · 1.72 KB
/
Copy pathPublishSettings.php
File metadata and controls
53 lines (42 loc) · 1.72 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
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Queue.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Settings\Commands;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Publisher\Publisher;
use Throwable;
class PublishSettings extends BaseCommand
{
protected $group = 'Settings';
protected $name = 'settings:publish';
protected $description = 'Publish Settings config file into the current application.';
public function run(array $params): void
{
$source = service('autoloader')->getNamespace('CodeIgniter\\Settings')[0];
$publisher = new Publisher($source, APPPATH);
try {
$publisher->addPaths([
'Config/Settings.php',
])->merge(false);
} catch (Throwable $e) {
$this->showError($e);
return;
}
foreach ($publisher->getPublished() as $file) {
$contents = file_get_contents($file);
$contents = str_replace('namespace CodeIgniter\\Settings\\Config', 'namespace Config', $contents);
$contents = str_replace('use CodeIgniter\\Config\\BaseConfig', 'use CodeIgniter\\Settings\\Config\\Settings as BaseSettings', $contents);
$contents = str_replace('class Settings extends BaseConfig', 'class Settings extends BaseSettings', $contents);
file_put_contents($file, $contents);
}
CLI::write(CLI::color(' Published! ', 'green') . 'You can customize the configuration by editing the "app/Config/Settings.php" file.');
}
}