setOptions($options); $this->_pluralModuleName = $this->_moduleName . (substr($this->_moduleName, -2) == 'ss' ? 'es' : substr($this->_moduleName, -1) != 's' ? 's' : ''); return $this; } /** * @param $options * @return App_Admin_Tool_Project_Context_File_Abstract */ public function setOptions($options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$key] = $value; } } return $this; } /** * @abstract * @return array */ abstract public function getContext(); /** * @param bool $abstractDirectory * @param null|string $classSuffix * @param bool $abstractFile * @return string * @throws Qs_Db_Exception */ protected function _getClassName($abstractDirectory = false, $classSuffix = null, $abstractFile = false) { if ($abstractDirectory && $abstractFile) { throw new Qs_Db_Exception('$abstractDirectory and $abstractFile can not be set simultaneously.'); } if (empty($classSuffix)) { $classSuffix = $this->_classSuffix; } if ($this->_useNamespace && $classSuffix == 'ModuleNameList') { if ($abstractDirectory) { $classSuffix = 'List'; } else { $classSuffix = $this->_moduleName . 'List'; } } if ($this->_useNamespace) { return (true === $abstractDirectory || true === $abstractFile) ? 'Abstract' . $classSuffix : $classSuffix; } $baseDirectory = $this->_baseDirectory; if ($abstractDirectory) { $baseDirectory = str_replace(DIRECTORY_SEPARATOR . 'Admin', '', $baseDirectory); $baseDirectory = str_replace(DIRECTORY_SEPARATOR . 'Abstract', '', $baseDirectory); } return str_replace(DIRECTORY_SEPARATOR, '_', $baseDirectory) . '_' . (true === $abstractDirectory ? 'Abstract_' : '') . (true === $abstractFile ? 'Abstract' : ucfirst(strtolower($classSuffix))); } /** * @param string $classBase */ public function setClassBase($classBase) { $this->_classBase = $classBase; } /** * @param string $classSuffix */ public function setClassSuffix($classSuffix) { $this->_classSuffix = $classSuffix; } /** * @param string $moduleName */ public function setModuleName($moduleName) { $this->_moduleName = $moduleName; } /** * @param string $baseDirectory */ public function setBaseDirectory($baseDirectory) { $this->_baseDirectory = $baseDirectory; } public function setUseNamespace($useNamespace) { $this->_useNamespace = $useNamespace; } protected function _getNameSpace($baseLevel = false, $prefix = '') { if ($baseLevel) { $partArray = explode(DIRECTORY_SEPARATOR, $this->_baseDirectory); foreach ($partArray as $key => $part) { if (in_array($part, ['Admin', 'Form'])) { unset($partArray[$key]); } } $namespace = $prefix . implode('\\', $partArray); } else { $namespace = $prefix . str_replace(DIRECTORY_SEPARATOR, '\\', $this->_baseDirectory); } return $namespace; } protected function _getTableAlias() { if ($this->_params['tableAlias']) { return $this->_params['tableAlias']; } else { return $this->_moduleName; } } /** * @param array $params */ public function setParams($params) { $this->_params = $params; } protected function _generateContext($classGenerator, $generateContextWithUse = false) { $fileGenerator = new FileGenerator(); if ($this->_useNamespace) { if ($generateContextWithUse) { $fileGenerator->setUse($this->_getNameSpace(true, '\\')); } $fileGenerator->setNamespace($this->_getNameSpace()); } $fileGenerator->setClass($classGenerator); return $fileGenerator->generate(); } }