Contracts and base classes
This page lists the interfaces of Nwidart\Modules\Contracts, the base classes of the package, its traits and the default activator. Method lists are complete for the public and protected API. The provider base class of a module has its own page: Module service provider.
Interfaces
Section titled “Interfaces”Each interface has the same layout: what it is and how the package uses it, then a table of its methods.
RepositoryInterface
Section titled “RepositoryInterface”Nwidart\Modules\Contracts\RepositoryInterface is the contract of the module repository. The container binds it as a singleton, aliased as modules, to Laravel\LaravelFileRepository. Its docblock adds setUsed(), forgetUsed(), getUsedNow(), update() and resetModules(), which the package commands call: a custom repository must implement them too. Behaviour of every method: Module facade and repository.
| Signature | Returns | Description |
|---|---|---|
all() |
array<string, Module> |
Every module. |
scan() |
array<string, Module> |
Scans the module folders. |
toCollection() |
Collection<string, Module> |
The modules as a Nwidart\Modules\Collection. |
getScanPaths() |
array<int, string> |
The scanned folders. |
allEnabled() |
array<string, Module> |
The enabled modules. |
allDisabled() |
array<string, Module> |
The disabled modules. |
count() |
int |
The number of modules. |
getOrdered(string $direction = 'asc') |
array<string, Module> |
The enabled modules ordered by priority. |
getByStatus(int|bool $status) |
array<string, Module> |
The modules with the given status. |
find(string $name) |
Module|null |
The module with that name. |
findOrFail(string $name) |
Module |
Like find(). Throws ModuleNotFoundException. |
getModulePath(string $moduleName) |
string |
The folder of a module, or the path it would have. |
getFiles() |
Filesystem |
The filesystem instance. |
config(string $key, $default = null) |
mixed |
A value of the modules config. |
getPath() |
string |
The folder that holds the modules. |
boot() |
void |
Deprecated. The package no longer calls it. |
register() |
void |
Deprecated. The package no longer calls it. |
assetPath(string $module) |
string |
The assets path of a module. |
delete(string $module) |
bool |
Deletes a module. Throws ModuleNotFoundException. |
isEnabled(string $name) |
bool |
true when the module is enabled. Throws ModuleNotFoundException. |
isDisabled(string $name) |
bool |
true when the module is not enabled. Throws ModuleNotFoundException. |
ActivatorInterface
Section titled “ActivatorInterface”Nwidart\Modules\Contracts\ActivatorInterface stores the enabled or disabled status of modules. The container binds it as a singleton. It selects the activator from modules.activator, reads modules.activators.<name>.class, and instantiates new $class($app). See Configuration.
| Signature | Returns | Description |
|---|---|---|
enable(Module $module) |
void |
Marks the module as enabled. |
disable(Module $module) |
void |
Marks the module as disabled. |
hasStatus(Module|string $module, bool $status) |
bool |
true when the module has the given status. Accepts a module or a module name. |
setActive(Module $module, bool $active) |
void |
Sets the status of a module. |
setActiveByName(string $name, bool $active) |
void |
Sets the status of a module by name. module:make calls it. |
delete(Module $module) |
void |
Deletes the stored status of a module. |
reset() |
void |
Deletes every status the activator stores. |
ConfirmableCommand
Section titled “ConfirmableCommand”Nwidart\Modules\Contracts\ConfirmableCommand is a marker interface.
| Signature | Returns | Description |
|---|---|---|
| none | The interface declares no method. BaseCommand checks instanceof when it is constructed and when it runs. |
A BaseCommand that implements it:
- has the
--forceoption, without a shortcut; - runs the prohibition check, then confirmation, after module validation and before any action. Either failure exits with
1and runs no action; - prohibition check: prints
This command is prohibited from running in this environment.when prohibited.--forcedoes not lift it; - confirmation: Laravel’s
confirmToProceed()displaysgetConfirmableLabel()(defaultApplication In Production) and asksAre you sure you want to run this command?(default no).--forceskips it. It runs whengetConfirmableCallback()returnstrue, or inproductionwhennull. Without interactive input, the command printsCommand cancelled.and exits with1.
| Command | Confirmation applies | Prohibition applies |
|---|---|---|
module:migrate-fresh, module:migrate-refresh, module:migrate-reset, module:migrate-rollback |
In production |
After Module::prohibitDestructiveCommands() or its own prohibit() |
module:delete |
In every environment (true callback; label Warning: Do you want to remove the module?) |
After Module::prohibitDestructiveCommands() or its own prohibit() |
Module::prohibitDestructiveCommands() is the package counterpart of Laravel’s DB::prohibitDestructiveCommands(). It calls prohibit() from Illuminate\Console\Prohibitable on the five commands above. See Destructive commands. Each command uses the trait directly and keeps its own flag: MigrateFreshCommand::prohibit() prohibits only module:migrate-fresh.
BaseCommand also uses Prohibitable. A third-party command extending BaseCommand and implementing ConfirmableCommand without its own trait shares the BaseCommand flag. BaseCommand::prohibit() or the command’s prohibit() prohibits it. Module::prohibitDestructiveCommands() does not affect third-party commands, and BaseCommand::prohibit() does not affect the five package commands. Non-confirmable commands skip the check.
PublisherInterface
Section titled “PublisherInterface”Nwidart\Modules\Contracts\PublisherInterface is implemented by Nwidart\Modules\Publishing\Publisher for the asset, language and migration publishers.
| Signature | Returns | Description |
|---|---|---|
publish() |
void |
Publishes the files. |
RunableInterface
Section titled “RunableInterface”Nwidart\Modules\Contracts\RunableInterface is implemented by Nwidart\Modules\Process\Runner.
| Signature | Returns | Description |
|---|---|---|
run(string $command) |
void |
Runs the command. |
Base classes
Section titled “Base classes”ModuleServiceProvider
Section titled “ModuleServiceProvider”Nwidart\Modules\Support\ModuleServiceProvider is the base class for a module’s main provider. See Module service provider for its properties, methods, and registered resources.
BaseCommand
Section titled “BaseCommand”Nwidart\Modules\Commands\BaseCommand extends Illuminate\Console\Command and implements PromptsForMissingInput. It adds the variadic module argument and --all (-a) option, then runs executeAction() for each selected module. See Shared behaviour.
| Signature | Description |
|---|---|
const ALL = 'All' |
Label of the first entry in the interactive module prompt. |
abstract executeAction($name) |
Public. Runs the action for one module. Return false or a non-zero integer, or call markAsFailed(), to fail the run. Remaining modules still run. |
getInfo(): ?string |
Public. Optional info line printed once before actions run. Default null. |
getConfirmableLabel(): ?string |
Public. Confirmation alert label. Default Application In Production. Used only with ConfirmableCommand. |
getConfirmableCallback(): \Closure|bool|null |
Public. Decides whether confirmation runs. Default null. |
handle() |
Public. Validates input and modules, checks canProceed(), runs executeModules(), and returns 0 or 1. |
hasModulesToRun(): bool |
Protected, from ValidatesModuleArgument. Returns true if a module or --all was given; otherwise prints an error and returns false. |
validateModules(): bool |
Protected, from ValidatesModuleArgument. Returns true if every named module exists; otherwise prints the missing names and returns false. |
canProceed(): bool |
Protected. Returns true for non-confirmable commands. For ConfirmableCommand, verifies ! $this->isProhibited() and confirmToProceed(). |
executeModules(): void |
Protected. Prints getInfo() when set, runs executeAction() for each module, and marks failures. |
markAsFailed(): void |
Protected. Marks the run as failed. |
hasFailures(): bool |
Protected. Returns true when an action failed during this run. |
getModuleModel(Module|string $name) |
Protected. Returns the Module for a name, or throws ModuleNotFoundException. |
getModuleNames(InputInterface $input): array |
Protected. Returns module names for --all and the All prompt choice: every module, or priority-ordered enabled modules when --direction exists. MigrateRefreshCommand overrides this with getEnabledModuleNames('asc'). |
getEnabledModuleNames(string $direction = 'asc'): array |
Protected. Returns enabled module names ordered by priority in the given direction. |
moduleRepository() |
Protected. Returns the repository, from InteractsWithModuleRepository. |
The package registers the classes of modules.commands (see Configuration). A module provider registers the classes of its $commands property.
GeneratorCommand
Section titled “GeneratorCommand”Nwidart\Modules\Commands\Make\GeneratorCommand extends Illuminate\Console\Command and is the base class for module:make-* generators. It uses InteractsWithModuleRepository and PathNamespace. Its constructor adds --force (with -f if unused) unless the command defines --force itself.
| Signature | Description |
|---|---|
$argumentName |
Protected property. Argument name holding the class name. Empty by default, which disables name validation. |
abstract getTemplateContents() |
Protected. Returns file contents, usually via Stub::create('/x.stub', [...])->render(). |
abstract getDestinationFilePath() |
Protected. Returns the destination file path. |
handle(): int |
Public. Validates the name and module, creates missing directories, writes via FileGenerator, and returns 0. Prints an error and returns 1 on validation or overwrite failure. |
validateNameArgument(): ?string |
Protected. Rejects empty names, absolute paths, and .. segments (including segments that reduce to .. after stripping whitespace, hyphens, and underscores). Returns an error string or null. |
validateModuleArgument(): ?string |
Protected. Checks the module argument or module:use fallback. Returns an error message when missing or unknown, otherwise null. |
getClass() |
Public. Returns class_basename() of the name argument. |
getDefaultNamespace(): string |
Public. Namespace part below the module namespace. Default ''. |
getClassNamespace($module) |
Public. Full namespace combining the module namespace, getDefaultNamespace(), and any folders in the name argument. |
module(?string $name = null): Module |
Public. Returns the Module for $name, or for getModuleName() when null. |
getModuleName() |
Not defined on this class. Provided by ModuleCommandTrait, which most generators use. |
The path and namespace of a generated class come from modules.paths.generator.<key>, read with Support\Config\GenerateConfigReader.
ReplacementKeyCommand
Section titled “ReplacementKeyCommand”Nwidart\Modules\Support\ReplacementKeyCommand is the base class of a replacement that module:make computes for a stub. A class is selected by an upper-case key in modules.stubs.replacements.<stub>. See Stubs and placeholders.
| Signature | Description |
|---|---|
__construct(protected ModuleGenerator $generator) |
The generator that renders the stubs. |
abstract handle(): string |
Returns the text that replaces the key. module:make inserts it unchanged: in a JSON stub, escape it yourself. |
use Nwidart\Modules\Support\ReplacementKeyCommand;
class CustomKey extends ReplacementKeyCommand{ public function handle(): string { return strtolower($this->generator->getName()); }}module:make-replacement generates a class with this handle() body, which returns the lower-case module name. See Stubs and placeholders.
Controller
Section titled “Controller”Nwidart\Modules\Routing\Controller extends Illuminate\Routing\Controller and uses AuthorizesRequests, DispatchesJobs and ValidatesRequests. It adds no method. No stub or class of the package uses it: the generated controllers extend App\Http\Controllers\Controller.
Traits
Section titled “Traits”All traits are in Nwidart\Modules\Traits. Each has the same layout as the interfaces: a short description, then a table of its methods.
PathNamespace
Section titled “PathNamespace”Path and namespace helpers. They build the class namespaces of the generators from the paths of modules.paths. All methods are public.
| Signature | Returns | Description |
|---|---|---|
studly_path(string $path, $ds = '/') |
string |
Studly-cases each segment of a path. |
studly_namespace(string $namespace, $ds = '\\') |
string |
Studly-cases each segment of a namespace. |
path_namespace(string $path) |
string |
The namespace of a path. |
module_namespace(string $module, ?string $path = null) |
string |
The namespace of a module, with an optional extra path. |
clean_path(string $path, $ds = '/') |
string |
Removes empty segments. |
strip_app_folder(?string $path) |
string |
Removes the leading modules.paths.app_folder segment of a path. |
app_path(?string $path = null) |
string |
The app folder of a module, with an optional path inside it. |
ModuleCommandTrait
Section titled “ModuleCommandTrait”| Signature | Returns | Description |
|---|---|---|
getModuleName() |
string |
The studly-case name of the module argument, or of the module set with module:use when the argument is empty. Throws ModuleNotFoundException for an unknown module. |
InteractsWithModuleRepository
Section titled “InteractsWithModuleRepository”| Signature | Returns | Description |
|---|---|---|
moduleRepository() |
RepositoryInterface |
Protected. The repository, resolved by its modules alias. A swap of the Module facade replaces it. |
CanClearModulesCache
Section titled “CanClearModulesCache”| Signature | Returns | Description |
|---|---|---|
clearCache() |
void |
Calls resetModules() on the repository, so the next lookup reads the module.json files again. It does not delete bootstrap/cache/modules.php. For commands. |
ValidatesModuleArgument
Section titled “ValidatesModuleArgument”Checks the module argument and --all option before a command runs. BaseCommand and module:prune use it. The command needs an array module argument, an --all option, and InteractsWithModuleRepository.
| Signature | Returns | Description |
|---|---|---|
hasModulesToRun() |
bool |
Protected. true when --all or at least one module name is given. Otherwise prints No module given. Pass a module name or --all. and returns false. |
validateModules() |
bool |
Protected. true when every module name of the argument exists. Otherwise prints Module [<name>] does not exist. (or Modules [<names>] do not exist.) and returns false. |
moduleNamesToValidate() |
array |
Protected. The names that validateModules() checks. Default: the module argument. |
ResolvesInertiaFrontend
Section titled “ResolvesInertiaFrontend”Resolves the Inertia frontend from --vue, --react, and --svelte, falling back to modules.inertia.frontend. Used by Inertia generator and publish commands.
| Signature | Returns | Description |
|---|---|---|
getInertiaFrontend() |
string |
Protected. Returns the passed framework option (vue, react, or svelte), or modules.inertia.frontend (default 'vue'). |
reportConflictingInertiaFrontends() |
bool |
Protected. Prints an error and returns true when more than one framework option is passed; otherwise returns false. |
MigrationLoaderTrait
Section titled “MigrationLoaderTrait”Deprecated, unused, removed in version 14. Nwidart\Modules\Migrations\Migrator replaces it.
| Signature | Returns | Description |
|---|---|---|
loadMigrationFiles(string $module) |
void |
Protected. Throws a TypeError: it calls getMigrationGeneratorPath(). |
getMigrationGeneratorPath() |
string |
Protected. Returns the whole paths.generator.migration array, which does not match its return type: calling it throws a TypeError. |
FileActivator
Section titled “FileActivator”Nwidart\Modules\Activators\FileActivator implements ActivatorInterface. It is the activator of the file entry of modules.activators. It keeps the statuses in a JSON file: an object that maps each module name to true or false.
{ "Blog": true, "Shop": false}| Signature | Returns | Description |
|---|---|---|
new FileActivator(Container $app) |
FileActivator |
Reads the file at modules.activators.file.statuses-file (default base_path('modules_statuses.json')). A missing or empty file gives no statuses. Throws InvalidJsonException for a file that is not valid JSON or is a non-empty JSON list. |
getStatusesFilePath() |
string |
The path of the statuses file. |
getStatuses() |
array<string, bool> |
The stored statuses, keyed by module name. They are the ones read when the activator was created. |
enable(Module $module), disable(Module $module), setActive(Module $module, bool $active), setActiveByName(string $name, bool $status) |
void |
Set the status, then write the whole file. |
hasStatus(Module|string $module, bool $status) |
bool |
true when the stored status equals $status. A module with no stored status has the status false. |
delete(Module $module) |
void |
Removes the entry of the module and writes the file. Does nothing when there is no entry. |
reset() |
void |
Deletes the file and forgets the statuses in memory. |
The activator reads the file once, when it is created. It stores nothing for a module that was never enabled or disabled, and module:make writes a status for each module it creates.