Initial Commit

This commit is contained in:
Mark Gregory
2026-04-21 09:12:51 +01:00
commit 6bc3c69c3e
151 changed files with 11917 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace mpba\Modules;
use mpba\Modules\Contracts\RepositoryInterface;
use mpba\Modules\Exceptions\InvalidActivatorClass;
use mpba\Modules\Support\Stub;
class LaravelModulesServiceProvider extends ModulesServiceProvider
{
/**
* Booting the package.
*/
public function boot(): void
{
$this->registerNamespaces();
$this->registerModules();
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
/**
* Register the service provider.
*/
public function register()
{
$this->registerServices();
$this->setupStubPath();
$this->registerProviders();
}
/**
* Setup stub path.
*/
public function setupStubPath()
{
$path = $this->app['config']->get('modules.stubs.path') ?? __DIR__.'/Commands/stubs';
Stub::setBasePath($path);
$this->app->booted(function ($app) {
/** @var RepositoryInterface $moduleRepository */
$moduleRepository = $app[RepositoryInterface::class];
if ($moduleRepository->config('stubs.enabled') === true) {
Stub::setBasePath($moduleRepository->config('stubs.path'));
}
});
}
/**
* {@inheritdoc}
*/
protected function registerServices()
{
$this->app->singleton(RepositoryInterface::class, function ($app) {
$path = $app['config']->get('modules.paths.modules');
return new Laravel\LaravelFileRepository($app, $path);
});
$this->app->singleton(Contracts\ActivatorInterface::class, function ($app) {
$activator = $app['config']->get('modules.activator');
$class = $app['config']->get('modules.activators.'.$activator)['class'];
if ($class === null) {
throw InvalidActivatorClass::missingConfig();
}
return new $class($app);
});
$this->app->alias(RepositoryInterface::class, 'modules');
}
}