/** * @param ModuleEntity $moduleEntity * @param ModuleUtils $modules * @param ConfigResource $config */ public function __construct(ModuleEntity $moduleEntity, ModuleUtils $modules, ConfigResource $config) { $this->module = $moduleEntity->getName(); $this->moduleEntity = $moduleEntity; $this->modules = $modules; $this->configResource = $config; $this->modulePath = $modules->getModulePath($this->module); }
protected function getDocsConfig($module) { $moduleConfigPath = $this->moduleUtils->getModuleConfigPath($module); $docConfigPath = dirname($moduleConfigPath) . '/documentation.config.php'; if (!file_exists($docConfigPath)) { return null; } $documentation = (include $docConfigPath); return $this->configFactory->createConfigResource($documentation, $docConfigPath); }
/** * Retrieve a ConfigResource for a given module * * @param string $moduleName * @return ConfigResource */ public function factory($moduleName) { $moduleName = $this->normalizeModuleName($moduleName); if (isset($this->resources[$moduleName])) { return $this->resources[$moduleName]; } $moduleConfigPath = $this->modules->getModuleConfigPath($moduleName); $config = (include $moduleConfigPath); $this->resources[$moduleName] = new ConfigResource($config, $moduleConfigPath, $this->writer); return $this->resources[$moduleName]; }
/** * @param $module * @return \ZF\Configuration\ConfigResource */ protected function getDocumentationConfigResource($module) { $moduleConfigPath = $this->moduleUtils->getModuleConfigPath($module); $docConfigPath = dirname($moduleConfigPath) . '/documentation.config.php'; $docArray = file_exists($docConfigPath) ? include $docConfigPath : []; return $this->configFactory->createConfigResource($docArray, $docConfigPath); }
/** * Create a controller in the current module named for the given service * * @param string $serviceName * @return stdClass */ public function createController($serviceName) { $module = $this->module; $modulePath = $this->modules->getModulePath($module); $version = $this->moduleEntity->getLatestVersion(); $serviceName = str_replace("\\", "/", $serviceName); $srcPath = $this->modules->getRpcPath($module, $version, $serviceName); if (!file_exists($srcPath)) { mkdir($srcPath, 0775, true); } $className = sprintf('%sController', $serviceName); $classPath = sprintf('%s/%s.php', $srcPath, $className); $controllerService = sprintf('%s\\V%s\\Rpc\\%s\\Controller', $module, $version, $serviceName); if (file_exists($classPath)) { throw new Exception\RuntimeException(sprintf('The controller "%s" already exists', $className), 409); } $view = new ViewModel(['module' => $module, 'classname' => $className, 'servicename' => $serviceName, 'version' => $version]); $resolver = new Resolver\TemplateMapResolver(['code-connected/rpc-controller' => __DIR__ . '/../../view/code-connected/rpc-controller.phtml']); $view->setTemplate('code-connected/rpc-controller'); $renderer = new PhpRenderer(); $renderer->setResolver($resolver); if (!file_put_contents($classPath, "<" . "?php\n" . $renderer->render($view))) { return false; } $fullClassFactory = $this->createFactoryController($serviceName); $this->configResource->patch(['controllers' => ['factories' => [$controllerService => $fullClassFactory]]], true); $fullClassName = sprintf('%s\\V%s\\Rpc\\%s\\%s', $module, $version, $serviceName, $className); return (object) ['class' => $fullClassName, 'file' => $classPath, 'service' => $controllerService]; }
/** * Get the source path for the module * * @param string $serviceName * @return string */ protected function getSourcePath($serviceName) { $sourcePath = $this->modules->getRestPath($this->module, $this->moduleEntity->getLatestVersion(), $serviceName); if (!file_exists($sourcePath)) { mkdir($sourcePath, 0775, true); } return $sourcePath; }
/** * Returns the path for the module name that is specified. * * @param $moduleName * @return string */ public function getModulePath($moduleName) { // see if we can get the path from ModuleUtils, if module isn't set will throw exception try { $modulePath = $this->modules->getModulePath($moduleName); } catch (\Exception $e) { $modulePath = sprintf($this->modulePathSpec, $this->applicationPath, $moduleName); } return $modulePath; }
/** * Retrieve the documentation for a given API module * * @param string $apiName * @return array */ protected function getDocumentationConfig($apiName) { if (isset($this->docs[$apiName])) { return $this->docs[$apiName]; } $moduleConfigPath = $this->configModuleUtils->getModuleConfigPath($apiName); $docConfigPath = dirname($moduleConfigPath) . '/documentation.config.php'; if (file_exists($docConfigPath)) { $this->docs[$apiName] = (include $docConfigPath); } else { $this->docs[$apiName] = []; } return $this->docs[$apiName]; }