Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions src/Commands/OutboxPublish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tatter\Outbox\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Publisher\Publisher;
use Throwable;

class OutboxPublish extends BaseCommand
{
protected $group = 'Outbox';
protected $name = 'outbox:publish';
protected $description = 'Publish Oubox config file into the current application.';

public function run(array $params): void
{
$source = service('autoloader')->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/Oubox.php" file.');
}
}