|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter Queue. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Settings\Commands; |
| 15 | + |
| 16 | +use CodeIgniter\CLI\BaseCommand; |
| 17 | +use CodeIgniter\CLI\CLI; |
| 18 | +use CodeIgniter\Publisher\Publisher; |
| 19 | +use Throwable; |
| 20 | + |
| 21 | +class PublishSettings extends BaseCommand |
| 22 | +{ |
| 23 | + protected $group = 'Settings'; |
| 24 | + protected $name = 'settings:publish'; |
| 25 | + protected $description = 'Publish Settings config file into the current application.'; |
| 26 | + |
| 27 | + public function run(array $params): void |
| 28 | + { |
| 29 | + $source = service('autoloader')->getNamespace('CodeIgniter\\Settings')[0]; |
| 30 | + |
| 31 | + $publisher = new Publisher($source, APPPATH); |
| 32 | + |
| 33 | + try { |
| 34 | + $publisher->addPaths([ |
| 35 | + 'Config/Settings.php', |
| 36 | + ])->merge(false); |
| 37 | + } catch (Throwable $e) { |
| 38 | + $this->showError($e); |
| 39 | + |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + foreach ($publisher->getPublished() as $file) { |
| 44 | + $contents = file_get_contents($file); |
| 45 | + $contents = str_replace('namespace CodeIgniter\\Settings\\Config', 'namespace Config', $contents); |
| 46 | + $contents = str_replace('use CodeIgniter\\Config\\BaseConfig', 'use CodeIgniter\\Settings\\Config\\Settings as BaseSettings', $contents); |
| 47 | + $contents = str_replace('class Settings extends BaseConfig', 'class Settings extends BaseSettings', $contents); |
| 48 | + file_put_contents($file, $contents); |
| 49 | + } |
| 50 | + |
| 51 | + CLI::write(CLI::color(' Published! ', 'green') . 'You can customize the configuration by editing the "app/Config/Settings.php" file.'); |
| 52 | + } |
| 53 | +} |
0 commit comments