LayersCollection & Layer
These classes power layer discovery and are used internally by OSDD commands. They are also available for use in your own tooling or custom commands.
LayersCollection
Xefi\LaravelOSDD\Layers\LayersCollection extends Illuminate\Support\Collection. Each item is a Layer instance.
LayersCollection::fromConfig(): self
Discovers all layers from all paths defined in config/osdd.php.
use Xefi\LaravelOSDD\Layers\LayersCollection;
$layers = LayersCollection::fromConfig();
foreach ($layers as $layer) {
echo $layer->manifest->name(); // e.g. "functional/orders"
}
LayersCollection::discover(string ...$paths): self
Discovers layers from one or more explicit paths, bypassing config.
$layers = LayersCollection::discover(
base_path('functional'),
base_path('technical')
);
Discovery Algorithm
The scanner traverses each configured path at depth 0:
- If a subdirectory contains a
composer.jsonwith"type": "layer"→ it is a valid layer - Otherwise → it recurses one level deeper
This allows grouping layers under category subfolders without those folders needing to be layers themselves.
Layer
Xefi\LaravelOSDD\Layers\Layer represents a single discovered layer.
Static Methods
Layer::fromDirectory(SplFileInfo $directory): self
Constructs a Layer from a filesystem directory object.
Layer::isValidLayerDirectory(SplFileInfo $directory): bool
Returns true if the directory contains a composer.json with "type": "layer".
Public Properties
| Property | Type | Description |
|---|---|---|
$path | string | Absolute path to the layer directory |
$manifest | LayerManifest | Parsed composer.json data |
LayerManifest
Xefi\LaravelOSDD\Layers\LayerManifest parses a layer's composer.json and exposes its data through typed methods.
Methods
| Method | Return | Description |
|---|---|---|
name() | string | Full Composer name, e.g. functional/orders |
type() | string | Composer type, e.g. layer |
vendor() | string | Vendor portion, e.g. functional |
package() | string | Package portion, e.g. orders |
isLayer() | bool | true when type === 'layer' |
rootNamespace() | string | First PSR-4 key, e.g. Functional\Orders\ |
srcPath(string $layerPath) | string | Absolute path to the layer's src/ directory |
Example
use Xefi\LaravelOSDD\Layers\LayersCollection;
$layers = LayersCollection::fromConfig();
foreach ($layers as $layer) {
$manifest = $layer->manifest;
echo $manifest->name(); // functional/orders
echo $manifest->vendor(); // functional
echo $manifest->package(); // orders
echo $manifest->rootNamespace(); // Functional\Orders\
echo $manifest->srcPath($layer->path); // /path/to/project/functional/orders/src
}