You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param string $dir * @param string $namespace * @param \Spot\Locator $locator */functionmigrateEntities(string$dir, string$namespace, \Spot\Locator$locator)
{
$contents = array_filter(scandir($dir), function ($entry) {
return !in_array($entry, ['.', '..']);
});
foreach ($contentsas$entry) {
if (is_file($dir . DIRECTORY_SEPARATOR . $entry)) {
$classname = $namespace . substr($entry, 0, -4);
//check if the class exists and is an Entityif (class_exists($classname) && is_subclass_of($classname, \Spot\Entity::class)) {
$locator->mapper($classname)->migrate();
}
} else {
//must be a subdirectory, so scan that toomigrateEntities(
$dir . DIRECTORY_SEPARATOR . $entry,
$namespace . "{$entry}\\",
$locator
);
}
}
}
It has 3 parameters:
the directory where your entities are stored, the namespace (with trailing ) and the Spot\Locator object. It will scan through all files and directories and if it finds a valid entity it will run the migration.
Hi,
What is best practice to create all entities by not defining all of them one by one?
I use
$spot->mapper('Entity\Post')->migrate();
command for each entity. Is there a better way?
Thank you.
The text was updated successfully, but these errors were encountered: