From 96957c384a549a5cf7ad9c0e330307cc362a1c09 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 26 Nov 2013 10:32:35 -0500 Subject: Adjusting to PRADO code style... --- framework/Wsat/TWsatARGenerator.php | 111 ++++++++++++++++++------------ framework/Wsat/TWsatService.php | 30 ++++---- framework/Wsat/pages/TWsatGenerateAR.php | 31 +++++---- framework/Wsat/pages/TWsatHome.php | 11 ++- framework/Wsat/pages/TWsatLogin.php | 20 +++--- framework/Wsat/pages/TWsatScaffolding.php | 11 ++- 6 files changed, 121 insertions(+), 93 deletions(-) (limited to 'framework/Wsat') diff --git a/framework/Wsat/TWsatARGenerator.php b/framework/Wsat/TWsatARGenerator.php index ed873358..a4846306 100644 --- a/framework/Wsat/TWsatARGenerator.php +++ b/framework/Wsat/TWsatARGenerator.php @@ -9,7 +9,8 @@ * @since 3.3 * @package Wsat */ -class TWsatARGenerator { +class TWsatARGenerator +{ /** * Gets the current Db connection, the connection object is obtained from @@ -49,7 +50,8 @@ class TWsatARGenerator { */ private $uq_chars = array('[', ']', '"', '`', "'"); - function __construct() { + function __construct() + { $ar_manager = TActiveRecordManager::getInstance(); $this->_conn = $ar_manager->getDbConnection(); $this->_conn->Active = true; @@ -60,37 +62,42 @@ class TWsatARGenerator { * Destructor. * Disconnect the db connection. */ - public function __destruct() { + public function __destruct() + { if ($this->_conn !== null) $this->_conn->Active = false; } - public function setOpFile($op_file_namespace) { + public function setOpFile($op_file_namespace) + { $op_file = Prado::getPathOfNamespace($op_file_namespace); - if (empty($op_file)) { + if (empty($op_file)) throw new Exception("You need to fix your output folder namespace."); - } - if (!is_dir($op_file)) { + if (!is_dir($op_file)) mkdir($op_file, 0777, true); - } $this->_op_file = $op_file; } - public function setClasPrefix($_clas_prefix) { + public function setClasPrefix($_clas_prefix) + { $this->_clas_prefix = $_clas_prefix; } - public function setClassSufix($_clas_sufix) { + public function setClassSufix($_clas_sufix) + { $this->_class_sufix = $_clas_sufix; } //----------------------------------------------------------------------------- // - public function generate($tableName) { + public function generate($tableName) + { $tableInfo = $this->_gateway->getTableInfo($this->_conn, $tableName); - if (count($tableInfo->getColumns()) === 0) { + if (count($tableInfo->getColumns()) === 0) + { throw new Exception("Unable to find table or view $tableName in " . $this->_conn->getConnectionString() . "."); - } else { + } else + { $properties = array(); foreach ($tableInfo->getColumns() as $field => $column) $properties[] = $this->generateProperty($field, $column); @@ -103,20 +110,26 @@ class TWsatARGenerator { file_put_contents($output, $class); } - public function generateAll() { - foreach ($this->_getAllTableNames() as $tableName) { - if ($tableName == "pradocache") { + public function generateAll() + { + foreach ($this->_getAllTableNames() as $tableName) + { + if ($tableName == "pradocache") + { continue; } $this->generate($tableName); } } - public function buildRelations() { + public function buildRelations() + { $this->_relations = array(); - foreach ($this->_getAllTableNames() as $table_name) { + foreach ($this->_getAllTableNames() as $table_name) + { $tableInfo = $this->_gateway->getTableInfo($this->_conn, $table_name); - foreach ($tableInfo->getForeignKeys() as $fk_data) { + foreach ($tableInfo->getForeignKeys() as $fk_data) + { $owner_table = $fk_data["table"]; $slave_table = $table_name; $fk_prop = key($fk_data["keys"]); @@ -142,25 +155,28 @@ class TWsatARGenerator { //----------------------------------------------------------------------------- // - private function _getAllTableNames() { + private function _getAllTableNames() + { $command = $this->_conn->createCommand("Show Tables"); $dataReader = $command->query(); $dataReader->bindColumn(1, $table); $tables = array(); - while ($dataReader->read()) { + while ($dataReader->read()) $tables[] = $table; - } return $tables; } - private function _getProperClassName($tableName) { + private function _getProperClassName($tableName) + { $table_name_words = str_replace("_", " ", strtolower($tableName)); $final_conversion = str_replace(" ", "", ucwords($table_name_words)); return $this->_clas_prefix . $final_conversion . $this->_class_sufix; } - public function renderAllTablesInformation() { - foreach ($this->_getAllTableNames() as $table_name) { + public function renderAllTablesInformation() + { + foreach ($this->_getAllTableNames() as $table_name) + { echo $table_name . "
"; $tableInfo = $this->_gateway->getTableInfo($this->_conn, $table_name); @@ -173,7 +189,8 @@ class TWsatARGenerator { //----------------------------------------------------------------------------- - protected function generateProperty($field, $column) { + protected function generateProperty($field, $column) + { $prop = ''; $name = '$' . $field; @@ -184,40 +201,47 @@ class TWsatARGenerator { return $prop; } - private function _renderRelations($tablename) { - if (!isset($this->_relations[$tablename])) { + private function _renderRelations($tablename) + { + if (!isset($this->_relations[$tablename])) return ""; - } + $code = "\tpublic static \$RELATIONS = array ("; - foreach ($this->_relations[$tablename] as $rel_data) { + foreach ($this->_relations[$tablename] as $rel_data) $code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),"; - } + $code = substr($code, 0, -1); $code .= "\n\t);"; return $code; } - private function _buildSmartToString($tableInfo) { + private function _buildSmartToString($tableInfo) + { $code = "\tpublic function __toString() {"; $property = "throw new THttpException(500, 'Not implemented yet.');"; - try { - foreach ($tableInfo->getColumns() as $column) { - if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) { + try + { + foreach ($tableInfo->getColumns() as $column) + { + if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) $property = str_replace($this->uq_chars, "", $column->ColumnName); - } elseif ($column->PHPType == "string" && $column->DBType != "date") { + elseif ($column->PHPType == "string" && $column->DBType != "date") + { $property = str_replace($this->uq_chars, "", $column->ColumnName); break; } } - } catch (Exception $ex) { - + } catch (Exception $ex) + { + Prado::trace($ex->getMessage()); } $code .= "\n\t\treturn \$this->$property;"; $code .= "\n\t}"; return $code; } - protected function generateClass($properties, $tablename, $classname, $toString) { + protected function generateClass($properties, $tablename, $classname, $toString) + { $props = implode("\n", $properties); $relations = $this->_renderRelations($tablename); $date = date('Y-m-d h:i:s'); @@ -227,8 +251,8 @@ class TWsatARGenerator { * Auto generated by PRADO - WSAT on $date. * @author prado_user_name */ -class $classname extends TActiveRecord { - +class $classname extends TActiveRecord +{ const TABLE='$tablename'; $props @@ -241,11 +265,8 @@ $relations $toString } -?> EOD; } //
-} - -?> +} \ No newline at end of file diff --git a/framework/Wsat/TWsatService.php b/framework/Wsat/TWsatService.php index f2d852ea..5aa86dbd 100644 --- a/framework/Wsat/TWsatService.php +++ b/framework/Wsat/TWsatService.php @@ -33,29 +33,33 @@ * * Warning: You should only use Wsat in development mode. */ -class TWsatService extends TPageService { +class TWsatService extends TPageService +{ private $_pass = ''; //----------------------------------------------------------------------------- - public function init($config) { - if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) { + public function init($config) + { + if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); - } - if (empty($this->_pass)) { + + if (empty($this->_pass)) throw new TConfigurationException("You need to specify the Password attribute."); - } + $this->setDefaultPage("TWsatHome"); $this->_startThemeManager(); parent::init($config); } - public function getBasePath() { + public function getBasePath() + { $basePath = Prado::getPathOfNamespace("System.Wsat.pages"); return realpath($basePath); } - private function _startThemeManager() { + private function _startThemeManager() + { $themeManager = new TThemeManager; $themeManager->BasePath = "System.Wsat.themes"; $url = Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); @@ -65,14 +69,14 @@ class TWsatService extends TPageService { $this->setThemeManager($themeManager); } - public function getPassword() { + public function getPassword() + { return $this->_pass; } - public function setPassword($_pass) { + public function setPassword($_pass) + { $this->_pass = $_pass; } -} - -?> +} \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatGenerateAR.php b/framework/Wsat/pages/TWsatGenerateAR.php index d5934686..14e14983 100644 --- a/framework/Wsat/pages/TWsatGenerateAR.php +++ b/framework/Wsat/pages/TWsatGenerateAR.php @@ -11,32 +11,40 @@ */ Prado::using("System.Wsat.TWsatARGenerator"); -class TWsatGenerateAR extends TPage { +class TWsatGenerateAR extends TPage +{ - public function generate($sender) { - if ($this->IsValid) { + public function generate($sender) + { + if ($this->IsValid) + { $table_name = $this->table_name->Text; $output_folder_ns = $this->output_folder->Text; $class_prefix = $this->class_prefix->Text; $class_sufix = $this->class_sufix->Text; - try { + try + { $ar_generator = new TWsatARGenerator(); $ar_generator->setOpFile($output_folder_ns); $ar_generator->setClasPrefix($class_prefix); $ar_generator->setClassSufix($class_sufix); - if ($this->build_rel->Checked) { + if ($this->build_rel->Checked) + { $ar_generator->buildRelations(); } - if ($table_name != "*") { + if ($table_name != "*") + { $ar_generator->generate($table_name); - } else { + } else + { $ar_generator->generateAll(); } $this->feedback_panel->CssClass = "green_panel"; $this->generation_msg->Text = "The code has been generated successfully."; - } catch (Exception $ex) { + } catch (Exception $ex) + { $this->feedback_panel->CssClass = "red_panel"; $this->generation_msg->Text = $ex->getMessage(); } @@ -44,12 +52,11 @@ class TWsatGenerateAR extends TPage { } } - public function preview($sender) { + public function preview($sender) + { // $ar_generator = new TWsatARGenerator(); // $ar_generator->renderAllTablesInformation(); throw new THttpException(500, "Not implemented yet."); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatHome.php b/framework/Wsat/pages/TWsatHome.php index 035dd7c6..c5291ed7 100644 --- a/framework/Wsat/pages/TWsatHome.php +++ b/framework/Wsat/pages/TWsatHome.php @@ -9,12 +9,9 @@ * @since 3.3 * @package Wsat.pages */ - Prado::using("System.Wsat.TWsatARGenerator"); -class TWsatHome extends TPage { - - -} - -?> \ No newline at end of file +class TWsatHome extends TPage +{ + +} \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatLogin.php b/framework/Wsat/pages/TWsatLogin.php index 7c4570af..4b3ba0c1 100644 --- a/framework/Wsat/pages/TWsatLogin.php +++ b/framework/Wsat/pages/TWsatLogin.php @@ -9,28 +9,30 @@ * @since 3.3 * @package Wsat.pages */ +class TWsatLogin extends TPage +{ -class TWsatLogin extends TPage { - - public function login() { - if ($this->IsValid) { + public function login() + { + if ($this->IsValid) + { $this->Session["wsat_password"] = $this->getService()->getPassword(); $authManager = $this->Application->getModule('auth'); $url = $authManager->ReturnUrl; - if (empty($url)) { + if (empty($url)) + { $url = $this->Service->constructUrl('TWsatHome'); } $this->Response->redirect($url); } } - public function validatePassword($sender, $param) { + public function validatePassword($sender, $param) + { $config_pass = $this->getService()->getPassword(); $user_pass = $this->password->Text; $param->IsValid = $user_pass === $config_pass; } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatScaffolding.php b/framework/Wsat/pages/TWsatScaffolding.php index 2fc036ad..b8e28b03 100644 --- a/framework/Wsat/pages/TWsatScaffolding.php +++ b/framework/Wsat/pages/TWsatScaffolding.php @@ -9,12 +9,9 @@ * @since 3.3 * @package Wsat.pages */ - Prado::using("System.Wsat.TWsatARGenerator"); -class TWsatScaffolding extends TPage { - - -} - -?> \ No newline at end of file +class TWsatScaffolding extends TPage +{ + +} \ No newline at end of file -- cgit v1.2.3