private function scanBundle(Bundle $bundle, BundleService $bundleService) { $bundleService->addBundle($bundle); if ($bundle->hasBundles()) { $rootNamespace = $bundle->getNamespace(); $rootDir = $bundle->getBundlesDir(); $bundles = Chain::create(scandir($bundle->getBundlesDir()))->filter(function (string $dir) use($rootDir) { return $dir != '.' && $dir != '..' && is_dir($rootDir . '/' . $dir); })->map(function (string $dir) use($rootNamespace) { $bundleClassName = "{$rootNamespace}\\{$dir}\\{$dir}Bundle"; if (!class_exists($bundleClassName)) { $bundleClassName = "{$rootNamespace}\\Bundles\\{$dir}\\{$dir}Bundle"; if (!class_exists($bundleClassName)) { throw new \Exception(sprintf('No Bundle available for bundle `%s`', $bundleClassName)); } } if (!is_subclass_of($bundleClassName, Bundle::class)) { throw new \Exception(sprintf('Bundle `%s` should implements interface %s', $bundleClassName, Bundle::class)); } return new $bundleClassName(); })->array; foreach ($bundles as $bundle) { $this->scanBundle($bundle, $bundleService); } } }
private function createAPIDocsBuilderRequest() { $apiDocsBuilderRequest = new APIDocsBuilderRequest(); foreach ($this->bundlesService->getBundles() as $bundle) { if (in_array(get_class($bundle), $this->excludedBundles)) { continue; } if ($bundle->hasAPIDocsDir()) { $apiDocsBuilderRequest->addDirectory($bundle->getAPIDocsDir()); } } return $apiDocsBuilderRequest; }
public function fetch(Filter $filter) : array { $result = []; $scripts = Chain::create($this->bundlesService->getBundles())->filter(function (Bundle $bundle) { return $bundle instanceof FrontlineBundleInjectable; })->map(function (FrontlineBundleInjectable $bundle) { return $bundle->getFrontlineScripts(); })->reduce(function (array $carry, array $scripts) { return array_merge($carry, $scripts); }, []); $scripts = array_map(function (string $script) { return $this->container->get($script); }, $scripts); foreach ($filter->filter($scripts) as $script) { if ($script instanceof FrontlineScript) { $result = array_merge_recursive($result, $script()); } else { throw new \Exception(); } } return $result; }
private function fetchSchema($bundleName, $path) : JSONSchema { $bundle = $this->bundleService->getBundleByName($bundleName); if (!$bundle->hasAPIDocsDir()) { throw new NoAPIDocsAvailableException(sprintf('No API docs available for bundle `%s`', $bundle->getName())); } $apiFile = "{$bundle->getAPIDocsDir()}/{$path}"; if (!file_exists($apiFile)) { throw new SchemaFileNotExists(sprintf('Schema file `%s` not found', $apiFile)); } $yaml = Yaml::parse(file_get_contents($apiFile)); $yaml = array_pop($yaml); $yaml = json_decode(json_encode($yaml)); return new JSONSchema($yaml); }