Loaders
This extension provides a loader to handle YAML files containing the seeding data. See Configuration file for an example.
This section describes how custom loaders can be implemented.
A custom loader needs to implements the interface
\KM2\
and requires the PHP attribute
\KM2\ to be set.
Custom loader class example
<?php
namespace MyVendor\MyExtension\Loaders;
use KM2\DataSeeder\Attribute\DataLoader;
use KM2\DataSeeder\DataHandling\Loader\DataLoaderInterface;
#[DataLoader(identifier: 'myLoader')]
class MyCustomLoader implements DataLoaderInterface
{
public function load(array $options = []): SeedingData
{
$variables = new VariableCollection($options['variables']);
$staticData = [
'pages' => [
[
'identifier' => 'home',
'pid' => '{pages:root}',
'title' => 'Home',
'doktype' => '{variable:defaultPageType}',
],
],
];
return new SeedingData($staticData, $variables);
}
}
Copied!
Custom loader configuration
data:
loader: myLoader
options:
variables:
defaultPageType: 1
Copied!