API Reference

LayerServiceProvider

The base class of every layer's service provider.

Lomkit\Osdd\LayerServiceProvider is an abstract class that extends Illuminate\Support\ServiceProvider. Every layer's provider extends it.

use Lomkit\Osdd\LayerServiceProvider;

class OrdersServiceProvider extends LayerServiceProvider
{
    //
}

loadSeeders()

protected function loadSeeders(array $seeders, int $priority = 0): void

Registers seeder classes in the SeederRegistry. osdd:seed and LayersSeeder run them.

ParameterTypeDescription
$seedersclass-string<Seeder>[]Seeder classes
$priorityintLower values run first. Defaults to 0. Ties keep the registration order.

A seeder registered twice runs once: the first registration and its priority win.

$this->loadSeeders([OrdersSeeder::class, OrderStatusesSeeder::class]);

$this->loadSeeders([RolesSeeder::class], priority: -10);

overrideConfigFrom()

protected function overrideConfigFrom(string $path, string $key): void

Loads the PHP config file at $path and merges it over the config key $key. The file's values win over the values already loaded. Does nothing when the configuration is cached.

  • Maps are merged key by key, at every depth.
  • A list replaces the loaded value as a whole, and an empty array clears it: ['queues' => ['high']] over ['queues' => ['default', 'low']] gives ['high'].
ParameterTypeDescription
$pathstringAbsolute path to a PHP file that returns an array
$keystringConfig key to override, such as horizon
public function register(): void
{
    $this->overrideConfigFrom(__DIR__ . '/../../config/horizon.php', 'horizon');
}
Call it from register(), so the override is in place before other packages boot and read their config.

withRouting()

protected function withRouting(
    array|string|null $web = null,
    array|string|null $api = null,
    ?string $commands = null,
    ?string $channels = null,
    ?string $health = null,
    string $apiPrefix = 'api',
): void

Mounts the layer's route files with Laravel's conventions. Missing files are skipped. When routes are cached, the web, api and health routes come from the cache; the commands and channels files are still loaded.

ParameterTypeDescription
$webstring[]|string|nullRoute files loaded in the web middleware group
$apistring[]|string|nullRoute files loaded in the api middleware group, under $apiPrefix
$commands?stringConsole routes file, required when running in the console
$channels?stringBroadcast channels file
$health?stringURI of a GET route that returns {"status":"ok"}
$apiPrefixstringPrefix of the api routes
public function boot(): void
{
    $this->withRouting(
        web: __DIR__ . '/../../routes/web.php',
        api: __DIR__ . '/../../routes/api.php',
        commands: __DIR__ . '/../../routes/console.php',
        channels: __DIR__ . '/../../routes/channels.php',
    );
}

See Routes.

withViews()

protected function withViews(string $path, ?string $namespace = null): void

Loads the Blade views of $path under $namespace: view('orders::index'). Does nothing when the folder does not exist.

ParameterTypeDescription
$pathstringThe layer's views folder
$namespace?stringDefaults to the package name of the layer that owns the provider: orders for functional/orders

withTranslations()

protected function withTranslations(string $path, ?string $namespace = null): void

Loads the translation files of $path under $namespace (__('orders::messages.welcome')), and its *.json files without a namespace. Does nothing when the folder does not exist. $namespace defaults like withViews().

withComponents()

protected function withComponents(string $namespace, ?string $prefix = null): void

Registers the Blade components of a PHP namespace under a prefix: withComponents('Functional\\Orders\\View\\Components') makes <x-orders::alert /> render Functional\Orders\View\Components\Alert. $prefix defaults like withViews().

Namespaces and collisions

The three with*() resource methods share these rules:

  • Without a namespace, they use the package name of the discovered layer whose autoload.psr-4 prefix covers the provider class. A provider that belongs to no discovered layer throws Lomkit\Osdd\Layers\ProviderLayerNotFoundException: pass the namespace.
  • Two providers claiming the same views namespace, translations namespace or component prefix throw Lomkit\Osdd\Resources\ResourceNamespaceCollisionException at boot, naming both providers. Pass the second argument in one of them.

See Views and components.

Inherited methods

Every method of Laravel's ServiceProvider works as usual. The ones a layer uses most:

MethodUse
loadMigrationsFrom($path)Add the layer's migrations to migrate
commands([...])Register the layer's Artisan commands
mergeConfigFrom($path, $key)Fill in defaults without overriding loaded values
loadViewsFrom($path, $namespace), loadTranslationsFrom($path, $namespace)Load views or translations under a namespace you manage yourself