Skip to content

Commit

Permalink
🎨 Add a make method to cleanly create module instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Dec 21, 2023
1 parent fda47aa commit 3c574c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AcornPretty.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Application $app)

add_filter('init', fn () => collect($this->modules)
->reject(fn ($module) => $module instanceof AbstractModule)
->each(fn ($module) => new $module($this->app, $this->config))
->each(fn ($module) => $module::make($this->app, $this->config))
);
}
}
8 changes: 8 additions & 0 deletions src/Modules/AbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function __construct(Application $app, Collection $config)
$this->boot();
}

/**
* Make a new instance of the module.
*/
public static function make(Application $app, Collection $config): self
{
return new static($app, $config);
}

/**
* Boot the module.
*/
Expand Down

0 comments on commit 3c574c3

Please sign in to comment.