protected function generateDocs($loadModels, $ignore = '')
{
$output = "<?php\n/**\n * A helper file for your Eloquent Models\n * Copy the phpDocs from this file to the correct Model,\n * And remove them from this file, to prevent double declarations.\n *\n * @author Barry vd. Heuvel <[email protected]>\n */\n\n\n";
$hasDoctrine = interface_exists('Doctrine\\DBAL\\Driver');
if (empty($loadModels)) {
$models = $this->loadModels();
} else {
$models = array();
foreach ($loadModels as $model) {
$models = array_merge($models, explode(',', $model));
}
}
$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();
$this->methods = array();
if (class_exists($name)) {
try {
// handle abstract classes, interfaces, ...
$reflectionClass = new \ReflectionClass($name);
if (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
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);
if ($hasDoctrine) {
$this->getPropertiesFromTable($model);
}
if (method_exists($model, 'getCasts')) {
$this->castPropertiesType($model);
}
$this->getPropertiesFromMethods($model);
$output .= $this->createPhpDocs($name);
$ignore[] = $name;
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
}
}
}
if (!$hasDoctrine) {
$this->error('Warning: `"doctrine/dbal": "~2.3"` is required to load database information. ' . 'Please require that in your composer.json and run `composer update`.');
}
return $output;
}