/** * Create a controller in the current module named for the given service * * @param string $serviceName * @return mixed */ public function createController($serviceName) { $module = $this->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)); } $view = new ViewModel(array('module' => $module, 'classname' => $className, 'servicename' => $serviceName, 'version' => $version)); $resolver = new Resolver\TemplateMapResolver(array('code-connected/rpc-controller' => __DIR__ . '/../../../view/doctrine/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; } $fullClassName = sprintf('%s\\V%s\\Rpc\\%s\\%s', $module, $version, $serviceName, $className); $this->configResource->patch(array('controllers' => array('invokables' => array($controllerService => $fullClassName))), true); return (object) array('class' => $fullClassName, 'file' => $classPath, 'service' => $controllerService); }
/** * Get the source path for the module * * @param string $resourceName * @return string */ protected function getSourcePath($resourceName) { $sourcePath = $this->modules->getRestPath($this->module, $this->moduleEntity->getLatestVersion(), $resourceName); if (!file_exists($sourcePath)) { mkdir($sourcePath, 0777, true); } return $sourcePath; }
/** * Get the source path for the module * * @param string $serviceName * @return string */ protected function getSourcePath($serviceName) { $sourcePath = sprintf('%s/src/%s/V%s/Rest/%s', $this->modulePath, str_replace('\\', '/', $this->module), $this->moduleEntity->getLatestVersion(), $serviceName); if (!file_exists($sourcePath)) { mkdir($sourcePath, 0775, true); } return $sourcePath; }
/** * Create the mediatype for this * * Based on the module and the latest module version. * * @return string */ public function createMediaType() { return sprintf( 'application/vnd.%s.v%s+json', $this->normalize($this->module), $this->moduleEntity->getLatestVersion() ); }