@@ -37,13 +37,14 @@ discard block |
||
| 37 | 37 | $verb = strtolower(trim($verb)); |
| 38 | 38 | foreach($this as $rule) |
| 39 | 39 | { |
| 40 | - if(($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0) |
|
| 41 | - return ($decision > 0); |
|
| 40 | + if(($decision = $rule->isUserAllowed($user, $verb, $ip)) !== 0) { |
|
| 41 | + return ($decision > 0); |
|
| 42 | + } |
|
| 42 | 43 | } |
| 43 | 44 | return true; |
| 45 | + } else { |
|
| 46 | + return false; |
|
| 44 | 47 | } |
| 45 | - else |
|
| 46 | - return false; |
|
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | /** |
@@ -56,9 +57,10 @@ discard block |
||
| 56 | 57 | */ |
| 57 | 58 | public function insertAt($index, $item) |
| 58 | 59 | { |
| 59 | - if($item instanceof TAuthorizationRule) |
|
| 60 | - parent::insertAt($index, $item); |
|
| 61 | - else |
|
| 62 | - throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); |
|
| 60 | + if($item instanceof TAuthorizationRule) { |
|
| 61 | + parent::insertAt($index, $item); |
|
| 62 | + } else { |
|
| 63 | + throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); |
|
| 64 | + } |
|
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | 67 | \ No newline at end of file |
@@ -112,15 +112,16 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function setRoles($value) |
| 114 | 114 | { |
| 115 | - if(is_array($value)) |
|
| 116 | - $this->setState('Roles', $value, []); |
|
| 117 | - else |
|
| 115 | + if(is_array($value)) { |
|
| 116 | + $this->setState('Roles', $value, []); |
|
| 117 | + } else |
|
| 118 | 118 | { |
| 119 | 119 | $roles = []; |
| 120 | 120 | foreach(explode(',', $value) as $role) |
| 121 | 121 | { |
| 122 | - if(($role = trim($role)) !== '') |
|
| 123 | - $roles[] = $role; |
|
| 122 | + if(($role = trim($role)) !== '') { |
|
| 123 | + $roles[] = $role; |
|
| 124 | + } |
|
| 124 | 125 | } |
| 125 | 126 | $this->setState('Roles', $roles, []); |
| 126 | 127 | } |
@@ -132,9 +133,10 @@ discard block |
||
| 132 | 133 | */ |
| 133 | 134 | public function isInRole($role) |
| 134 | 135 | { |
| 135 | - foreach($this->getRoles() as $r) |
|
| 136 | - if(strcasecmp($role, $r) === 0) |
|
| 136 | + foreach($this->getRoles() as $r) { |
|
| 137 | + if(strcasecmp($role, $r) === 0) |
|
| 137 | 138 | return true; |
| 139 | + } |
|
| 138 | 140 | return false; |
| 139 | 141 | } |
| 140 | 142 | |
@@ -152,10 +154,12 @@ discard block |
||
| 152 | 154 | */ |
| 153 | 155 | public function loadFromString($data) |
| 154 | 156 | { |
| 155 | - if(!empty($data)) |
|
| 156 | - $this->_state = unserialize($data); |
|
| 157 | - if(!is_array($this->_state)) |
|
| 158 | - $this->_state = []; |
|
| 157 | + if(!empty($data)) { |
|
| 158 | + $this->_state = unserialize($data); |
|
| 159 | + } |
|
| 160 | + if(!is_array($this->_state)) { |
|
| 161 | + $this->_state = []; |
|
| 162 | + } |
|
| 159 | 163 | return $this; |
| 160 | 164 | } |
| 161 | 165 | |
@@ -193,10 +197,11 @@ discard block |
||
| 193 | 197 | */ |
| 194 | 198 | protected function setState($key, $value, $defaultValue = null) |
| 195 | 199 | { |
| 196 | - if($value === $defaultValue) |
|
| 197 | - unset($this->_state[$key]); |
|
| 198 | - else |
|
| 199 | - $this->_state[$key] = $value; |
|
| 200 | + if($value === $defaultValue) { |
|
| 201 | + unset($this->_state[$key]); |
|
| 202 | + } else { |
|
| 203 | + $this->_state[$key] = $value; |
|
| 204 | + } |
|
| 200 | 205 | $this->_stateChanged = true; |
| 201 | 206 | } |
| 202 | 207 | |
@@ -61,11 +61,13 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function init($config) |
| 63 | 63 | { |
| 64 | - if($this->_userClass === '') |
|
| 65 | - throw new TConfigurationException('dbusermanager_userclass_required'); |
|
| 64 | + if($this->_userClass === '') { |
|
| 65 | + throw new TConfigurationException('dbusermanager_userclass_required'); |
|
| 66 | + } |
|
| 66 | 67 | $this->_userFactory = Prado::createComponent($this->_userClass, $this); |
| 67 | - if(!($this->_userFactory instanceof TDbUser)) |
|
| 68 | - throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass); |
|
| 68 | + if(!($this->_userFactory instanceof TDbUser)) { |
|
| 69 | + throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass); |
|
| 70 | + } |
|
| 69 | 71 | } |
| 70 | 72 | |
| 71 | 73 | /** |
@@ -123,9 +125,9 @@ discard block |
||
| 123 | 125 | $user = Prado::createComponent($this->_userClass, $this); |
| 124 | 126 | $user->setIsGuest(true); |
| 125 | 127 | return $user; |
| 128 | + } else { |
|
| 129 | + return $this->_userFactory->createUser($username); |
|
| 126 | 130 | } |
| 127 | - else |
|
| 128 | - return $this->_userFactory->createUser($username); |
|
| 129 | 131 | } |
| 130 | 132 | |
| 131 | 133 | /** |
@@ -171,13 +173,14 @@ discard block |
||
| 171 | 173 | if($connectionID !== '') |
| 172 | 174 | { |
| 173 | 175 | $conn = $this->getApplication()->getModule($connectionID); |
| 174 | - if($conn instanceof TDataSourceConfig) |
|
| 175 | - return $conn->getDbConnection(); |
|
| 176 | - else |
|
| 177 | - throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID); |
|
| 176 | + if($conn instanceof TDataSourceConfig) { |
|
| 177 | + return $conn->getDbConnection(); |
|
| 178 | + } else { |
|
| 179 | + throw new TConfigurationException('dbusermanager_connectionid_invalid', $connectionID); |
|
| 180 | + } |
|
| 181 | + } else { |
|
| 182 | + throw new TConfigurationException('dbusermanager_connectionid_required'); |
|
| 178 | 183 | } |
| 179 | - else |
|
| 180 | - throw new TConfigurationException('dbusermanager_connectionid_required'); |
|
| 181 | 184 | } |
| 182 | 185 | |
| 183 | 186 | /** |
@@ -199,7 +202,8 @@ discard block |
||
| 199 | 202 | public function saveUserToCookie($cookie) |
| 200 | 203 | { |
| 201 | 204 | $user = $this->getApplication()->getUser(); |
| 202 | - if($user instanceof TDbUser) |
|
| 203 | - $user->saveUserToCookie($cookie); |
|
| 205 | + if($user instanceof TDbUser) { |
|
| 206 | + $user->saveUserToCookie($cookie); |
|
| 207 | + } |
|
| 204 | 208 | } |
| 205 | 209 | } |
| 206 | 210 | \ No newline at end of file |
@@ -99,8 +99,9 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function setValidationKey($value) |
| 101 | 101 | { |
| 102 | - if('' === $value) |
|
| 103 | - throw new TInvalidDataValueException('securitymanager_validationkey_invalid'); |
|
| 102 | + if('' === $value) { |
|
| 103 | + throw new TInvalidDataValueException('securitymanager_validationkey_invalid'); |
|
| 104 | + } |
|
| 104 | 105 | |
| 105 | 106 | $this->_validationKey = $value; |
| 106 | 107 | } |
@@ -126,8 +127,9 @@ discard block |
||
| 126 | 127 | */ |
| 127 | 128 | public function setEncryptionKey($value) |
| 128 | 129 | { |
| 129 | - if('' === $value) |
|
| 130 | - throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid'); |
|
| 130 | + if('' === $value) { |
|
| 131 | + throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid'); |
|
| 132 | + } |
|
| 131 | 133 | |
| 132 | 134 | $this->_encryptionKey = $value; |
| 133 | 135 | } |
@@ -148,8 +150,9 @@ discard block |
||
| 148 | 150 | public function setHashAlgorithm($value) |
| 149 | 151 | { |
| 150 | 152 | $this->_hashAlgorithm = TPropertyValue::ensureString($value); |
| 151 | - if(!in_array($this->_hashAlgorithm, hash_algos())) |
|
| 152 | - throw new TInvalidDataValueException('securitymanager_hash_algorithm_invalid'); |
|
| 153 | + if(!in_array($this->_hashAlgorithm, hash_algos())) { |
|
| 154 | + throw new TInvalidDataValueException('securitymanager_hash_algorithm_invalid'); |
|
| 155 | + } |
|
| 153 | 156 | } |
| 154 | 157 | |
| 155 | 158 | /** |
@@ -167,8 +170,9 @@ discard block |
||
| 167 | 170 | public function setCryptAlgorithm($value) |
| 168 | 171 | { |
| 169 | 172 | $this->_cryptAlgorithm = TPropertyValue::ensureString($value); |
| 170 | - if(!in_array($this->_hashAlgorithm, openssl_get_cipher_methods())) |
|
| 171 | - throw new TInvalidDataValueException('securitymanager_crypt_algorithm_invalid'); |
|
| 173 | + if(!in_array($this->_hashAlgorithm, openssl_get_cipher_methods())) { |
|
| 174 | + throw new TInvalidDataValueException('securitymanager_crypt_algorithm_invalid'); |
|
| 175 | + } |
|
| 172 | 176 | } |
| 173 | 177 | |
| 174 | 178 | /** |
@@ -184,9 +188,9 @@ discard block |
||
| 184 | 188 | $key = md5($this->getEncryptionKey()); |
| 185 | 189 | $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->_cryptAlgorithm)); |
| 186 | 190 | return $iv . openssl_encrypt($data, $this->_cryptAlgorithm, $key, null, $iv); |
| 191 | + } else { |
|
| 192 | + throw new TNotSupportedException('securitymanager_openssl_required'); |
|
| 187 | 193 | } |
| 188 | - else |
|
| 189 | - throw new TNotSupportedException('securitymanager_openssl_required'); |
|
| 190 | 194 | } |
| 191 | 195 | |
| 192 | 196 | /** |
@@ -202,9 +206,9 @@ discard block |
||
| 202 | 206 | $key = md5($this->getEncryptionKey()); |
| 203 | 207 | $iv = $this->substr($data, 0, openssl_cipher_iv_length($this->_cryptAlgorithm)); |
| 204 | 208 | return openssl_decrypt($this->substr($data, $this->strlen($iv), $this->strlen($data)), $this->_cryptAlgorithm, $key, null, $iv); |
| 209 | + } else { |
|
| 210 | + throw new TNotSupportedException('securitymanager_openssl_required'); |
|
| 205 | 211 | } |
| 206 | - else |
|
| 207 | - throw new TNotSupportedException('securitymanager_openssl_required'); |
|
| 208 | 212 | } |
| 209 | 213 | |
| 210 | 214 | /** |
@@ -229,8 +233,9 @@ discard block |
||
| 229 | 233 | { |
| 230 | 234 | $len = $this->strlen($this->computeHMAC('test')); |
| 231 | 235 | |
| 232 | - if($this->strlen($data) < $len) |
|
| 233 | - return false; |
|
| 236 | + if($this->strlen($data) < $len) { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 234 | 239 | |
| 235 | 240 | $hmac = $this->substr($data, 0, $len); |
| 236 | 241 | $data2 = $this->substr($data, $len, $this->strlen($data)); |
@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function __construct() |
| 35 | 35 | { |
| 36 | - if (!class_exists("TActiveRecordManager", false)) |
|
| 37 | - throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); |
|
| 36 | + if (!class_exists("TActiveRecordManager", false)) { |
|
| 37 | + throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); |
|
| 38 | + } |
|
| 38 | 39 | $ar_manager = TActiveRecordManager::getInstance(); |
| 39 | 40 | $_conn = $ar_manager->getDbConnection(); |
| 40 | 41 | $_conn->Active = true; |
@@ -44,10 +45,12 @@ discard block |
||
| 44 | 45 | public function setOpFile($op_file_namespace) |
| 45 | 46 | { |
| 46 | 47 | $op_file = Prado::getPathOfNamespace($op_file_namespace); |
| 47 | - if (empty($op_file)) |
|
| 48 | - throw new Exception("You need to fix your output folder namespace."); |
|
| 49 | - if (!is_dir($op_file)) |
|
| 50 | - mkdir($op_file, 0777, true); |
|
| 48 | + if (empty($op_file)) { |
|
| 49 | + throw new Exception("You need to fix your output folder namespace."); |
|
| 50 | + } |
|
| 51 | + if (!is_dir($op_file)) { |
|
| 52 | + mkdir($op_file, 0777, true); |
|
| 53 | + } |
|
| 51 | 54 | $this->_opFile = $op_file; |
| 52 | 55 | } |
| 53 | 56 | |
@@ -68,8 +71,9 @@ discard block |
||
| 68 | 71 | { |
| 69 | 72 | $tableNames = $this->_dbMetaData->findTableNames(); |
| 70 | 73 | $index = array_search('pradocache', $tableNames); |
| 71 | - if ($index) |
|
| 72 | - array_splice($tableNames, $index, 1); |
|
| 74 | + if ($index) { |
|
| 75 | + array_splice($tableNames, $index, 1); |
|
| 76 | + } |
|
| 73 | 77 | return $tableNames; |
| 74 | 78 | } |
| 75 | 79 | |
@@ -71,8 +71,10 @@ discard block |
||
| 71 | 71 | if (!empty($this->_relations)) |
| 72 | 72 | { |
| 73 | 73 | // Cancel generation of M-M relationships middle table |
| 74 | - if (count($tableInfo->getPrimaryKeys()) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships |
|
| 74 | + if (count($tableInfo->getPrimaryKeys()) === 2 && count($tableInfo->getColumns()) === 2) { |
|
| 75 | + //M-M relationships |
|
| 75 | 76 | continue; |
| 77 | + } |
|
| 76 | 78 | } |
| 77 | 79 | $this->_commonGenerate($tableName, $tableInfo); |
| 78 | 80 | } |
@@ -87,9 +89,11 @@ discard block |
||
| 87 | 89 | $pks = $tableInfo->getPrimaryKeys(); |
| 88 | 90 | $fks = $tableInfo->getForeignKeys(); |
| 89 | 91 | |
| 90 | - if (count($pks) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships |
|
| 92 | + if (count($pks) === 2 && count($tableInfo->getColumns()) === 2) { |
|
| 93 | + //M-M relationships |
|
| 91 | 94 | { |
| 92 | 95 | $table_name_mm = $fks[0]["table"]; |
| 96 | + } |
|
| 93 | 97 | $table_name_mm2 = $fks[1]["table"]; |
| 94 | 98 | |
| 95 | 99 | $this->_relations[$table_name_mm][] = [ |
@@ -107,9 +111,11 @@ discard block |
||
| 107 | 111 | ]; |
| 108 | 112 | continue; |
| 109 | 113 | } |
| 110 | - foreach ($fks as $fk_data)//1-M relationships |
|
| 114 | + foreach ($fks as $fk_data) { |
|
| 115 | + //1-M relationships |
|
| 111 | 116 | { |
| 112 | 117 | $owner_table = $fk_data["table"]; |
| 118 | + } |
|
| 113 | 119 | $slave_table = $table_name; |
| 114 | 120 | $fk_prop = key($fk_data["keys"]); |
| 115 | 121 | |
@@ -136,13 +142,14 @@ discard block |
||
| 136 | 142 | |
| 137 | 143 | private function _commonGenerate($tableName, $tableInfo) |
| 138 | 144 | { |
| 139 | - if (count($tableInfo->getColumns()) === 0) |
|
| 140 | - throw new Exception("Unable to find table or view $tableName in " . $this->_dbMetaData->getDbConnection()->getConnectionString() . "."); |
|
| 141 | - else |
|
| 145 | + if (count($tableInfo->getColumns()) === 0) { |
|
| 146 | + throw new Exception("Unable to find table or view $tableName in " . $this->_dbMetaData->getDbConnection()->getConnectionString() . "."); |
|
| 147 | + } else |
|
| 142 | 148 | { |
| 143 | 149 | $properties = []; |
| 144 | - foreach ($tableInfo->getColumns() as $field => $metadata) |
|
| 145 | - $properties[] = $this->generateProperty($field, $metadata); |
|
| 150 | + foreach ($tableInfo->getColumns() as $field => $metadata) { |
|
| 151 | + $properties[] = $this->generateProperty($field, $metadata); |
|
| 152 | + } |
|
| 146 | 153 | $toString = $this->_buildSmartToString($tableInfo); |
| 147 | 154 | } |
| 148 | 155 | |
@@ -175,12 +182,14 @@ discard block |
||
| 175 | 182 | |
| 176 | 183 | private function _renderRelations($tablename) |
| 177 | 184 | { |
| 178 | - if (!isset($this->_relations[$tablename])) |
|
| 179 | - return ""; |
|
| 185 | + if (!isset($this->_relations[$tablename])) { |
|
| 186 | + return ""; |
|
| 187 | + } |
|
| 180 | 188 | |
| 181 | 189 | $code = "\tpublic static \$RELATIONS = array ("; |
| 182 | - foreach ($this->_relations[$tablename] as $rel_data) |
|
| 183 | - $code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),"; |
|
| 190 | + foreach ($this->_relations[$tablename] as $rel_data) { |
|
| 191 | + $code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),"; |
|
| 192 | + } |
|
| 184 | 193 | |
| 185 | 194 | $code = substr($code, 0, -1); |
| 186 | 195 | $code .= "\n\t);"; |
@@ -195,9 +204,9 @@ discard block |
||
| 195 | 204 | { |
| 196 | 205 | foreach ($tableInfo->getColumns() as $column) |
| 197 | 206 | { |
| 198 | - if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) |
|
| 199 | - $property = str_replace($this->uqChars, "", $column->ColumnName); |
|
| 200 | - elseif ($column->PdoType == PDO::PARAM_STR && $column->DBType != "date") |
|
| 207 | + if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) { |
|
| 208 | + $property = str_replace($this->uqChars, "", $column->ColumnName); |
|
| 209 | + } elseif ($column->PdoType == PDO::PARAM_STR && $column->DBType != "date") |
|
| 201 | 210 | { |
| 202 | 211 | $property = str_replace($this->uqChars, "", $column->ColumnName); |
| 203 | 212 | break; |
@@ -48,11 +48,13 @@ |
||
| 48 | 48 | |
| 49 | 49 | public function init($config) |
| 50 | 50 | { |
| 51 | - if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) |
|
| 52 | - throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); |
|
| 51 | + if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) { |
|
| 52 | + throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | - if (empty($this->_pass)) |
|
| 55 | - throw new TConfigurationException("You need to specify the Password attribute."); |
|
| 55 | + if (empty($this->_pass)) { |
|
| 56 | + throw new TConfigurationException("You need to specify the Password attribute."); |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | $this->setDefaultPage("TWsatHome"); |
| 58 | 60 | $this->_startThemeManager(); |
@@ -37,13 +37,15 @@ |
||
| 37 | 37 | $ar_generator->setClasPrefix($classPrefix); |
| 38 | 38 | $ar_generator->setClassSufix($classSuffix); |
| 39 | 39 | |
| 40 | - if ($this->build_rel->Checked) |
|
| 41 | - $ar_generator->buildRelations(); |
|
| 40 | + if ($this->build_rel->Checked) { |
|
| 41 | + $ar_generator->buildRelations(); |
|
| 42 | + } |
|
| 42 | 43 | |
| 43 | - if ($tableName != "*") |
|
| 44 | - $ar_generator->generate($tableName); |
|
| 45 | - else |
|
| 46 | - $ar_generator->generateAll(); |
|
| 44 | + if ($tableName != "*") { |
|
| 45 | + $ar_generator->generate($tableName); |
|
| 46 | + } else { |
|
| 47 | + $ar_generator->generateAll(); |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | $this->feedback_panel->CssClass = "green_panel"; |
| 49 | 51 | $this->generation_msg->Text = "The code has been generated successfully."; |
@@ -98,8 +98,9 @@ |
||
| 98 | 98 | */ |
| 99 | 99 | public function publishAsset($assetPath, $className = null) |
| 100 | 100 | { |
| 101 | - if($className === null) |
|
| 102 | - $className = get_class($this); |
|
| 101 | + if($className === null) { |
|
| 102 | + $className = get_class($this); |
|
| 103 | + } |
|
| 103 | 104 | $class = new \ReflectionClass($className); |
| 104 | 105 | $fullPath = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . $assetPath; |
| 105 | 106 | return $this->publishFilePath($fullPath); |