Publishing Files

A publish bundle copies defaults from the framework or a module into the application. Once published, the files can be edited alongside application code. For example, a module can ship templates that each installation can customize.

Define a Bundle

Give the bundle a name and a source directory. Call file() once per source and destination. In this example, the module ships a receipt and a reminder under its Resources directory.

use Atom\Publish\PublishBundle;

$bundle = (new PublishBundle("billing", __DIR__ . "/Resources"))
    ->file("receipt.txt", "@root/templates/billing/receipt.txt")
    ->file("reminder.txt", "@root/templates/billing/reminder.txt");

Relative source names are resolved from the bundle's source directory. @root resolves to the application root, so the destination stays the same when the command runs from another working directory.

Publish a Bundle

Inject Atom\Publish\Publisher into the command or service that owns the bundle. Pass the bundle to publish():

$result = $publisher->publish($bundle);

By default, the publisher copies missing files and skips existing destinations. If someone edited the receipt, a later publish keeps that edit and can still add a missing reminder.

Result field Contains
$result->published Paths of newly copied files.
$result->skipped Paths of existing files that were kept.
$result->overwritten Paths of existing files that were replaced.

When to overwrite files

A publish command can expose a boolean $force option that defaults to false. Forward it to the publisher:

$result = $publisher->publish($bundle, force: $force);

Use --force when you deliberately want the bundled files to replace their application copies. Any edits in the replaced files are lost. For example, the queue command accepts:

php atom queue:publish --force

Publishing a migration writes a file. Applying it is a separate step described in Migrations and seeders.