protected function generateFactories($loadModels, $ignore = '')
{
if (empty($loadModels)) {
$models = $this->loadModels();
} else {
$models = array();
foreach ($loadModels as $model) {
$models = array_merge($models, explode(',', $model));
}
}
$output = $this->reset || !$this->files->exists('database/factories/ModelFactory.php') ? '<?php' . "\n\n" : $this->existingFactories;
$ignore = explode(',', $ignore);
foreach ($models as $name) {
if (in_array($name, $ignore)) {
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->comment("Ignoring model '{$name}'");
}
continue;
}
$this->properties = array();
if (class_exists($name)) {
try {
// handle abstract classes, interfaces, ...
$reflectionClass = new \ReflectionClass($name);
if (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
continue;
}
if (!$this->reset && preg_match("/\\\$factory->define\\((.*?)" . preg_quote($reflectionClass->getName()) . "::class(.*?),/", $this->existingFactories)) {
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->error("Model '{$name}' already has a factory");
}
continue;
}
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->comment("Loading model '{$name}'");
}
if (!$reflectionClass->IsInstantiable()) {
// ignore abstract class or interface
continue;
}
$model = $this->laravel->make($name);
$this->getPropertiesFromTable($model);
$this->getPropertiesFromMethods($model);
$output .= $this->createFactory($name);
$ignore[] = $name;
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
}
}
}
return $output;
}