/** * Build the controller * * @return string * @throws \Exception */ public function build() { if (!is_dir($this->_options['directory']) || $this->_options['force'] == true) { if (!is_dir($this->_options['directory'])) { if (!@mkdir($this->_options['directory'])) { throw new \Exception("Unable to create module directory!"); } @chmod($this->_options['directory'], 0777); } } else { throw new \Exception("Module directory already exists!"); } if (!is_dir($this->_options['directory'] . Tools::getControllersDir())) { if (!@mkdir($this->_options['directory'] . Tools::getControllersDir())) { throw new \Exception("Unable to create controller directory!"); } @chmod($this->_options['directory'] . Tools::getControllersDir(), 0777); } $controller = new Controller(array('module' => $this->_options['name'], 'name' => 'IndexController', 'namespace' => null, 'baseClass' => current(Tools::getBaseController()), 'directory' => $this->_options['directory'] . DIRECTORY_SEPARATOR . Tools::getControllersDir(), 'force' => $this->_options['force'])); $controller->build(); if (!is_dir($this->_options['directory'] . Tools::getModelsDir())) { if (!@mkdir($this->_options['directory'] . Tools::getModelsDir())) { throw new \Exception("Unable to create model directory!"); } @chmod($this->_options['directory'] . Tools::getModelsDir(), 0777); } if (!is_dir($this->_options['directory'] . Tools::getFormsDir())) { if (!@mkdir($this->_options['directory'] . Tools::getFormsDir())) { throw new \Exception("Unable to create form directory!"); } @chmod($this->_options['directory'] . Tools::getFormsDir(), 0777); } if (!is_dir($this->_options['directory'] . Tools::getViewsDir())) { if (!@mkdir($this->_options['directory'] . Tools::getViewsDir())) { throw new \Exception("Unable to create controller directory!"); } @chmod($this->_options['directory'] . Tools::getViewsDir(), 0777); } $view = new View(array('name' => 'IndexController', 'module' => $this->_options['name'], 'force' => $this->_options['force'])); $view->build(); if ($this->_options['routes']) { $this->_createRoute(); } $this->_createModule(); }
/** * Generate controller using scaffold * * @param array $options */ private function _makeController($options) { $controllerPath = $options['controllersDir'] . $options['className'] . 'Controller.php'; if (!is_dir($options['controllersDir'])) { if (!mkdir($options['controllersDir'])) { return; } @chmod($options['controllersDir'], 0777); } if (file_exists($controllerPath)) { if (!$options['force']) { return; } } $path = $options['templatePath'] . '/scaffold/no-forms/Controller.php'; $code = file_get_contents($path); $code = str_replace('$modelClass$', $options['modelClass'], $code); if (Tools::getCopyright() == null) { $code = str_replace('$copyright$', '', $code); } else { $code = str_replace('$copyright$', PHP_EOL . Tools::getCopyright() . PHP_EOL, $code); } if (isset($options['controllersNamespace']) === true) { $code = str_replace('$namespace$', 'namespace ' . $options['controllersNamespace'] . ';', $code); } else { $code = str_replace('$namespace$', ' ', $code); } $code = str_replace('$singularVar$', '$' . $options['singular'], $code); $code = str_replace('$singular$', $options['singular'], $code); $code = str_replace('$pluralVar$', '$' . $options['plural'], $code); $code = str_replace('$plural$', $options['plural'], $code); $code = str_replace('$className$', $options['className'], $code); $code = str_replace('$package$', $options['controllersNamespace'], $code); $code = str_replace('$controllerClass$', Tools::getBaseController()[0], $code); $explodeController = explode('\\', Tools::getBaseController()[0]); $code = str_replace('$controllerName$', array_pop($explodeController), $code); $code = str_replace('$assignInputFromRequestCreate$', $this->_captureFilterInput($options['singular'], $options['dataTypes'], $options['genSettersGetters'], $options['identityField']), $code); $code = str_replace('$assignInputFromRequestUpdate$', $this->_captureFilterInput($options['singular'], $options['dataTypes'], $options['genSettersGetters'], $options['identityField']), $code); $code = str_replace('$assignTagDefaults$', $this->_assignTagDefaults($options['singular'], $options['dataTypes'], $options['genSettersGetters']), $code); $code = str_replace('$pkVar$', '$' . $options['attributes'][0], $code); $code = str_replace('$pkFind$', Text::camelize($options['attributes'][0]), $code); $code = str_replace('$pk$', $options['attributes'][0], $code); $code = str_replace("\t", " ", $code); file_put_contents($controllerPath, $code); @chmod($controllerPath, 0777); }