diff --git a/README.md b/README.md index 6b048ba..3fe51b2 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,11 @@ Or, install manually by downloading the source files and adding the directory to ## Configuration (optional) -The library's default behavior can be altered by extending its config file. Copy -**examples/Outbox.php** to **app/Config/** and follow the instructions +The library's default behavior can be altered by extending its config file. You can create config file using this command +```shell +php spark outbox:publish +``` +Or, manually by copy **examples/Outbox.php** to **app/Config/** and follow the instructions in the comments. If no config file is found in **app/Config** then the library will use its own. If you plan to use the Template Routes (see below) you might also want to configure diff --git a/src/Commands/OutboxPublish.php b/src/Commands/OutboxPublish.php new file mode 100644 index 0000000..f2bbc1d --- /dev/null +++ b/src/Commands/OutboxPublish.php @@ -0,0 +1,42 @@ +getNamespace('Tatter\\Outbox')[0]; + + $publisher = new Publisher($source, APPPATH); + + try { + $publisher->addPaths([ + 'Config/Outbox.php', + ])->merge(false); + } catch (Throwable $e) { + $this->showError($e); + + return; + } + + foreach ($publisher->getPublished() as $file) { + $contents = file_get_contents($file); + $contents = str_replace('namespace Tatter\\Outbox\\Config', 'namespace Config', $contents); + $contents = str_replace('use CodeIgniter\\Config\\BaseConfig', 'use Tatter\\Outbox\\Config\\Outbox as BaseOutbox', $contents); + $contents = str_replace('class Outbox extends BaseConfig', 'class Outbox extends BaseOutbox', $contents); + file_put_contents($file, $contents); + } + + CLI::write(CLI::color(' Published! ', 'green') . 'You can customize the configuration by editing the "app/Config/Outbox.php" file.'); + } +}