public function generate(Collection $controllers, $name, $version, $includePath)
{
$this->includePath = $includePath;
$resources = $controllers->map(function ($controller) use($version) {
$controller = $controller instanceof ReflectionClass ? $controller : new ReflectionClass($controller);
$actions = new Collection();
// Spin through all the methods on the controller and compare the version
// annotation (if supplied) with the version given for the generation.
// We'll also build up an array of actions on each resource.
foreach ($controller->getMethods() as $method) {
if ($versionAnnotation = $this->reader->getMethodAnnotation($method, Annotation\Versions::class)) {
if (!in_array($version, $versionAnnotation->value)) {
continue;
}
}
if ($annotations = $this->reader->getMethodAnnotations($method)) {
if (!$actions->contains($method)) {
$actions->push(new Action($method, new Collection($annotations)));
}
}
}
$annotations = new Collection($this->reader->getClassAnnotations($controller));
return new Resource($controller->getName(), $controller, $annotations, $actions);
});
$contents = $this->generateContentsFromResources($resources, $name);
$this->includePath = null;
return $contents;
}