mirror of
https://github.com/coollabsio/coolify.git
synced 2026-06-19 07:35:25 +00:00
2.2 KiB
2.2 KiB
Object Entrypoint (run, make, DI)
Scope
Use this reference when the action is invoked as a plain object.
Recap
- Explains object-style invocation with
make,run,runIf,runUnless. - Clarifies when to use static helpers versus DI/manual invocation.
- Includes minimal examples for direct run and service-level injection.
- Highlights boundaries: business logic stays in
handle(...).
Recommended pattern
- Keep core business logic in
handle(...). - Prefer
Action::run(...)for readability. - Use
Action::make()->handle(...)or DI only when needed.
Methods provided
make
Resolves the action from the container.
PublishArticle::make();
// Equivalent to:
app(PublishArticle::class);
run
Resolves and executes the action.
PublishArticle::run($articleId);
// Equivalent to:
PublishArticle::make()->handle($articleId);
runIf
Resolves and executes the action only if the condition is met.
PublishArticle::runIf($shouldPublish, $articleId);
// Equivalent mental model:
if ($shouldPublish) {
PublishArticle::run($articleId);
}
runUnless
Resolves and executes the action only if the condition is not met.
PublishArticle::runUnless($alreadyPublished, $articleId);
// Equivalent mental model:
if (! $alreadyPublished) {
PublishArticle::run($articleId);
}
Checklist
- Input/output types are explicit.
handle(...)has no transport concerns.- Business behavior is covered by direct
handle(...)tests.
Common pitfalls
- Putting HTTP/CLI/queue concerns in
handle(...). - Calling adapters from
handle(...)instead of the reverse.
References
Examples
Minimal object-style invocation
final class PublishArticle
{
use AsAction;
public function handle(int $articleId): bool
{
// Domain logic...
return true;
}
}
$published = PublishArticle::run(42);
Dependency injection invocation
final class ArticleService
{
public function __construct(
private PublishArticle $publishArticle
) {}
public function publish(int $articleId): bool
{
return $this->publishArticle->handle($articleId);
}
}