@@ -77,6 +77,7 @@ |
||
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Saves the current SqlMap manager to cache. |
| 80 | + * @param TSqlMapManager $manager |
|
| 80 | 81 | * @return boolean true if SqlMap manager was cached, false otherwise. |
| 81 | 82 | */ |
| 82 | 83 | protected function cacheSqlMapManager($manager) |
@@ -24,19 +24,19 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | private $_configFile; |
| 26 | 26 | private $_sqlmap; |
| 27 | - private $_enableCache=false; |
|
| 27 | + private $_enableCache = false; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * File extension of external configuration file |
| 31 | 31 | */ |
| 32 | - const CONFIG_FILE_EXT='.xml'; |
|
| 32 | + const CONFIG_FILE_EXT = '.xml'; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @return string module ID + configuration file path. |
| 36 | 36 | */ |
| 37 | 37 | private function getCacheKey() |
| 38 | 38 | { |
| 39 | - return $this->getID().$this->getConfigFile(); |
|
| 39 | + return $this->getID() . $this->getConfigFile(); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function clearCache() |
| 46 | 46 | { |
| 47 | 47 | $cache = $this->getApplication()->getCache(); |
| 48 | - if($cache !== null) { |
|
| 48 | + if ($cache !== null) { |
|
| 49 | 49 | $cache->delete($this->getCacheKey()); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function getSqlMapManager() { |
| 62 | 62 | Prado::using('System.Data.SqlMap.TSqlMapManager'); |
| 63 | - if(($manager = $this->loadCachedSqlMapManager())===null) |
|
| 63 | + if (($manager = $this->loadCachedSqlMapManager()) === null) |
|
| 64 | 64 | { |
| 65 | 65 | $manager = new TSqlMapManager($this->getDbConnection()); |
| 66 | - if(strlen($file=$this->getConfigFile()) > 0) |
|
| 66 | + if (strlen($file = $this->getConfigFile()) > 0) |
|
| 67 | 67 | { |
| 68 | 68 | $manager->configureXml($file); |
| 69 | 69 | $this->cacheSqlMapManager($manager); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - elseif($this->getConnectionID() !== '') { |
|
| 72 | + elseif ($this->getConnectionID() !== '') { |
|
| 73 | 73 | $manager->setDbConnection($this->getDbConnection()); |
| 74 | 74 | } |
| 75 | 75 | return $manager; |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | protected function cacheSqlMapManager($manager) |
| 83 | 83 | { |
| 84 | - if($this->getEnableCache()) |
|
| 84 | + if ($this->getEnableCache()) |
|
| 85 | 85 | { |
| 86 | 86 | $cache = $this->getApplication()->getCache(); |
| 87 | - if($cache !== null) { |
|
| 87 | + if ($cache !== null) { |
|
| 88 | 88 | $dependencies = null; |
| 89 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 89 | + if ($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 90 | 90 | $dependencies = $manager->getCacheDependencies(); |
| 91 | 91 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
| 92 | 92 | } |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | protected function loadCachedSqlMapManager() |
| 102 | 102 | { |
| 103 | - if($this->getEnableCache()) |
|
| 103 | + if ($this->getEnableCache()) |
|
| 104 | 104 | { |
| 105 | 105 | $cache = $this->getApplication()->getCache(); |
| 106 | - if($cache !== null) |
|
| 106 | + if ($cache !== null) |
|
| 107 | 107 | { |
| 108 | 108 | $manager = $cache->get($this->getCacheKey()); |
| 109 | - if($manager instanceof TSqlMapManager) |
|
| 109 | + if ($manager instanceof TSqlMapManager) |
|
| 110 | 110 | return $manager; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -128,13 +128,13 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function setConfigFile($value) |
| 130 | 130 | { |
| 131 | - if(is_file($value)) |
|
| 132 | - $this->_configFile=$value; |
|
| 131 | + if (is_file($value)) |
|
| 132 | + $this->_configFile = $value; |
|
| 133 | 133 | else |
| 134 | 134 | { |
| 135 | - $file = Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT); |
|
| 136 | - if($file === null || !is_file($file)) |
|
| 137 | - throw new TConfigurationException('sqlmap_configfile_invalid',$value); |
|
| 135 | + $file = Prado::getPathOfNamespace($value, self::CONFIG_FILE_EXT); |
|
| 136 | + if ($file === null || !is_file($file)) |
|
| 137 | + throw new TConfigurationException('sqlmap_configfile_invalid', $value); |
|
| 138 | 138 | else |
| 139 | 139 | $this->_configFile = $file; |
| 140 | 140 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function getClient() |
| 173 | 173 | { |
| 174 | - if($this->_sqlmap===null ) |
|
| 175 | - $this->_sqlmap=$this->createSqlMapGateway(); |
|
| 174 | + if ($this->_sqlmap === null) |
|
| 175 | + $this->_sqlmap = $this->createSqlMapGateway(); |
|
| 176 | 176 | return $this->_sqlmap; |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -68,8 +68,7 @@ discard block |
||
| 68 | 68 | $manager->configureXml($file); |
| 69 | 69 | $this->cacheSqlMapManager($manager); |
| 70 | 70 | } |
| 71 | - } |
|
| 72 | - elseif($this->getConnectionID() !== '') { |
|
| 71 | + } elseif($this->getConnectionID() !== '') { |
|
| 73 | 72 | $manager->setDbConnection($this->getDbConnection()); |
| 74 | 73 | } |
| 75 | 74 | return $manager; |
@@ -86,8 +85,9 @@ discard block |
||
| 86 | 85 | $cache = $this->getApplication()->getCache(); |
| 87 | 86 | if($cache !== null) { |
| 88 | 87 | $dependencies = null; |
| 89 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 90 | - $dependencies = $manager->getCacheDependencies(); |
|
| 88 | + if($this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
| 89 | + $dependencies = $manager->getCacheDependencies(); |
|
| 90 | + } |
|
| 91 | 91 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -106,8 +106,9 @@ discard block |
||
| 106 | 106 | if($cache !== null) |
| 107 | 107 | { |
| 108 | 108 | $manager = $cache->get($this->getCacheKey()); |
| 109 | - if($manager instanceof TSqlMapManager) |
|
| 110 | - return $manager; |
|
| 109 | + if($manager instanceof TSqlMapManager) { |
|
| 110 | + return $manager; |
|
| 111 | + } |
|
| 111 | 112 | } |
| 112 | 113 | } |
| 113 | 114 | return null; |
@@ -128,15 +129,16 @@ discard block |
||
| 128 | 129 | */ |
| 129 | 130 | public function setConfigFile($value) |
| 130 | 131 | { |
| 131 | - if(is_file($value)) |
|
| 132 | - $this->_configFile=$value; |
|
| 133 | - else |
|
| 132 | + if(is_file($value)) { |
|
| 133 | + $this->_configFile=$value; |
|
| 134 | + } else |
|
| 134 | 135 | { |
| 135 | 136 | $file = Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT); |
| 136 | - if($file === null || !is_file($file)) |
|
| 137 | - throw new TConfigurationException('sqlmap_configfile_invalid',$value); |
|
| 138 | - else |
|
| 139 | - $this->_configFile = $file; |
|
| 137 | + if($file === null || !is_file($file)) { |
|
| 138 | + throw new TConfigurationException('sqlmap_configfile_invalid',$value); |
|
| 139 | + } else { |
|
| 140 | + $this->_configFile = $file; |
|
| 141 | + } |
|
| 140 | 142 | } |
| 141 | 143 | } |
| 142 | 144 | |
@@ -171,8 +173,9 @@ discard block |
||
| 171 | 173 | */ |
| 172 | 174 | public function getClient() |
| 173 | 175 | { |
| 174 | - if($this->_sqlmap===null ) |
|
| 175 | - $this->_sqlmap=$this->createSqlMapGateway(); |
|
| 176 | + if($this->_sqlmap===null ) { |
|
| 177 | + $this->_sqlmap=$this->createSqlMapGateway(); |
|
| 178 | + } |
|
| 176 | 179 | return $this->_sqlmap; |
| 177 | 180 | } |
| 178 | 181 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TSqlMapConfig class file. |
|
| 4 | - * |
|
| 5 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
| 6 | - * @link https://github.com/pradosoft/prado |
|
| 7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
| 8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
| 9 | - * @package System.Data.SqlMap |
|
| 10 | - */ |
|
| 3 | + * TSqlMapConfig class file. |
|
| 4 | + * |
|
| 5 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
| 6 | + * @link https://github.com/pradosoft/prado |
|
| 7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
| 8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
| 9 | + * @package System.Data.SqlMap |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | Prado::using('System.Data.TDataSourceConfig'); |
| 13 | 13 | |
@@ -32,6 +32,9 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | private $_manager; |
| 34 | 34 | |
| 35 | + /** |
|
| 36 | + * @param TSqlMapManager|null $manager |
|
| 37 | + */ |
|
| 35 | 38 | public function __construct($manager) |
| 36 | 39 | { |
| 37 | 40 | $this->_manager=$manager; |
@@ -63,6 +66,8 @@ discard block |
||
| 63 | 66 | * @param string The name of the sql statement to execute. |
| 64 | 67 | * @param mixed The object used to set the parameters in the SQL. |
| 65 | 68 | * @param mixed An object of the type to be returned. |
| 69 | + * @param string $statementName |
|
| 70 | + * @param Account $result |
|
| 66 | 71 | * @return object A single result object populated with the result set data. |
| 67 | 72 | */ |
| 68 | 73 | public function queryForObject($statementName, $parameter=null, $result=null) |
@@ -84,6 +89,8 @@ discard block |
||
| 84 | 89 | * pass in null if want to return a list instead. |
| 85 | 90 | * @param int The number of rows to skip over. |
| 86 | 91 | * @param int The maximum number of rows to return. |
| 92 | + * @param string $statementName |
|
| 93 | + * @param AccountCollection $result |
|
| 87 | 94 | * @return TList A List of result objects. |
| 88 | 95 | */ |
| 89 | 96 | public function queryForList($statementName, $parameter=null, $result=null, $skip=-1, $max=-1) |
@@ -105,6 +112,7 @@ discard block |
||
| 105 | 112 | * pass in null if want to return a list instead. |
| 106 | 113 | * @param int The number of rows to skip over. |
| 107 | 114 | * @param int The maximum number of rows to return. |
| 115 | + * @param string $statementName |
|
| 108 | 116 | * @return TList A List of result objects. |
| 109 | 117 | */ |
| 110 | 118 | public function queryWithRowDelegate($statementName, $delegate, $parameter=null, $result=null, $skip=-1, $max=-1) |
@@ -121,6 +129,7 @@ discard block |
||
| 121 | 129 | * @param mixed The object used to set the parameters in the SQL. |
| 122 | 130 | * @param integer The maximum number of objects to store in each page. |
| 123 | 131 | * @param integer The number of the page to initially load into the list. |
| 132 | + * @param string $statementName |
|
| 124 | 133 | * @return TPagedList A PaginatedList of beans containing the rows. |
| 125 | 134 | */ |
| 126 | 135 | public function queryForPagedList($statementName, $parameter=null, $pageSize=10, $page=0) |
@@ -161,6 +170,9 @@ discard block |
||
| 161 | 170 | * @param mixed The object used to set the parameters in the SQL. |
| 162 | 171 | * @param string The property of the result object to be used as the key. |
| 163 | 172 | * @param string The property of the result object to be used as the value. |
| 173 | + * @param string $statementName |
|
| 174 | + * @param string $keyProperty |
|
| 175 | + * @param string $valueProperty |
|
| 164 | 176 | * @return TMap Array object containing the rows keyed by keyProperty. |
| 165 | 177 | */ |
| 166 | 178 | public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
@@ -180,6 +192,8 @@ discard block |
||
| 180 | 192 | * @param mixed The object used to set the parameters in the SQL. |
| 181 | 193 | * @param string The property of the result object to be used as the key. |
| 182 | 194 | * @param string The property of the result object to be used as the value. |
| 195 | + * @param string $statementName |
|
| 196 | + * @param string $keyProperty |
|
| 183 | 197 | * @return TMap Array object containing the rows keyed by keyProperty. |
| 184 | 198 | */ |
| 185 | 199 | public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
@@ -200,6 +214,7 @@ discard block |
||
| 200 | 214 | * |
| 201 | 215 | * @param string The name of the statement to execute. |
| 202 | 216 | * @param string The parameter object. |
| 217 | + * @param string $statementName |
|
| 203 | 218 | * @return mixed The primary key of the newly inserted row. |
| 204 | 219 | * This might be automatically generated by the RDBMS, |
| 205 | 220 | * or selected from a sequence table or other source. |
@@ -233,6 +248,7 @@ discard block |
||
| 233 | 248 | * Executes a Sql DELETE statement. Delete returns the number of rows effected. |
| 234 | 249 | * @param string The name of the statement to execute. |
| 235 | 250 | * @param mixed The parameter object. |
| 251 | + * @param string $statementName |
|
| 236 | 252 | * @return integer The number of rows effected. |
| 237 | 253 | */ |
| 238 | 254 | public function delete($statementName, $parameter=null) |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function __construct($manager) |
| 36 | 36 | { |
| 37 | - $this->_manager=$manager; |
|
| 37 | + $this->_manager = $manager; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param mixed An object of the type to be returned. |
| 66 | 66 | * @return object A single result object populated with the result set data. |
| 67 | 67 | */ |
| 68 | - public function queryForObject($statementName, $parameter=null, $result=null) |
|
| 68 | + public function queryForObject($statementName, $parameter = null, $result = null) |
|
| 69 | 69 | { |
| 70 | 70 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 71 | 71 | return $statement->executeQueryForObject($this->getDbConnection(), $parameter, $result); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | * @param int The maximum number of rows to return. |
| 87 | 87 | * @return TList A List of result objects. |
| 88 | 88 | */ |
| 89 | - public function queryForList($statementName, $parameter=null, $result=null, $skip=-1, $max=-1) |
|
| 89 | + public function queryForList($statementName, $parameter = null, $result = null, $skip = -1, $max = -1) |
|
| 90 | 90 | { |
| 91 | 91 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 92 | - return $statement->executeQueryForList($this->getDbConnection(),$parameter, $result, $skip, $max); |
|
| 92 | + return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param int The maximum number of rows to return. |
| 108 | 108 | * @return TList A List of result objects. |
| 109 | 109 | */ |
| 110 | - public function queryWithRowDelegate($statementName, $delegate, $parameter=null, $result=null, $skip=-1, $max=-1) |
|
| 110 | + public function queryWithRowDelegate($statementName, $delegate, $parameter = null, $result = null, $skip = -1, $max = -1) |
|
| 111 | 111 | { |
| 112 | 112 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 113 | 113 | return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max, $delegate); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param integer The number of the page to initially load into the list. |
| 124 | 124 | * @return TPagedList A PaginatedList of beans containing the rows. |
| 125 | 125 | */ |
| 126 | - public function queryForPagedList($statementName, $parameter=null, $pageSize=10, $page=0) |
|
| 126 | + public function queryForPagedList($statementName, $parameter = null, $pageSize = 10, $page = 0) |
|
| 127 | 127 | { |
| 128 | 128 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 129 | 129 | return new TSqlMapPagedList($statement, $parameter, $pageSize, null, $page); |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | * @param integer The number of the page to initially load into the list. |
| 145 | 145 | * @return TPagedList A PaginatedList of beans containing the rows. |
| 146 | 146 | */ |
| 147 | - public function queryForPagedListWithRowDelegate($statementName,$delegate, $parameter=null, $pageSize=10, $page=0) |
|
| 147 | + public function queryForPagedListWithRowDelegate($statementName, $delegate, $parameter = null, $pageSize = 10, $page = 0) |
|
| 148 | 148 | { |
| 149 | 149 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 150 | - return new TSqlMapPagedList($statement, $parameter, $pageSize, $delegate,$page); |
|
| 150 | + return new TSqlMapPagedList($statement, $parameter, $pageSize, $delegate, $page); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param string The property of the result object to be used as the value. |
| 164 | 164 | * @return TMap Array object containing the rows keyed by keyProperty. |
| 165 | 165 | */ |
| 166 | - public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
|
| 166 | + public function queryForMap($statementName, $parameter = null, $keyProperty = null, $valueProperty = null, $skip = -1, $max = -1) |
|
| 167 | 167 | { |
| 168 | 168 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 169 | 169 | return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param string The property of the result object to be used as the value. |
| 183 | 183 | * @return TMap Array object containing the rows keyed by keyProperty. |
| 184 | 184 | */ |
| 185 | - public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
|
| 185 | + public function queryForMapWithRowDelegate($statementName, $delegate, $parameter = null, $keyProperty = null, $valueProperty = null, $skip = -1, $max = -1) |
|
| 186 | 186 | { |
| 187 | 187 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 188 | 188 | return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max, $delegate); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * This might be automatically generated by the RDBMS, |
| 205 | 205 | * or selected from a sequence table or other source. |
| 206 | 206 | */ |
| 207 | - public function insert($statementName, $parameter=null) |
|
| 207 | + public function insert($statementName, $parameter = null) |
|
| 208 | 208 | { |
| 209 | 209 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 210 | 210 | return $statement->executeInsert($this->getDbConnection(), $parameter); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param mixed The parameter object. |
| 224 | 224 | * @return integer The number of rows effected. |
| 225 | 225 | */ |
| 226 | - public function update($statementName, $parameter=null) |
|
| 226 | + public function update($statementName, $parameter = null) |
|
| 227 | 227 | { |
| 228 | 228 | $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
| 229 | 229 | return $statement->executeUpdate($this->getDbConnection(), $parameter); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @param mixed The parameter object. |
| 236 | 236 | * @return integer The number of rows effected. |
| 237 | 237 | */ |
| 238 | - public function delete($statementName, $parameter=null) |
|
| 238 | + public function delete($statementName, $parameter = null) |
|
| 239 | 239 | { |
| 240 | 240 | return $this->update($statementName, $parameter); |
| 241 | 241 | } |
@@ -55,6 +55,7 @@ discard block |
||
| 55 | 55 | * Constructor, create a new SqlMap manager. |
| 56 | 56 | * @param TDbConnection database connection |
| 57 | 57 | * @param string configuration file. |
| 58 | + * @param TDbConnection $connection |
|
| 58 | 59 | */ |
| 59 | 60 | public function __construct($connection=null) |
| 60 | 61 | { |
@@ -68,6 +69,7 @@ discard block |
||
| 68 | 69 | |
| 69 | 70 | /** |
| 70 | 71 | * @param TDbConnection default database connection |
| 72 | + * @param TComponent $conn |
|
| 71 | 73 | */ |
| 72 | 74 | public function setDbConnection($conn) |
| 73 | 75 | { |
@@ -105,6 +107,7 @@ discard block |
||
| 105 | 107 | /** |
| 106 | 108 | * Loads and parses the SqlMap configuration file. |
| 107 | 109 | * @param string xml configuration file. |
| 110 | + * @param string $file |
|
| 108 | 111 | */ |
| 109 | 112 | public function configureXml($file) |
| 110 | 113 | { |
@@ -180,6 +183,7 @@ discard block |
||
| 180 | 183 | /** |
| 181 | 184 | * Gets a named result map |
| 182 | 185 | * @param string result name. |
| 186 | + * @param string $name |
|
| 183 | 187 | * @return TResultMap the result map. |
| 184 | 188 | * @throws TSqlMapUndefinedException |
| 185 | 189 | */ |
@@ -212,6 +216,7 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | /** |
| 214 | 218 | * @param string parameter map ID name. |
| 219 | + * @param string $name |
|
| 215 | 220 | * @return TParameterMap the parameter with given ID. |
| 216 | 221 | * @throws TSqlMapUndefinedException |
| 217 | 222 | */ |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | * @param TDbConnection database connection |
| 57 | 57 | * @param string configuration file. |
| 58 | 58 | */ |
| 59 | - public function __construct($connection=null) |
|
| 59 | + public function __construct($connection = null) |
|
| 60 | 60 | { |
| 61 | - $this->_connection=$connection; |
|
| 61 | + $this->_connection = $connection; |
|
| 62 | 62 | |
| 63 | - $this->_mappedStatements=new TMap; |
|
| 64 | - $this->_resultMaps=new TMap; |
|
| 65 | - $this->_parameterMaps=new TMap; |
|
| 66 | - $this->_cacheModels=new TMap; |
|
| 63 | + $this->_mappedStatements = new TMap; |
|
| 64 | + $this->_resultMaps = new TMap; |
|
| 65 | + $this->_parameterMaps = new TMap; |
|
| 66 | + $this->_cacheModels = new TMap; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function setDbConnection($conn) |
| 73 | 73 | { |
| 74 | - $this->_connection=$conn; |
|
| 74 | + $this->_connection = $conn; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function getTypeHandlers() |
| 89 | 89 | { |
| 90 | - if($this->_typeHandlers===null) |
|
| 91 | - $this->_typeHandlers= new TSqlMapTypeHandlerRegistry(); |
|
| 90 | + if ($this->_typeHandlers === null) |
|
| 91 | + $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
|
| 92 | 92 | return $this->_typeHandlers; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function getSqlmapGateway() |
| 99 | 99 | { |
| 100 | - if($this->_gateway===null) |
|
| 101 | - $this->_gateway=$this->createSqlMapGateway(); |
|
| 100 | + if ($this->_gateway === null) |
|
| 101 | + $this->_gateway = $this->createSqlMapGateway(); |
|
| 102 | 102 | return $this->_gateway; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function getCacheDependencies() |
| 120 | 120 | { |
| 121 | - if($this->_cacheDependencies === null) |
|
| 122 | - $this->_cacheDependencies=new TChainedCacheDependency(); |
|
| 121 | + if ($this->_cacheDependencies === null) |
|
| 122 | + $this->_cacheDependencies = new TChainedCacheDependency(); |
|
| 123 | 123 | |
| 124 | 124 | return $this->_cacheDependencies; |
| 125 | 125 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public function getMappedStatement($name) |
| 152 | 152 | { |
| 153 | - if($this->_mappedStatements->contains($name) == false) |
|
| 153 | + if ($this->_mappedStatements->contains($name) == false) |
|
| 154 | 154 | throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
| 155 | 155 | return $this->_mappedStatements[$name]; |
| 156 | 156 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | public function addMappedStatement(IMappedStatement $statement) |
| 165 | 165 | { |
| 166 | 166 | $key = $statement->getID(); |
| 167 | - if($this->_mappedStatements->contains($key) == true) |
|
| 167 | + if ($this->_mappedStatements->contains($key) == true) |
|
| 168 | 168 | throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
| 169 | 169 | $this->_mappedStatements->add($key, $statement); |
| 170 | 170 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public function getResultMap($name) |
| 187 | 187 | { |
| 188 | - if($this->_resultMaps->contains($name) == false) |
|
| 188 | + if ($this->_resultMaps->contains($name) == false) |
|
| 189 | 189 | throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
| 190 | 190 | return $this->_resultMaps[$name]; |
| 191 | 191 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | public function addResultMap(TResultMap $result) |
| 198 | 198 | { |
| 199 | 199 | $key = $result->getID(); |
| 200 | - if($this->_resultMaps->contains($key) == true) |
|
| 200 | + if ($this->_resultMaps->contains($key) == true) |
|
| 201 | 201 | throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
| 202 | 202 | $this->_resultMaps->add($key, $result); |
| 203 | 203 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | public function getParameterMap($name) |
| 219 | 219 | { |
| 220 | - if($this->_parameterMaps->contains($name) == false) |
|
| 220 | + if ($this->_parameterMaps->contains($name) == false) |
|
| 221 | 221 | throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
| 222 | 222 | return $this->_parameterMaps[$name]; |
| 223 | 223 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | public function addParameterMap(TParameterMap $parameter) |
| 230 | 230 | { |
| 231 | 231 | $key = $parameter->getID(); |
| 232 | - if($this->_parameterMaps->contains($key) == true) |
|
| 232 | + if ($this->_parameterMaps->contains($key) == true) |
|
| 233 | 233 | throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
| 234 | 234 | $this->_parameterMaps->add($key, $parameter); |
| 235 | 235 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public function addCacheModel(TSqlMapCacheModel $cacheModel) |
| 243 | 243 | { |
| 244 | - if($this->_cacheModels->contains($cacheModel->getID())) |
|
| 244 | + if ($this->_cacheModels->contains($cacheModel->getID())) |
|
| 245 | 245 | throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
| 246 | 246 | else |
| 247 | 247 | $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function getCacheModel($name) |
| 257 | 257 | { |
| 258 | - if(!$this->_cacheModels->contains($name)) |
|
| 258 | + if (!$this->_cacheModels->contains($name)) |
|
| 259 | 259 | throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
| 260 | 260 | return $this->_cacheModels[$name]; |
| 261 | 261 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function flushCacheModels() |
| 267 | 267 | { |
| 268 | - foreach($this->_cacheModels as $cache) |
|
| 268 | + foreach ($this->_cacheModels as $cache) |
|
| 269 | 269 | $cache->flush(); |
| 270 | 270 | } |
| 271 | 271 | } |
@@ -87,8 +87,9 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function getTypeHandlers() |
| 89 | 89 | { |
| 90 | - if($this->_typeHandlers===null) |
|
| 91 | - $this->_typeHandlers= new TSqlMapTypeHandlerRegistry(); |
|
| 90 | + if($this->_typeHandlers===null) { |
|
| 91 | + $this->_typeHandlers= new TSqlMapTypeHandlerRegistry(); |
|
| 92 | + } |
|
| 92 | 93 | return $this->_typeHandlers; |
| 93 | 94 | } |
| 94 | 95 | |
@@ -97,8 +98,9 @@ discard block |
||
| 97 | 98 | */ |
| 98 | 99 | public function getSqlmapGateway() |
| 99 | 100 | { |
| 100 | - if($this->_gateway===null) |
|
| 101 | - $this->_gateway=$this->createSqlMapGateway(); |
|
| 101 | + if($this->_gateway===null) { |
|
| 102 | + $this->_gateway=$this->createSqlMapGateway(); |
|
| 103 | + } |
|
| 102 | 104 | return $this->_gateway; |
| 103 | 105 | } |
| 104 | 106 | |
@@ -118,8 +120,9 @@ discard block |
||
| 118 | 120 | */ |
| 119 | 121 | public function getCacheDependencies() |
| 120 | 122 | { |
| 121 | - if($this->_cacheDependencies === null) |
|
| 122 | - $this->_cacheDependencies=new TChainedCacheDependency(); |
|
| 123 | + if($this->_cacheDependencies === null) { |
|
| 124 | + $this->_cacheDependencies=new TChainedCacheDependency(); |
|
| 125 | + } |
|
| 123 | 126 | |
| 124 | 127 | return $this->_cacheDependencies; |
| 125 | 128 | } |
@@ -150,8 +153,9 @@ discard block |
||
| 150 | 153 | */ |
| 151 | 154 | public function getMappedStatement($name) |
| 152 | 155 | { |
| 153 | - if($this->_mappedStatements->contains($name) == false) |
|
| 154 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
|
| 156 | + if($this->_mappedStatements->contains($name) == false) { |
|
| 157 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
|
| 158 | + } |
|
| 155 | 159 | return $this->_mappedStatements[$name]; |
| 156 | 160 | } |
| 157 | 161 | |
@@ -164,8 +168,9 @@ discard block |
||
| 164 | 168 | public function addMappedStatement(IMappedStatement $statement) |
| 165 | 169 | { |
| 166 | 170 | $key = $statement->getID(); |
| 167 | - if($this->_mappedStatements->contains($key) == true) |
|
| 168 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
|
| 171 | + if($this->_mappedStatements->contains($key) == true) { |
|
| 172 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
|
| 173 | + } |
|
| 169 | 174 | $this->_mappedStatements->add($key, $statement); |
| 170 | 175 | } |
| 171 | 176 | |
@@ -185,8 +190,9 @@ discard block |
||
| 185 | 190 | */ |
| 186 | 191 | public function getResultMap($name) |
| 187 | 192 | { |
| 188 | - if($this->_resultMaps->contains($name) == false) |
|
| 189 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
|
| 193 | + if($this->_resultMaps->contains($name) == false) { |
|
| 194 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
|
| 195 | + } |
|
| 190 | 196 | return $this->_resultMaps[$name]; |
| 191 | 197 | } |
| 192 | 198 | |
@@ -197,8 +203,9 @@ discard block |
||
| 197 | 203 | public function addResultMap(TResultMap $result) |
| 198 | 204 | { |
| 199 | 205 | $key = $result->getID(); |
| 200 | - if($this->_resultMaps->contains($key) == true) |
|
| 201 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
|
| 206 | + if($this->_resultMaps->contains($key) == true) { |
|
| 207 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
|
| 208 | + } |
|
| 202 | 209 | $this->_resultMaps->add($key, $result); |
| 203 | 210 | } |
| 204 | 211 | |
@@ -217,8 +224,9 @@ discard block |
||
| 217 | 224 | */ |
| 218 | 225 | public function getParameterMap($name) |
| 219 | 226 | { |
| 220 | - if($this->_parameterMaps->contains($name) == false) |
|
| 221 | - throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
|
| 227 | + if($this->_parameterMaps->contains($name) == false) { |
|
| 228 | + throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
|
| 229 | + } |
|
| 222 | 230 | return $this->_parameterMaps[$name]; |
| 223 | 231 | } |
| 224 | 232 | |
@@ -229,8 +237,9 @@ discard block |
||
| 229 | 237 | public function addParameterMap(TParameterMap $parameter) |
| 230 | 238 | { |
| 231 | 239 | $key = $parameter->getID(); |
| 232 | - if($this->_parameterMaps->contains($key) == true) |
|
| 233 | - throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
|
| 240 | + if($this->_parameterMaps->contains($key) == true) { |
|
| 241 | + throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
|
| 242 | + } |
|
| 234 | 243 | $this->_parameterMaps->add($key, $parameter); |
| 235 | 244 | } |
| 236 | 245 | |
@@ -241,10 +250,11 @@ discard block |
||
| 241 | 250 | */ |
| 242 | 251 | public function addCacheModel(TSqlMapCacheModel $cacheModel) |
| 243 | 252 | { |
| 244 | - if($this->_cacheModels->contains($cacheModel->getID())) |
|
| 245 | - throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
|
| 246 | - else |
|
| 247 | - $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
|
| 253 | + if($this->_cacheModels->contains($cacheModel->getID())) { |
|
| 254 | + throw new TSqlMapConfigurationException('sqlmap_cache_model_already_exists', $cacheModel->getID()); |
|
| 255 | + } else { |
|
| 256 | + $this->_cacheModels->add($cacheModel->getID(), $cacheModel); |
|
| 257 | + } |
|
| 248 | 258 | } |
| 249 | 259 | |
| 250 | 260 | /** |
@@ -255,8 +265,9 @@ discard block |
||
| 255 | 265 | */ |
| 256 | 266 | public function getCacheModel($name) |
| 257 | 267 | { |
| 258 | - if(!$this->_cacheModels->contains($name)) |
|
| 259 | - throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
|
| 268 | + if(!$this->_cacheModels->contains($name)) { |
|
| 269 | + throw new TSqlMapConfigurationException('sqlmap_unable_to_find_cache_model', $name); |
|
| 270 | + } |
|
| 260 | 271 | return $this->_cacheModels[$name]; |
| 261 | 272 | } |
| 262 | 273 | |
@@ -265,8 +276,9 @@ discard block |
||
| 265 | 276 | */ |
| 266 | 277 | public function flushCacheModels() |
| 267 | 278 | { |
| 268 | - foreach($this->_cacheModels as $cache) |
|
| 269 | - $cache->flush(); |
|
| 279 | + foreach($this->_cacheModels as $cache) { |
|
| 280 | + $cache->flush(); |
|
| 281 | + } |
|
| 270 | 282 | } |
| 271 | 283 | } |
| 272 | 284 | |
@@ -149,6 +149,7 @@ |
||
| 149 | 149 | /** |
| 150 | 150 | * Finds the database connection instance from the Application modules. |
| 151 | 151 | * @param string Database connection module ID. |
| 152 | + * @param string $id |
|
| 152 | 153 | * @return TDbConnection database connection. |
| 153 | 154 | * @throws TConfigurationException when module is not of TDbConnection or TDataSourceConfig. |
| 154 | 155 | */ |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | class TDataSourceConfig extends TModule |
| 48 | 48 | { |
| 49 | - private $_connID=''; |
|
| 49 | + private $_connID = ''; |
|
| 50 | 50 | private $_conn; |
| 51 | - private $_connClass='System.Data.TDbConnection'; |
|
| 51 | + private $_connClass = 'System.Data.TDbConnection'; |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Initalize the database connection properties from attributes in <database> tag. |
@@ -56,22 +56,22 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function init($xml) |
| 58 | 58 | { |
| 59 | - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
| 59 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
| 60 | 60 | { |
| 61 | - if(isset($xml['database']) && is_array($xml['database'])) |
|
| 61 | + if (isset($xml['database']) && is_array($xml['database'])) |
|
| 62 | 62 | { |
| 63 | - $db=$this->getDbConnection(); |
|
| 64 | - foreach($xml['database'] as $name=>$value) |
|
| 65 | - $db->setSubProperty($name,$value); |
|
| 63 | + $db = $this->getDbConnection(); |
|
| 64 | + foreach ($xml['database'] as $name=>$value) |
|
| 65 | + $db->setSubProperty($name, $value); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | else |
| 69 | 69 | { |
| 70 | - if($prop=$xml->getElementByTagName('database')) |
|
| 70 | + if ($prop = $xml->getElementByTagName('database')) |
|
| 71 | 71 | { |
| 72 | - $db=$this->getDbConnection(); |
|
| 73 | - foreach($prop->getAttributes() as $name=>$value) |
|
| 74 | - $db->setSubproperty($name,$value); |
|
| 72 | + $db = $this->getDbConnection(); |
|
| 73 | + foreach ($prop->getAttributes() as $name=>$value) |
|
| 74 | + $db->setSubproperty($name, $value); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setConnectionID($value) |
| 86 | 86 | { |
| 87 | - $this->_connID=$value; |
|
| 87 | + $this->_connID = $value; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getDbConnection() |
| 105 | 105 | { |
| 106 | - if($this->_conn===null) |
|
| 106 | + if ($this->_conn === null) |
|
| 107 | 107 | { |
| 108 | - if($this->_connID!=='') |
|
| 108 | + if ($this->_connID !== '') |
|
| 109 | 109 | $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
| 110 | 110 | else |
| 111 | 111 | $this->_conn = Prado::createComponent($this->getConnectionClass()); |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function setConnectionClass($value) |
| 143 | 143 | { |
| 144 | - if($this->_conn!==null) |
|
| 144 | + if ($this->_conn !== null) |
|
| 145 | 145 | throw new TConfigurationException('datasource_dbconnection_exists', $value); |
| 146 | - $this->_connClass=$value; |
|
| 146 | + $this->_connClass = $value; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | protected function findConnectionByID($id) |
| 156 | 156 | { |
| 157 | 157 | $conn = $this->getApplication()->getModule($id); |
| 158 | - if($conn instanceof TDbConnection) |
|
| 158 | + if ($conn instanceof TDbConnection) |
|
| 159 | 159 | return $conn; |
| 160 | - else if($conn instanceof TDataSourceConfig) |
|
| 160 | + else if ($conn instanceof TDataSourceConfig) |
|
| 161 | 161 | return $conn->getDbConnection(); |
| 162 | 162 | else |
| 163 | - throw new TConfigurationException('datasource_dbconnection_invalid',$id); |
|
| 163 | + throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
|
| 164 | 164 | } |
| 165 | 165 | } |
@@ -61,17 +61,18 @@ discard block |
||
| 61 | 61 | if(isset($xml['database']) && is_array($xml['database'])) |
| 62 | 62 | { |
| 63 | 63 | $db=$this->getDbConnection(); |
| 64 | - foreach($xml['database'] as $name=>$value) |
|
| 65 | - $db->setSubProperty($name,$value); |
|
| 64 | + foreach($xml['database'] as $name=>$value) { |
|
| 65 | + $db->setSubProperty($name,$value); |
|
| 66 | + } |
|
| 66 | 67 | } |
| 67 | - } |
|
| 68 | - else |
|
| 68 | + } else |
|
| 69 | 69 | { |
| 70 | 70 | if($prop=$xml->getElementByTagName('database')) |
| 71 | 71 | { |
| 72 | 72 | $db=$this->getDbConnection(); |
| 73 | - foreach($prop->getAttributes() as $name=>$value) |
|
| 74 | - $db->setSubproperty($name,$value); |
|
| 73 | + foreach($prop->getAttributes() as $name=>$value) { |
|
| 74 | + $db->setSubproperty($name,$value); |
|
| 75 | + } |
|
| 75 | 76 | } |
| 76 | 77 | } |
| 77 | 78 | } |
@@ -105,10 +106,11 @@ discard block |
||
| 105 | 106 | { |
| 106 | 107 | if($this->_conn===null) |
| 107 | 108 | { |
| 108 | - if($this->_connID!=='') |
|
| 109 | - $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
| 110 | - else |
|
| 111 | - $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
| 109 | + if($this->_connID!=='') { |
|
| 110 | + $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
| 111 | + } else { |
|
| 112 | + $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
| 113 | + } |
|
| 112 | 114 | } |
| 113 | 115 | return $this->_conn; |
| 114 | 116 | } |
@@ -141,8 +143,9 @@ discard block |
||
| 141 | 143 | */ |
| 142 | 144 | public function setConnectionClass($value) |
| 143 | 145 | { |
| 144 | - if($this->_conn!==null) |
|
| 145 | - throw new TConfigurationException('datasource_dbconnection_exists', $value); |
|
| 146 | + if($this->_conn!==null) { |
|
| 147 | + throw new TConfigurationException('datasource_dbconnection_exists', $value); |
|
| 148 | + } |
|
| 146 | 149 | $this->_connClass=$value; |
| 147 | 150 | } |
| 148 | 151 | |
@@ -155,11 +158,12 @@ discard block |
||
| 155 | 158 | protected function findConnectionByID($id) |
| 156 | 159 | { |
| 157 | 160 | $conn = $this->getApplication()->getModule($id); |
| 158 | - if($conn instanceof TDbConnection) |
|
| 159 | - return $conn; |
|
| 160 | - else if($conn instanceof TDataSourceConfig) |
|
| 161 | - return $conn->getDbConnection(); |
|
| 162 | - else |
|
| 163 | - throw new TConfigurationException('datasource_dbconnection_invalid',$id); |
|
| 161 | + if($conn instanceof TDbConnection) { |
|
| 162 | + return $conn; |
|
| 163 | + } else if($conn instanceof TDataSourceConfig) { |
|
| 164 | + return $conn->getDbConnection(); |
|
| 165 | + } else { |
|
| 166 | + throw new TConfigurationException('datasource_dbconnection_invalid',$id); |
|
| 167 | + } |
|
| 164 | 168 | } |
| 165 | 169 | } |
@@ -136,6 +136,7 @@ |
||
| 136 | 136 | * @param mixed Name of the PHP variable to bind to the SQL statement parameter |
| 137 | 137 | * @param int SQL data type of the parameter |
| 138 | 138 | * @param int length of the data type |
| 139 | + * @param string $name |
|
| 139 | 140 | * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php |
| 140 | 141 | */ |
| 141 | 142 | public function bindParameter($name, &$value, $dataType=null, $length=null) |
@@ -37,17 +37,17 @@ discard block |
||
| 37 | 37 | class TDbCommand extends TComponent |
| 38 | 38 | { |
| 39 | 39 | private $_connection; |
| 40 | - private $_text=''; |
|
| 41 | - private $_statement=null; |
|
| 40 | + private $_text = ''; |
|
| 41 | + private $_statement = null; |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Constructor. |
| 45 | 45 | * @param TDbConnection the database connection |
| 46 | 46 | * @param string the SQL statement to be executed |
| 47 | 47 | */ |
| 48 | - public function __construct(TDbConnection $connection,$text) |
|
| 48 | + public function __construct(TDbConnection $connection, $text) |
|
| 49 | 49 | { |
| 50 | - $this->_connection=$connection; |
|
| 50 | + $this->_connection = $connection; |
|
| 51 | 51 | $this->setText($text); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function __sleep() |
| 58 | 58 | { |
| 59 | - return array_diff(parent::__sleep(),array("\0TDbCommand\0_statement")); |
|
| 59 | + return array_diff(parent::__sleep(), array("\0TDbCommand\0_statement")); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function setText($value) |
| 76 | 76 | { |
| 77 | - $this->_text=$value; |
|
| 77 | + $this->_text = $value; |
|
| 78 | 78 | $this->cancel(); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -104,15 +104,15 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function prepare() |
| 106 | 106 | { |
| 107 | - if($this->_statement==null) |
|
| 107 | + if ($this->_statement == null) |
|
| 108 | 108 | { |
| 109 | 109 | try |
| 110 | 110 | { |
| 111 | - $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
| 111 | + $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
| 112 | 112 | } |
| 113 | - catch(Exception $e) |
|
| 113 | + catch (Exception $e) |
|
| 114 | 114 | { |
| 115 | - throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
|
| 115 | + throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function cancel() |
| 124 | 124 | { |
| 125 | - $this->_statement=null; |
|
| 125 | + $this->_statement = null; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -138,15 +138,15 @@ discard block |
||
| 138 | 138 | * @param int length of the data type |
| 139 | 139 | * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php |
| 140 | 140 | */ |
| 141 | - public function bindParameter($name, &$value, $dataType=null, $length=null) |
|
| 141 | + public function bindParameter($name, &$value, $dataType = null, $length = null) |
|
| 142 | 142 | { |
| 143 | 143 | $this->prepare(); |
| 144 | - if($dataType===null) |
|
| 145 | - $this->_statement->bindParam($name,$value); |
|
| 146 | - else if($length===null) |
|
| 147 | - $this->_statement->bindParam($name,$value,$dataType); |
|
| 144 | + if ($dataType === null) |
|
| 145 | + $this->_statement->bindParam($name, $value); |
|
| 146 | + else if ($length === null) |
|
| 147 | + $this->_statement->bindParam($name, $value, $dataType); |
|
| 148 | 148 | else |
| 149 | - $this->_statement->bindParam($name,$value,$dataType,$length); |
|
| 149 | + $this->_statement->bindParam($name, $value, $dataType, $length); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * @param int SQL data type of the parameter |
| 160 | 160 | * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php |
| 161 | 161 | */ |
| 162 | - public function bindValue($name, $value, $dataType=null) |
|
| 162 | + public function bindValue($name, $value, $dataType = null) |
|
| 163 | 163 | { |
| 164 | 164 | $this->prepare(); |
| 165 | - if($dataType===null) |
|
| 166 | - $this->_statement->bindValue($name,$value); |
|
| 165 | + if ($dataType === null) |
|
| 166 | + $this->_statement->bindValue($name, $value); |
|
| 167 | 167 | else |
| 168 | - $this->_statement->bindValue($name,$value,$dataType); |
|
| 168 | + $this->_statement->bindValue($name, $value, $dataType); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // Do not trace because it will remain even in |
| 183 | 183 | // Performance mode or when pradolite.php is used |
| 184 | 184 | // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'System.Data'); |
| 185 | - if($this->_statement instanceof PDOStatement) |
|
| 185 | + if ($this->_statement instanceof PDOStatement) |
|
| 186 | 186 | { |
| 187 | 187 | $this->_statement->execute(); |
| 188 | 188 | return $this->_statement->rowCount(); |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | else |
| 191 | 191 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
| 192 | 192 | } |
| 193 | - catch(Exception $e) |
|
| 193 | + catch (Exception $e) |
|
| 194 | 194 | { |
| 195 | - throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
| 195 | + throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function getDebugStatementText() |
| 203 | 203 | { |
| 204 | - if(Prado::getApplication()->getMode() === TApplicationMode::Debug) |
|
| 204 | + if (Prado::getApplication()->getMode() === TApplicationMode::Debug) |
|
| 205 | 205 | return $this->_statement instanceof PDOStatement ? |
| 206 | 206 | $this->_statement->queryString |
| 207 | 207 | : $this->getText(); |
@@ -218,15 +218,15 @@ discard block |
||
| 218 | 218 | try |
| 219 | 219 | { |
| 220 | 220 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'System.Data'); |
| 221 | - if($this->_statement instanceof PDOStatement) |
|
| 221 | + if ($this->_statement instanceof PDOStatement) |
|
| 222 | 222 | $this->_statement->execute(); |
| 223 | 223 | else |
| 224 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 224 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 225 | 225 | return new TDbDataReader($this); |
| 226 | 226 | } |
| 227 | - catch(Exception $e) |
|
| 227 | + catch (Exception $e) |
|
| 228 | 228 | { |
| 229 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
| 229 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
@@ -238,22 +238,22 @@ discard block |
||
| 238 | 238 | * @return array the first row of the query result, false if no result. |
| 239 | 239 | * @throws TDbException execution failed |
| 240 | 240 | */ |
| 241 | - public function queryRow($fetchAssociative=true) |
|
| 241 | + public function queryRow($fetchAssociative = true) |
|
| 242 | 242 | { |
| 243 | 243 | try |
| 244 | 244 | { |
| 245 | 245 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'System.Data'); |
| 246 | - if($this->_statement instanceof PDOStatement) |
|
| 246 | + if ($this->_statement instanceof PDOStatement) |
|
| 247 | 247 | $this->_statement->execute(); |
| 248 | 248 | else |
| 249 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 250 | - $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
| 249 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 250 | + $result = $this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
| 251 | 251 | $this->_statement->closeCursor(); |
| 252 | 252 | return $result; |
| 253 | 253 | } |
| 254 | - catch(Exception $e) |
|
| 254 | + catch (Exception $e) |
|
| 255 | 255 | { |
| 256 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
| 256 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
@@ -269,20 +269,20 @@ discard block |
||
| 269 | 269 | try |
| 270 | 270 | { |
| 271 | 271 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'System.Data'); |
| 272 | - if($this->_statement instanceof PDOStatement) |
|
| 272 | + if ($this->_statement instanceof PDOStatement) |
|
| 273 | 273 | $this->_statement->execute(); |
| 274 | 274 | else |
| 275 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 276 | - $result=$this->_statement->fetchColumn(); |
|
| 275 | + $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 276 | + $result = $this->_statement->fetchColumn(); |
|
| 277 | 277 | $this->_statement->closeCursor(); |
| 278 | - if(is_resource($result) && get_resource_type($result)==='stream') |
|
| 278 | + if (is_resource($result) && get_resource_type($result) === 'stream') |
|
| 279 | 279 | return stream_get_contents($result); |
| 280 | 280 | else |
| 281 | 281 | return $result; |
| 282 | 282 | } |
| 283 | - catch(Exception $e) |
|
| 283 | + catch (Exception $e) |
|
| 284 | 284 | { |
| 285 | - throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
|
| 285 | + throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function queryColumn() |
| 298 | 298 | { |
| 299 | - $rows=$this->query()->readAll(); |
|
| 300 | - $column=array(); |
|
| 301 | - foreach($rows as $row) |
|
| 302 | - $column[]=current($row); |
|
| 299 | + $rows = $this->query()->readAll(); |
|
| 300 | + $column = array(); |
|
| 301 | + foreach ($rows as $row) |
|
| 302 | + $column[] = current($row); |
|
| 303 | 303 | return $column; |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -109,8 +109,7 @@ discard block |
||
| 109 | 109 | try |
| 110 | 110 | { |
| 111 | 111 | $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
| 112 | - } |
|
| 113 | - catch(Exception $e) |
|
| 112 | + } catch(Exception $e) |
|
| 114 | 113 | { |
| 115 | 114 | throw new TDbException('dbcommand_prepare_failed',$e->getMessage(),$this->getText()); |
| 116 | 115 | } |
@@ -141,12 +140,13 @@ discard block |
||
| 141 | 140 | public function bindParameter($name, &$value, $dataType=null, $length=null) |
| 142 | 141 | { |
| 143 | 142 | $this->prepare(); |
| 144 | - if($dataType===null) |
|
| 145 | - $this->_statement->bindParam($name,$value); |
|
| 146 | - else if($length===null) |
|
| 147 | - $this->_statement->bindParam($name,$value,$dataType); |
|
| 148 | - else |
|
| 149 | - $this->_statement->bindParam($name,$value,$dataType,$length); |
|
| 143 | + if($dataType===null) { |
|
| 144 | + $this->_statement->bindParam($name,$value); |
|
| 145 | + } else if($length===null) { |
|
| 146 | + $this->_statement->bindParam($name,$value,$dataType); |
|
| 147 | + } else { |
|
| 148 | + $this->_statement->bindParam($name,$value,$dataType,$length); |
|
| 149 | + } |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -162,10 +162,11 @@ discard block |
||
| 162 | 162 | public function bindValue($name, $value, $dataType=null) |
| 163 | 163 | { |
| 164 | 164 | $this->prepare(); |
| 165 | - if($dataType===null) |
|
| 166 | - $this->_statement->bindValue($name,$value); |
|
| 167 | - else |
|
| 168 | - $this->_statement->bindValue($name,$value,$dataType); |
|
| 165 | + if($dataType===null) { |
|
| 166 | + $this->_statement->bindValue($name,$value); |
|
| 167 | + } else { |
|
| 168 | + $this->_statement->bindValue($name,$value,$dataType); |
|
| 169 | + } |
|
| 169 | 170 | } |
| 170 | 171 | |
| 171 | 172 | /** |
@@ -186,11 +187,10 @@ discard block |
||
| 186 | 187 | { |
| 187 | 188 | $this->_statement->execute(); |
| 188 | 189 | return $this->_statement->rowCount(); |
| 190 | + } else { |
|
| 191 | + return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
|
| 189 | 192 | } |
| 190 | - else |
|
| 191 | - return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
|
| 192 | - } |
|
| 193 | - catch(Exception $e) |
|
| 193 | + } catch(Exception $e) |
|
| 194 | 194 | { |
| 195 | 195 | throw new TDbException('dbcommand_execute_failed',$e->getMessage(),$this->getDebugStatementText()); |
| 196 | 196 | } |
@@ -201,10 +201,11 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function getDebugStatementText() |
| 203 | 203 | { |
| 204 | - if(Prado::getApplication()->getMode() === TApplicationMode::Debug) |
|
| 205 | - return $this->_statement instanceof PDOStatement ? |
|
| 204 | + if(Prado::getApplication()->getMode() === TApplicationMode::Debug) { |
|
| 205 | + return $this->_statement instanceof PDOStatement ? |
|
| 206 | 206 | $this->_statement->queryString |
| 207 | 207 | : $this->getText(); |
| 208 | + } |
|
| 208 | 209 | } |
| 209 | 210 | |
| 210 | 211 | /** |
@@ -218,13 +219,13 @@ discard block |
||
| 218 | 219 | try |
| 219 | 220 | { |
| 220 | 221 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'System.Data'); |
| 221 | - if($this->_statement instanceof PDOStatement) |
|
| 222 | - $this->_statement->execute(); |
|
| 223 | - else |
|
| 224 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 222 | + if($this->_statement instanceof PDOStatement) { |
|
| 223 | + $this->_statement->execute(); |
|
| 224 | + } else { |
|
| 225 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 226 | + } |
|
| 225 | 227 | return new TDbDataReader($this); |
| 226 | - } |
|
| 227 | - catch(Exception $e) |
|
| 228 | + } catch(Exception $e) |
|
| 228 | 229 | { |
| 229 | 230 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
| 230 | 231 | } |
@@ -243,15 +244,15 @@ discard block |
||
| 243 | 244 | try |
| 244 | 245 | { |
| 245 | 246 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'System.Data'); |
| 246 | - if($this->_statement instanceof PDOStatement) |
|
| 247 | - $this->_statement->execute(); |
|
| 248 | - else |
|
| 249 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 247 | + if($this->_statement instanceof PDOStatement) { |
|
| 248 | + $this->_statement->execute(); |
|
| 249 | + } else { |
|
| 250 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 251 | + } |
|
| 250 | 252 | $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
| 251 | 253 | $this->_statement->closeCursor(); |
| 252 | 254 | return $result; |
| 253 | - } |
|
| 254 | - catch(Exception $e) |
|
| 255 | + } catch(Exception $e) |
|
| 255 | 256 | { |
| 256 | 257 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
| 257 | 258 | } |
@@ -269,18 +270,19 @@ discard block |
||
| 269 | 270 | try |
| 270 | 271 | { |
| 271 | 272 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'System.Data'); |
| 272 | - if($this->_statement instanceof PDOStatement) |
|
| 273 | - $this->_statement->execute(); |
|
| 274 | - else |
|
| 275 | - $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 273 | + if($this->_statement instanceof PDOStatement) { |
|
| 274 | + $this->_statement->execute(); |
|
| 275 | + } else { |
|
| 276 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
| 277 | + } |
|
| 276 | 278 | $result=$this->_statement->fetchColumn(); |
| 277 | 279 | $this->_statement->closeCursor(); |
| 278 | - if(is_resource($result) && get_resource_type($result)==='stream') |
|
| 279 | - return stream_get_contents($result); |
|
| 280 | - else |
|
| 281 | - return $result; |
|
| 282 | - } |
|
| 283 | - catch(Exception $e) |
|
| 280 | + if(is_resource($result) && get_resource_type($result)==='stream') { |
|
| 281 | + return stream_get_contents($result); |
|
| 282 | + } else { |
|
| 283 | + return $result; |
|
| 284 | + } |
|
| 285 | + } catch(Exception $e) |
|
| 284 | 286 | { |
| 285 | 287 | throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText()); |
| 286 | 288 | } |
@@ -298,8 +300,9 @@ discard block |
||
| 298 | 300 | { |
| 299 | 301 | $rows=$this->query()->readAll(); |
| 300 | 302 | $column=array(); |
| 301 | - foreach($rows as $row) |
|
| 302 | - $column[]=current($row); |
|
| 303 | + foreach($rows as $row) { |
|
| 304 | + $column[]=current($row); |
|
| 305 | + } |
|
| 303 | 306 | return $column; |
| 304 | 307 | } |
| 305 | 308 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TDbCommand class file |
|
| 4 | - * |
|
| 5 | - * @author Qiang Xue <[email protected]> |
|
| 6 | - * @link https://github.com/pradosoft/prado |
|
| 7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
| 8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
| 9 | - * @package System.Data |
|
| 10 | - */ |
|
| 3 | + * TDbCommand class file |
|
| 4 | + * |
|
| 5 | + * @author Qiang Xue <[email protected]> |
|
| 6 | + * @link https://github.com/pradosoft/prado |
|
| 7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
| 8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
| 9 | + * @package System.Data |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * TDbCommand class. |
@@ -157,6 +157,7 @@ discard block |
||
| 157 | 157 | /** |
| 158 | 158 | * Open or close the DB connection. |
| 159 | 159 | * @param boolean whether to open or close DB connection |
| 160 | + * @param boolean $value |
|
| 160 | 161 | * @throws TDbException if connection fails |
| 161 | 162 | */ |
| 162 | 163 | public function setActive($value) |
@@ -241,6 +242,7 @@ discard block |
||
| 241 | 242 | |
| 242 | 243 | /** |
| 243 | 244 | * @param string The Data Source Name, or DSN, contains the information required to connect to the database. |
| 245 | + * @param string $value |
|
| 244 | 246 | * @see http://www.php.net/manual/en/function.PDO-construct.php |
| 245 | 247 | */ |
| 246 | 248 | public function setConnectionString($value) |
@@ -258,6 +260,7 @@ discard block |
||
| 258 | 260 | |
| 259 | 261 | /** |
| 260 | 262 | * @param string the username for establishing DB connection |
| 263 | + * @param string $value |
|
| 261 | 264 | */ |
| 262 | 265 | public function setUsername($value) |
| 263 | 266 | { |
@@ -274,6 +277,7 @@ discard block |
||
| 274 | 277 | |
| 275 | 278 | /** |
| 276 | 279 | * @param string the password for establishing DB connection |
| 280 | + * @param string $value |
|
| 277 | 281 | */ |
| 278 | 282 | public function setPassword($value) |
| 279 | 283 | { |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction'; |
| 89 | 89 | |
| 90 | - private $_dsn=''; |
|
| 91 | - private $_username=''; |
|
| 92 | - private $_password=''; |
|
| 93 | - private $_charset=''; |
|
| 94 | - private $_attributes=array(); |
|
| 95 | - private $_active=false; |
|
| 96 | - private $_pdo=null; |
|
| 90 | + private $_dsn = ''; |
|
| 91 | + private $_username = ''; |
|
| 92 | + private $_password = ''; |
|
| 93 | + private $_charset = ''; |
|
| 94 | + private $_attributes = array(); |
|
| 95 | + private $_active = false; |
|
| 96 | + private $_pdo = null; |
|
| 97 | 97 | private $_transaction; |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @var string |
| 106 | 106 | * @since 3.1.7 |
| 107 | 107 | */ |
| 108 | - private $_transactionClass=self::DEFAULT_TRANSACTION_CLASS; |
|
| 108 | + private $_transactionClass = self::DEFAULT_TRANSACTION_CLASS; |
|
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * Constructor. |
@@ -120,12 +120,12 @@ discard block |
||
| 120 | 120 | * @param string Charset used for DB Connection (MySql & pgsql only). If not set, will use the default charset of your database server |
| 121 | 121 | * @see http://www.php.net/manual/en/function.PDO-construct.php |
| 122 | 122 | */ |
| 123 | - public function __construct($dsn='',$username='',$password='', $charset='') |
|
| 123 | + public function __construct($dsn = '', $username = '', $password = '', $charset = '') |
|
| 124 | 124 | { |
| 125 | - $this->_dsn=$dsn; |
|
| 126 | - $this->_username=$username; |
|
| 127 | - $this->_password=$password; |
|
| 128 | - $this->_charset=$charset; |
|
| 125 | + $this->_dsn = $dsn; |
|
| 126 | + $this->_username = $username; |
|
| 127 | + $this->_password = $password; |
|
| 128 | + $this->_charset = $charset; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public function __sleep() |
| 135 | 135 | { |
| 136 | 136 | // $this->close(); - DO NOT CLOSE the current connection as serializing doesn't neccessarily mean we don't this connection anymore in the current session |
| 137 | - return array_diff(parent::__sleep(),array("\0TDbConnection\0_pdo","\0TDbConnection\0_active")); |
|
| 137 | + return array_diff(parent::__sleep(), array("\0TDbConnection\0_pdo", "\0TDbConnection\0_active")); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function setActive($value) |
| 163 | 163 | { |
| 164 | - $value=TPropertyValue::ensureBoolean($value); |
|
| 165 | - if($value!==$this->_active) |
|
| 164 | + $value = TPropertyValue::ensureBoolean($value); |
|
| 165 | + if ($value !== $this->_active) |
|
| 166 | 166 | { |
| 167 | - if($value) |
|
| 167 | + if ($value) |
|
| 168 | 168 | $this->open(); |
| 169 | 169 | else |
| 170 | 170 | $this->close(); |
@@ -177,22 +177,22 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | protected function open() |
| 179 | 179 | { |
| 180 | - if($this->_pdo===null) |
|
| 180 | + if ($this->_pdo === null) |
|
| 181 | 181 | { |
| 182 | 182 | try |
| 183 | 183 | { |
| 184 | - $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(), |
|
| 185 | - $this->getPassword(),$this->_attributes); |
|
| 184 | + $this->_pdo = new PDO($this->getConnectionString(), $this->getUsername(), |
|
| 185 | + $this->getPassword(), $this->_attributes); |
|
| 186 | 186 | // This attribute is only useful for PDO::MySql driver. |
| 187 | 187 | // Ignore the warning if a driver doesn't understand this. |
| 188 | 188 | @$this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 189 | 189 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 190 | - $this->_active=true; |
|
| 190 | + $this->_active = true; |
|
| 191 | 191 | $this->setConnectionCharset(); |
| 192 | 192 | } |
| 193 | - catch(PDOException $e) |
|
| 193 | + catch (PDOException $e) |
|
| 194 | 194 | { |
| 195 | - throw new TDbException('dbconnection_open_failed',$e->getMessage()); |
|
| 195 | + throw new TDbException('dbconnection_open_failed', $e->getMessage()); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | protected function close() |
| 205 | 205 | { |
| 206 | - $this->_pdo=null; |
|
| 207 | - $this->_active=false; |
|
| 206 | + $this->_pdo = null; |
|
| 207 | + $this->_active = false; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /* |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | public function setConnectionString($value) |
| 247 | 247 | { |
| 248 | - $this->_dsn=$value; |
|
| 248 | + $this->_dsn = $value; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function setUsername($value) |
| 263 | 263 | { |
| 264 | - $this->_username=$value; |
|
| 264 | + $this->_username = $value; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -277,13 +277,13 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public function setPassword($value) |
| 279 | 279 | { |
| 280 | - $this->_password=$value; |
|
| 280 | + $this->_password = $value; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * @return string the charset used for database connection. Defaults to emtpy string. |
| 285 | 285 | */ |
| 286 | - public function getCharset () |
|
| 286 | + public function getCharset() |
|
| 287 | 287 | { |
| 288 | 288 | return $this->_charset; |
| 289 | 289 | } |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | /** |
| 292 | 292 | * @param string the charset used for database connection |
| 293 | 293 | */ |
| 294 | - public function setCharset ($value) |
|
| 294 | + public function setCharset($value) |
|
| 295 | 295 | { |
| 296 | - $this->_charset=$value; |
|
| 296 | + $this->_charset = $value; |
|
| 297 | 297 | $this->setConnectionCharset(); |
| 298 | 298 | } |
| 299 | 299 | |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | public function createCommand($sql) |
| 315 | 315 | { |
| 316 | - if($this->getActive()) |
|
| 317 | - return new TDbCommand($this,$sql); |
|
| 316 | + if ($this->getActive()) |
|
| 317 | + return new TDbCommand($this, $sql); |
|
| 318 | 318 | else |
| 319 | 319 | throw new TDbException('dbconnection_connection_inactive'); |
| 320 | 320 | } |
@@ -324,9 +324,9 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | public function getCurrentTransaction() |
| 326 | 326 | { |
| 327 | - if($this->_transaction!==null) |
|
| 327 | + if ($this->_transaction !== null) |
|
| 328 | 328 | { |
| 329 | - if($this->_transaction->getActive()) |
|
| 329 | + if ($this->_transaction->getActive()) |
|
| 330 | 330 | return $this->_transaction; |
| 331 | 331 | } |
| 332 | 332 | return null; |
@@ -339,10 +339,10 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | public function beginTransaction() |
| 341 | 341 | { |
| 342 | - if($this->getActive()) |
|
| 342 | + if ($this->getActive()) |
|
| 343 | 343 | { |
| 344 | 344 | $this->_pdo->beginTransaction(); |
| 345 | - return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); |
|
| 345 | + return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this); |
|
| 346 | 346 | } |
| 347 | 347 | else |
| 348 | 348 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | public function setTransactionClass($value) |
| 366 | 366 | { |
| 367 | - $this->_transactionClass = (string)$value; |
|
| 367 | + $this->_transactionClass = (string) $value; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -373,9 +373,9 @@ discard block |
||
| 373 | 373 | * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object |
| 374 | 374 | * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php |
| 375 | 375 | */ |
| 376 | - public function getLastInsertID($sequenceName='') |
|
| 376 | + public function getLastInsertID($sequenceName = '') |
|
| 377 | 377 | { |
| 378 | - if($this->getActive()) |
|
| 378 | + if ($this->getActive()) |
|
| 379 | 379 | return $this->_pdo->lastInsertId($sequenceName); |
| 380 | 380 | else |
| 381 | 381 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function quoteString($str) |
| 391 | 391 | { |
| 392 | - if($this->getActive()) |
|
| 392 | + if ($this->getActive()) |
|
| 393 | 393 | return $this->_pdo->quote($str); |
| 394 | 394 | else |
| 395 | 395 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | */ |
| 431 | 431 | public function getDbMetaData() |
| 432 | 432 | { |
| 433 | - if($this->_dbMeta===null) |
|
| 433 | + if ($this->_dbMeta === null) |
|
| 434 | 434 | { |
| 435 | 435 | Prado::using('System.Data.Common.TDbMetaData'); |
| 436 | 436 | $this->_dbMeta = TDbMetaData::getInstance($this); |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function getColumnCase() |
| 445 | 445 | { |
| 446 | - switch($this->getAttribute(PDO::ATTR_CASE)) |
|
| 446 | + switch ($this->getAttribute(PDO::ATTR_CASE)) |
|
| 447 | 447 | { |
| 448 | 448 | case PDO::CASE_NATURAL: |
| 449 | 449 | return TDbColumnCaseMode::Preserved; |
@@ -459,19 +459,19 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | public function setColumnCase($value) |
| 461 | 461 | { |
| 462 | - switch(TPropertyValue::ensureEnum($value,'TDbColumnCaseMode')) |
|
| 462 | + switch (TPropertyValue::ensureEnum($value, 'TDbColumnCaseMode')) |
|
| 463 | 463 | { |
| 464 | 464 | case TDbColumnCaseMode::Preserved: |
| 465 | - $value=PDO::CASE_NATURAL; |
|
| 465 | + $value = PDO::CASE_NATURAL; |
|
| 466 | 466 | break; |
| 467 | 467 | case TDbColumnCaseMode::LowerCase: |
| 468 | - $value=PDO::CASE_LOWER; |
|
| 468 | + $value = PDO::CASE_LOWER; |
|
| 469 | 469 | break; |
| 470 | 470 | case TDbColumnCaseMode::UpperCase: |
| 471 | - $value=PDO::CASE_UPPER; |
|
| 471 | + $value = PDO::CASE_UPPER; |
|
| 472 | 472 | break; |
| 473 | 473 | } |
| 474 | - $this->setAttribute(PDO::ATTR_CASE,$value); |
|
| 474 | + $this->setAttribute(PDO::ATTR_CASE, $value); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | */ |
| 480 | 480 | public function getNullConversion() |
| 481 | 481 | { |
| 482 | - switch($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
| 482 | + switch ($this->getAttribute(PDO::ATTR_ORACLE_NULLS)) |
|
| 483 | 483 | { |
| 484 | 484 | case PDO::NULL_NATURAL: |
| 485 | 485 | return TDbNullConversionMode::Preserved; |
@@ -495,19 +495,19 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | public function setNullConversion($value) |
| 497 | 497 | { |
| 498 | - switch(TPropertyValue::ensureEnum($value,'TDbNullConversionMode')) |
|
| 498 | + switch (TPropertyValue::ensureEnum($value, 'TDbNullConversionMode')) |
|
| 499 | 499 | { |
| 500 | 500 | case TDbNullConversionMode::Preserved: |
| 501 | - $value=PDO::NULL_NATURAL; |
|
| 501 | + $value = PDO::NULL_NATURAL; |
|
| 502 | 502 | break; |
| 503 | 503 | case TDbNullConversionMode::EmptyStringToNull: |
| 504 | - $value=PDO::NULL_EMPTY_STRING; |
|
| 504 | + $value = PDO::NULL_EMPTY_STRING; |
|
| 505 | 505 | break; |
| 506 | 506 | case TDbNullConversionMode::NullToEmptyString: |
| 507 | - $value=PDO::NULL_TO_STRING; |
|
| 507 | + $value = PDO::NULL_TO_STRING; |
|
| 508 | 508 | break; |
| 509 | 509 | } |
| 510 | - $this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value); |
|
| 510 | + $this->setAttribute(PDO::ATTR_ORACLE_NULLS, $value); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | */ |
| 526 | 526 | public function setAutoCommit($value) |
| 527 | 527 | { |
| 528 | - $this->setAttribute(PDO::ATTR_AUTOCOMMIT,TPropertyValue::ensureBoolean($value)); |
|
| 528 | + $this->setAttribute(PDO::ATTR_AUTOCOMMIT, TPropertyValue::ensureBoolean($value)); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | */ |
| 544 | 544 | public function setPersistent($value) |
| 545 | 545 | { |
| 546 | - return $this->setAttribute(PDO::ATTR_PERSISTENT,TPropertyValue::ensureBoolean($value)); |
|
| 546 | + return $this->setAttribute(PDO::ATTR_PERSISTENT, TPropertyValue::ensureBoolean($value)); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | public function getAttribute($name) |
| 613 | 613 | { |
| 614 | - if($this->getActive()) |
|
| 614 | + if ($this->getActive()) |
|
| 615 | 615 | return $this->_pdo->getAttribute($name); |
| 616 | 616 | else |
| 617 | 617 | throw new TDbException('dbconnection_connection_inactive'); |
@@ -623,12 +623,12 @@ discard block |
||
| 623 | 623 | * @param mixed the attribute value |
| 624 | 624 | * @see http://www.php.net/manual/en/function.PDO-setAttribute.php |
| 625 | 625 | */ |
| 626 | - public function setAttribute($name,$value) |
|
| 626 | + public function setAttribute($name, $value) |
|
| 627 | 627 | { |
| 628 | - if($this->_pdo instanceof PDO) |
|
| 629 | - $this->_pdo->setAttribute($name,$value); |
|
| 628 | + if ($this->_pdo instanceof PDO) |
|
| 629 | + $this->_pdo->setAttribute($name, $value); |
|
| 630 | 630 | else |
| 631 | - $this->_attributes[$name]=$value; |
|
| 631 | + $this->_attributes[$name] = $value; |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | |
@@ -644,15 +644,15 @@ discard block |
||
| 644 | 644 | /** |
| 645 | 645 | * Column name cases are kept as is from the database |
| 646 | 646 | */ |
| 647 | - const Preserved='Preserved'; |
|
| 647 | + const Preserved = 'Preserved'; |
|
| 648 | 648 | /** |
| 649 | 649 | * Column names are converted to lower case |
| 650 | 650 | */ |
| 651 | - const LowerCase='LowerCase'; |
|
| 651 | + const LowerCase = 'LowerCase'; |
|
| 652 | 652 | /** |
| 653 | 653 | * Column names are converted to upper case |
| 654 | 654 | */ |
| 655 | - const UpperCase='UpperCase'; |
|
| 655 | + const UpperCase = 'UpperCase'; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -667,14 +667,14 @@ discard block |
||
| 667 | 667 | /** |
| 668 | 668 | * No conversion is performed for null and empty values. |
| 669 | 669 | */ |
| 670 | - const Preserved='Preserved'; |
|
| 670 | + const Preserved = 'Preserved'; |
|
| 671 | 671 | /** |
| 672 | 672 | * NULL is converted to empty string |
| 673 | 673 | */ |
| 674 | - const NullToEmptyString='NullToEmptyString'; |
|
| 674 | + const NullToEmptyString = 'NullToEmptyString'; |
|
| 675 | 675 | /** |
| 676 | 676 | * Empty string is converted to NULL |
| 677 | 677 | */ |
| 678 | - const EmptyStringToNull='EmptyStringToNull'; |
|
| 678 | + const EmptyStringToNull = 'EmptyStringToNull'; |
|
| 679 | 679 | } |
| 680 | 680 | |
@@ -164,10 +164,11 @@ discard block |
||
| 164 | 164 | $value=TPropertyValue::ensureBoolean($value); |
| 165 | 165 | if($value!==$this->_active) |
| 166 | 166 | { |
| 167 | - if($value) |
|
| 168 | - $this->open(); |
|
| 169 | - else |
|
| 170 | - $this->close(); |
|
| 167 | + if($value) { |
|
| 168 | + $this->open(); |
|
| 169 | + } else { |
|
| 170 | + $this->close(); |
|
| 171 | + } |
|
| 171 | 172 | } |
| 172 | 173 | } |
| 173 | 174 | |
@@ -189,8 +190,7 @@ discard block |
||
| 189 | 190 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 190 | 191 | $this->_active=true; |
| 191 | 192 | $this->setConnectionCharset(); |
| 192 | - } |
|
| 193 | - catch(PDOException $e) |
|
| 193 | + } catch(PDOException $e) |
|
| 194 | 194 | { |
| 195 | 195 | throw new TDbException('dbconnection_open_failed',$e->getMessage()); |
| 196 | 196 | } |
@@ -214,8 +214,9 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function setConnectionCharset() |
| 216 | 216 | { |
| 217 | - if ($this->_charset === '' || $this->_active === false) |
|
| 218 | - return; |
|
| 217 | + if ($this->_charset === '' || $this->_active === false) { |
|
| 218 | + return; |
|
| 219 | + } |
|
| 219 | 220 | switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) |
| 220 | 221 | { |
| 221 | 222 | case 'mysql': |
@@ -313,10 +314,11 @@ discard block |
||
| 313 | 314 | */ |
| 314 | 315 | public function createCommand($sql) |
| 315 | 316 | { |
| 316 | - if($this->getActive()) |
|
| 317 | - return new TDbCommand($this,$sql); |
|
| 318 | - else |
|
| 319 | - throw new TDbException('dbconnection_connection_inactive'); |
|
| 317 | + if($this->getActive()) { |
|
| 318 | + return new TDbCommand($this,$sql); |
|
| 319 | + } else { |
|
| 320 | + throw new TDbException('dbconnection_connection_inactive'); |
|
| 321 | + } |
|
| 320 | 322 | } |
| 321 | 323 | |
| 322 | 324 | /** |
@@ -326,8 +328,9 @@ discard block |
||
| 326 | 328 | { |
| 327 | 329 | if($this->_transaction!==null) |
| 328 | 330 | { |
| 329 | - if($this->_transaction->getActive()) |
|
| 330 | - return $this->_transaction; |
|
| 331 | + if($this->_transaction->getActive()) { |
|
| 332 | + return $this->_transaction; |
|
| 333 | + } |
|
| 331 | 334 | } |
| 332 | 335 | return null; |
| 333 | 336 | } |
@@ -343,9 +346,9 @@ discard block |
||
| 343 | 346 | { |
| 344 | 347 | $this->_pdo->beginTransaction(); |
| 345 | 348 | return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); |
| 349 | + } else { |
|
| 350 | + throw new TDbException('dbconnection_connection_inactive'); |
|
| 346 | 351 | } |
| 347 | - else |
|
| 348 | - throw new TDbException('dbconnection_connection_inactive'); |
|
| 349 | 352 | } |
| 350 | 353 | |
| 351 | 354 | /** |
@@ -375,10 +378,11 @@ discard block |
||
| 375 | 378 | */ |
| 376 | 379 | public function getLastInsertID($sequenceName='') |
| 377 | 380 | { |
| 378 | - if($this->getActive()) |
|
| 379 | - return $this->_pdo->lastInsertId($sequenceName); |
|
| 380 | - else |
|
| 381 | - throw new TDbException('dbconnection_connection_inactive'); |
|
| 381 | + if($this->getActive()) { |
|
| 382 | + return $this->_pdo->lastInsertId($sequenceName); |
|
| 383 | + } else { |
|
| 384 | + throw new TDbException('dbconnection_connection_inactive'); |
|
| 385 | + } |
|
| 382 | 386 | } |
| 383 | 387 | |
| 384 | 388 | /** |
@@ -389,10 +393,11 @@ discard block |
||
| 389 | 393 | */ |
| 390 | 394 | public function quoteString($str) |
| 391 | 395 | { |
| 392 | - if($this->getActive()) |
|
| 393 | - return $this->_pdo->quote($str); |
|
| 394 | - else |
|
| 395 | - throw new TDbException('dbconnection_connection_inactive'); |
|
| 396 | + if($this->getActive()) { |
|
| 397 | + return $this->_pdo->quote($str); |
|
| 398 | + } else { |
|
| 399 | + throw new TDbException('dbconnection_connection_inactive'); |
|
| 400 | + } |
|
| 396 | 401 | } |
| 397 | 402 | |
| 398 | 403 | /** |
@@ -611,10 +616,11 @@ discard block |
||
| 611 | 616 | */ |
| 612 | 617 | public function getAttribute($name) |
| 613 | 618 | { |
| 614 | - if($this->getActive()) |
|
| 615 | - return $this->_pdo->getAttribute($name); |
|
| 616 | - else |
|
| 617 | - throw new TDbException('dbconnection_connection_inactive'); |
|
| 619 | + if($this->getActive()) { |
|
| 620 | + return $this->_pdo->getAttribute($name); |
|
| 621 | + } else { |
|
| 622 | + throw new TDbException('dbconnection_connection_inactive'); |
|
| 623 | + } |
|
| 618 | 624 | } |
| 619 | 625 | |
| 620 | 626 | /** |
@@ -625,10 +631,11 @@ discard block |
||
| 625 | 631 | */ |
| 626 | 632 | public function setAttribute($name,$value) |
| 627 | 633 | { |
| 628 | - if($this->_pdo instanceof PDO) |
|
| 629 | - $this->_pdo->setAttribute($name,$value); |
|
| 630 | - else |
|
| 631 | - $this->_attributes[$name]=$value; |
|
| 634 | + if($this->_pdo instanceof PDO) { |
|
| 635 | + $this->_pdo->setAttribute($name,$value); |
|
| 636 | + } else { |
|
| 637 | + $this->_attributes[$name]=$value; |
|
| 638 | + } |
|
| 632 | 639 | } |
| 633 | 640 | } |
| 634 | 641 | |
@@ -58,6 +58,7 @@ discard block |
||
| 58 | 58 | * should match the case of the column, as returned by the driver. |
| 59 | 59 | * @param mixed Name of the PHP variable to which the column will be bound. |
| 60 | 60 | * @param int Data type of the parameter |
| 61 | + * @param integer $column |
|
| 61 | 62 | * @see http://www.php.net/manual/en/function.PDOStatement-bindColumn.php |
| 62 | 63 | */ |
| 63 | 64 | public function bindColumn($column, &$value, $dataType=null) |
@@ -89,6 +90,7 @@ discard block |
||
| 89 | 90 | /** |
| 90 | 91 | * Returns a single column from the next row of a result set. |
| 91 | 92 | * @param int zero-based column index |
| 93 | + * @param integer $columnIndex |
|
| 92 | 94 | * @return mixed|false the column of the current row, false if no more row available |
| 93 | 95 | */ |
| 94 | 96 | public function readColumn($columnIndex) |
@@ -100,6 +102,8 @@ discard block |
||
| 100 | 102 | * Returns a single column from the next row of a result set. |
| 101 | 103 | * @param string class name of the object to be created and populated |
| 102 | 104 | * @param array list of column names whose values are to be passed as parameters in the constructor of the class being created |
| 105 | + * @param string $className |
|
| 106 | + * @param string[] $fields |
|
| 103 | 107 | * @return mixed|false the populated object, false if no more row of data available |
| 104 | 108 | */ |
| 105 | 109 | public function readObject($className,$fields) |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | class TDbDataReader extends TComponent implements Iterator |
| 36 | 36 | { |
| 37 | 37 | private $_statement; |
| 38 | - private $_closed=false; |
|
| 38 | + private $_closed = false; |
|
| 39 | 39 | private $_row; |
| 40 | - private $_index=-1; |
|
| 40 | + private $_index = -1; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Constructor. |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __construct(TDbCommand $command) |
| 47 | 47 | { |
| 48 | - $this->_statement=$command->getPdoStatement(); |
|
| 48 | + $this->_statement = $command->getPdoStatement(); |
|
| 49 | 49 | $this->_statement->setFetchMode(PDO::FETCH_ASSOC); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | * @param int Data type of the parameter |
| 61 | 61 | * @see http://www.php.net/manual/en/function.PDOStatement-bindColumn.php |
| 62 | 62 | */ |
| 63 | - public function bindColumn($column, &$value, $dataType=null) |
|
| 63 | + public function bindColumn($column, &$value, $dataType = null) |
|
| 64 | 64 | { |
| 65 | - if($dataType===null) |
|
| 66 | - $this->_statement->bindColumn($column,$value); |
|
| 65 | + if ($dataType === null) |
|
| 66 | + $this->_statement->bindColumn($column, $value); |
|
| 67 | 67 | else |
| 68 | - $this->_statement->bindColumn($column,$value,$dataType); |
|
| 68 | + $this->_statement->bindColumn($column, $value, $dataType); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function setFetchMode($mode) |
| 75 | 75 | { |
| 76 | - $params=func_get_args(); |
|
| 77 | - call_user_func_array(array($this->_statement,'setFetchMode'),$params); |
|
| 76 | + $params = func_get_args(); |
|
| 77 | + call_user_func_array(array($this->_statement, 'setFetchMode'), $params); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | * @param array list of column names whose values are to be passed as parameters in the constructor of the class being created |
| 103 | 103 | * @return mixed|false the populated object, false if no more row of data available |
| 104 | 104 | */ |
| 105 | - public function readObject($className,$fields) |
|
| 105 | + public function readObject($className, $fields) |
|
| 106 | 106 | { |
| 107 | - return $this->_statement->fetchObject($className,$fields); |
|
| 107 | + return $this->_statement->fetchObject($className, $fields); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public function close() |
| 135 | 135 | { |
| 136 | 136 | $this->_statement->closeCursor(); |
| 137 | - $this->_closed=true; |
|
| 137 | + $this->_closed = true; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function rewind() |
| 173 | 173 | { |
| 174 | - if($this->_index<0) |
|
| 174 | + if ($this->_index < 0) |
|
| 175 | 175 | { |
| 176 | - $this->_row=$this->_statement->fetch(); |
|
| 177 | - $this->_index=0; |
|
| 176 | + $this->_row = $this->_statement->fetch(); |
|
| 177 | + $this->_index = 0; |
|
| 178 | 178 | } |
| 179 | 179 | else |
| 180 | 180 | throw new TDbException('dbdatareader_rewind_invalid'); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public function next() |
| 208 | 208 | { |
| 209 | - $this->_row=$this->_statement->fetch(); |
|
| 209 | + $this->_row = $this->_statement->fetch(); |
|
| 210 | 210 | $this->_index++; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | public function valid() |
| 219 | 219 | { |
| 220 | - return $this->_row!==false; |
|
| 220 | + return $this->_row !== false; |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
@@ -62,10 +62,11 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function bindColumn($column, &$value, $dataType=null) |
| 64 | 64 | { |
| 65 | - if($dataType===null) |
|
| 66 | - $this->_statement->bindColumn($column,$value); |
|
| 67 | - else |
|
| 68 | - $this->_statement->bindColumn($column,$value,$dataType); |
|
| 65 | + if($dataType===null) { |
|
| 66 | + $this->_statement->bindColumn($column,$value); |
|
| 67 | + } else { |
|
| 68 | + $this->_statement->bindColumn($column,$value,$dataType); |
|
| 69 | + } |
|
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | /** |
@@ -175,9 +176,9 @@ discard block |
||
| 175 | 176 | { |
| 176 | 177 | $this->_row=$this->_statement->fetch(); |
| 177 | 178 | $this->_index=0; |
| 179 | + } else { |
|
| 180 | + throw new TDbException('dbdatareader_rewind_invalid'); |
|
| 178 | 181 | } |
| 179 | - else |
|
| 180 | - throw new TDbException('dbdatareader_rewind_invalid'); |
|
| 181 | 182 | } |
| 182 | 183 | |
| 183 | 184 | /** |
@@ -101,6 +101,7 @@ |
||
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * @param boolean whether this transaction is active |
| 104 | + * @param boolean $value |
|
| 104 | 105 | */ |
| 105 | 106 | protected function setActive($value) |
| 106 | 107 | { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | class TDbTransaction extends TComponent |
| 41 | 41 | { |
| 42 | - private $_connection=null; |
|
| 42 | + private $_connection = null; |
|
| 43 | 43 | private $_active; |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function __construct(TDbConnection $connection) |
| 51 | 51 | { |
| 52 | - $this->_connection=$connection; |
|
| 52 | + $this->_connection = $connection; |
|
| 53 | 53 | $this->setActive(true); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function commit() |
| 61 | 61 | { |
| 62 | - if($this->_active && $this->_connection->getActive()) |
|
| 62 | + if ($this->_active && $this->_connection->getActive()) |
|
| 63 | 63 | { |
| 64 | 64 | $this->_connection->getPdoInstance()->commit(); |
| 65 | - $this->_active=false; |
|
| 65 | + $this->_active = false; |
|
| 66 | 66 | } |
| 67 | 67 | else |
| 68 | 68 | throw new TDbException('dbtransaction_transaction_inactive'); |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function rollback() |
| 76 | 76 | { |
| 77 | - if($this->_active && $this->_connection->getActive()) |
|
| 77 | + if ($this->_active && $this->_connection->getActive()) |
|
| 78 | 78 | { |
| 79 | 79 | $this->_connection->getPdoInstance()->rollBack(); |
| 80 | - $this->_active=false; |
|
| 80 | + $this->_active = false; |
|
| 81 | 81 | } |
| 82 | 82 | else |
| 83 | 83 | throw new TDbException('dbtransaction_transaction_inactive'); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function setActive($value) |
| 106 | 106 | { |
| 107 | - $this->_active=TPropertyValue::ensureBoolean($value); |
|
| 107 | + $this->_active = TPropertyValue::ensureBoolean($value); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | $this->_connection->getPdoInstance()->commit(); |
| 65 | 65 | $this->_active=false; |
| 66 | + } else { |
|
| 67 | + throw new TDbException('dbtransaction_transaction_inactive'); |
|
| 66 | 68 | } |
| 67 | - else |
|
| 68 | - throw new TDbException('dbtransaction_transaction_inactive'); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $this->_connection->getPdoInstance()->rollBack(); |
| 80 | 80 | $this->_active=false; |
| 81 | + } else { |
|
| 82 | + throw new TDbException('dbtransaction_transaction_inactive'); |
|
| 81 | 83 | } |
| 82 | - else |
|
| 83 | - throw new TDbException('dbtransaction_transaction_inactive'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -109,6 +109,7 @@ discard block |
||
| 109 | 109 | * It terminates the application immediately after the error is displayed. |
| 110 | 110 | * @param mixed sender of the event |
| 111 | 111 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
| 112 | + * @param null|TApplication $sender |
|
| 112 | 113 | */ |
| 113 | 114 | public function handleError($sender,$param) |
| 114 | 115 | { |
@@ -363,6 +364,9 @@ discard block |
||
| 363 | 364 | return $result; |
| 364 | 365 | } |
| 365 | 366 | |
| 367 | + /** |
|
| 368 | + * @param string $pattern |
|
| 369 | + */ |
|
| 366 | 370 | private function getPropertyAccessTrace($trace,$pattern) |
| 367 | 371 | { |
| 368 | 372 | $result=null; |
@@ -395,6 +399,9 @@ discard block |
||
| 395 | 399 | return $source; |
| 396 | 400 | } |
| 397 | 401 | |
| 402 | + /** |
|
| 403 | + * @param string $message |
|
| 404 | + */ |
|
| 398 | 405 | private function addLink($message) |
| 399 | 406 | { |
| 400 | 407 | $baseUrl='http://pradosoft.github.io/docs/manual/class-'; |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * error template file basename |
| 54 | 54 | */ |
| 55 | - const ERROR_FILE_NAME='error'; |
|
| 55 | + const ERROR_FILE_NAME = 'error'; |
|
| 56 | 56 | /** |
| 57 | 57 | * exception template file basename |
| 58 | 58 | */ |
| 59 | - const EXCEPTION_FILE_NAME='exception'; |
|
| 59 | + const EXCEPTION_FILE_NAME = 'exception'; |
|
| 60 | 60 | /** |
| 61 | 61 | * number of lines before and after the error line to be displayed in case of an exception |
| 62 | 62 | */ |
| 63 | - const SOURCE_LINES=12; |
|
| 63 | + const SOURCE_LINES = 12; |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * @var string error template directory |
| 67 | 67 | */ |
| 68 | - private $_templatePath=null; |
|
| 68 | + private $_templatePath = null; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Initializes the module. |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getErrorTemplatePath() |
| 84 | 84 | { |
| 85 | - if($this->_templatePath===null) |
|
| 86 | - $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
| 85 | + if ($this->_templatePath === null) |
|
| 86 | + $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
| 87 | 87 | return $this->_templatePath; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function setErrorTemplatePath($value) |
| 97 | 97 | { |
| 98 | - if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
|
| 99 | - $this->_templatePath=$templatePath; |
|
| 98 | + if (($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
| 99 | + $this->_templatePath = $templatePath; |
|
| 100 | 100 | else |
| 101 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 101 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -110,30 +110,30 @@ discard block |
||
| 110 | 110 | * @param mixed sender of the event |
| 111 | 111 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
| 112 | 112 | */ |
| 113 | - public function handleError($sender,$param) |
|
| 113 | + public function handleError($sender, $param) |
|
| 114 | 114 | { |
| 115 | - static $handling=false; |
|
| 115 | + static $handling = false; |
|
| 116 | 116 | // We need to restore error and exception handlers, |
| 117 | 117 | // because within error and exception handlers, new errors and exceptions |
| 118 | 118 | // cannot be handled properly by PHP |
| 119 | 119 | restore_error_handler(); |
| 120 | 120 | restore_exception_handler(); |
| 121 | 121 | // ensure that we do not enter infinite loop of error handling |
| 122 | - if($handling) |
|
| 122 | + if ($handling) |
|
| 123 | 123 | $this->handleRecursiveError($param); |
| 124 | 124 | else |
| 125 | 125 | { |
| 126 | - $handling=true; |
|
| 127 | - if(($response=$this->getResponse())!==null) |
|
| 126 | + $handling = true; |
|
| 127 | + if (($response = $this->getResponse()) !== null) |
|
| 128 | 128 | $response->clear(); |
| 129 | - if(!headers_sent()) |
|
| 129 | + if (!headers_sent()) |
|
| 130 | 130 | header('Content-Type: text/html; charset=UTF-8'); |
| 131 | - if($param instanceof THttpException) |
|
| 132 | - $this->handleExternalError($param->getStatusCode(),$param); |
|
| 133 | - else if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 131 | + if ($param instanceof THttpException) |
|
| 132 | + $this->handleExternalError($param->getStatusCode(), $param); |
|
| 133 | + else if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
| 134 | 134 | $this->displayException($param); |
| 135 | 135 | else |
| 136 | - $this->handleExternalError(500,$param); |
|
| 136 | + $this->handleExternalError(500, $param); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,22 +144,22 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | * @since 3.1.6 |
| 146 | 146 | */ |
| 147 | - protected static function hideSecurityRelated($value, $exception=null) |
|
| 147 | + protected static function hideSecurityRelated($value, $exception = null) |
|
| 148 | 148 | { |
| 149 | 149 | $aRpl = array(); |
| 150 | - if($exception !== null && $exception instanceof Exception) |
|
| 150 | + if ($exception !== null && $exception instanceof Exception) |
|
| 151 | 151 | { |
| 152 | 152 | $aTrace = $exception->getTrace(); |
| 153 | - foreach($aTrace as $item) |
|
| 153 | + foreach ($aTrace as $item) |
|
| 154 | 154 | { |
| 155 | - if(isset($item['file'])) |
|
| 155 | + if (isset($item['file'])) |
|
| 156 | 156 | $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
| 160 | 160 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
| 161 | 161 | $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
| 162 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 162 | + if (isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 163 | 163 | $aRpl = array_reverse($aRpl, true); |
| 164 | 164 | |
| 165 | 165 | return str_replace(array_keys($aRpl), $aRpl, $value); |
@@ -172,36 +172,36 @@ discard block |
||
| 172 | 172 | * @param integer response status code |
| 173 | 173 | * @param Exception exception instance |
| 174 | 174 | */ |
| 175 | - protected function handleExternalError($statusCode,$exception) |
|
| 175 | + protected function handleExternalError($statusCode, $exception) |
|
| 176 | 176 | { |
| 177 | - if(!($exception instanceof THttpException)) |
|
| 177 | + if (!($exception instanceof THttpException)) |
|
| 178 | 178 | error_log($exception->__toString()); |
| 179 | 179 | |
| 180 | - $content=$this->getErrorTemplate($statusCode,$exception); |
|
| 180 | + $content = $this->getErrorTemplate($statusCode, $exception); |
|
| 181 | 181 | |
| 182 | - $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
|
| 182 | + $serverAdmin = isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : ''; |
|
| 183 | 183 | |
| 184 | - $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug; |
|
| 184 | + $isDebug = $this->getApplication()->getMode() === TApplicationMode::Debug; |
|
| 185 | 185 | |
| 186 | 186 | $errorMessage = $exception->getMessage(); |
| 187 | - if($isDebug) |
|
| 188 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 187 | + if ($isDebug) |
|
| 188 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
| 189 | 189 | else |
| 190 | 190 | { |
| 191 | - $version=''; |
|
| 191 | + $version = ''; |
|
| 192 | 192 | $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
| 193 | 193 | } |
| 194 | - $tokens=array( |
|
| 194 | + $tokens = array( |
|
| 195 | 195 | '%%StatusCode%%' => "$statusCode", |
| 196 | 196 | '%%ErrorMessage%%' => htmlspecialchars($errorMessage), |
| 197 | 197 | '%%ServerAdmin%%' => $serverAdmin, |
| 198 | 198 | '%%Version%%' => $version, |
| 199 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
| 199 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | 202 | $this->getApplication()->getResponse()->setStatusCode($statusCode, $isDebug ? $exception->getMessage() : null); |
| 203 | 203 | |
| 204 | - echo strtr($content,$tokens); |
|
| 204 | + echo strtr($content, $tokens); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,16 +213,16 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | protected function handleRecursiveError($exception) |
| 215 | 215 | { |
| 216 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 216 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
| 217 | 217 | { |
| 218 | 218 | echo "<html><head><title>Recursive Error</title></head>\n"; |
| 219 | 219 | echo "<body><h1>Recursive Error</h1>\n"; |
| 220 | - echo "<pre>".$exception->__toString()."</pre>\n"; |
|
| 220 | + echo "<pre>" . $exception->__toString() . "</pre>\n"; |
|
| 221 | 221 | echo "</body></html>"; |
| 222 | 222 | } |
| 223 | 223 | else |
| 224 | 224 | { |
| 225 | - error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
|
| 225 | + error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
|
| 226 | 226 | header('HTTP/1.0 500 Internal Error'); |
| 227 | 227 | } |
| 228 | 228 | } |
@@ -236,55 +236,55 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | protected function displayException($exception) |
| 238 | 238 | { |
| 239 | - if(php_sapi_name()==='cli') |
|
| 239 | + if (php_sapi_name() === 'cli') |
|
| 240 | 240 | { |
| 241 | - echo $exception->getMessage()."\n"; |
|
| 241 | + echo $exception->getMessage() . "\n"; |
|
| 242 | 242 | echo $exception->getTraceAsString(); |
| 243 | 243 | return; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if($exception instanceof TTemplateException) |
|
| 246 | + if ($exception instanceof TTemplateException) |
|
| 247 | 247 | { |
| 248 | - $fileName=$exception->getTemplateFile(); |
|
| 249 | - $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName); |
|
| 250 | - $source=$this->getSourceCode($lines,$exception->getLineNumber()); |
|
| 251 | - if($fileName==='') |
|
| 252 | - $fileName='---embedded template---'; |
|
| 253 | - $errorLine=$exception->getLineNumber(); |
|
| 248 | + $fileName = $exception->getTemplateFile(); |
|
| 249 | + $lines = empty($fileName) ? explode("\n", $exception->getTemplateSource()) : @file($fileName); |
|
| 250 | + $source = $this->getSourceCode($lines, $exception->getLineNumber()); |
|
| 251 | + if ($fileName === '') |
|
| 252 | + $fileName = '---embedded template---'; |
|
| 253 | + $errorLine = $exception->getLineNumber(); |
|
| 254 | 254 | } |
| 255 | 255 | else |
| 256 | 256 | { |
| 257 | - if(($trace=$this->getExactTrace($exception))!==null) |
|
| 257 | + if (($trace = $this->getExactTrace($exception)) !== null) |
|
| 258 | 258 | { |
| 259 | - $fileName=$trace['file']; |
|
| 260 | - $errorLine=$trace['line']; |
|
| 259 | + $fileName = $trace['file']; |
|
| 260 | + $errorLine = $trace['line']; |
|
| 261 | 261 | } |
| 262 | 262 | else |
| 263 | 263 | { |
| 264 | - $fileName=$exception->getFile(); |
|
| 265 | - $errorLine=$exception->getLine(); |
|
| 264 | + $fileName = $exception->getFile(); |
|
| 265 | + $errorLine = $exception->getLine(); |
|
| 266 | 266 | } |
| 267 | - $source=$this->getSourceCode(@file($fileName),$errorLine); |
|
| 267 | + $source = $this->getSourceCode(@file($fileName), $errorLine); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 271 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 270 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
| 271 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
| 272 | 272 | else |
| 273 | - $version=''; |
|
| 273 | + $version = ''; |
|
| 274 | 274 | |
| 275 | - $tokens=array( |
|
| 275 | + $tokens = array( |
|
| 276 | 276 | '%%ErrorType%%' => get_class($exception), |
| 277 | 277 | '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), |
| 278 | - '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', |
|
| 278 | + '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', |
|
| 279 | 279 | '%%SourceCode%%' => $source, |
| 280 | 280 | '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), |
| 281 | 281 | '%%Version%%' => $version, |
| 282 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
| 282 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
| 283 | 283 | ); |
| 284 | 284 | |
| 285 | - $content=$this->getExceptionTemplate($exception); |
|
| 285 | + $content = $this->getExceptionTemplate($exception); |
|
| 286 | 286 | |
| 287 | - echo strtr($content,$tokens); |
|
| 287 | + echo strtr($content, $tokens); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | protected function getExceptionTemplate($exception) |
| 298 | 298 | { |
| 299 | - $lang=Prado::getPreferredLanguage(); |
|
| 300 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
|
| 301 | - if(!is_file($exceptionFile)) |
|
| 302 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
| 303 | - if(($content=@file_get_contents($exceptionFile))===false) |
|
| 299 | + $lang = Prado::getPreferredLanguage(); |
|
| 300 | + $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '-' . $lang . '.html'; |
|
| 301 | + if (!is_file($exceptionFile)) |
|
| 302 | + $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
| 303 | + if (($content = @file_get_contents($exceptionFile)) === false) |
|
| 304 | 304 | die("Unable to open exception template file '$exceptionFile'."); |
| 305 | 305 | return $content; |
| 306 | 306 | } |
@@ -321,84 +321,84 @@ discard block |
||
| 321 | 321 | * @param Exception the exception to be displayed |
| 322 | 322 | * @return string the template content |
| 323 | 323 | */ |
| 324 | - protected function getErrorTemplate($statusCode,$exception) |
|
| 324 | + protected function getErrorTemplate($statusCode, $exception) |
|
| 325 | 325 | { |
| 326 | - $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
|
| 327 | - $lang=Prado::getPreferredLanguage(); |
|
| 328 | - if(is_file("$base$statusCode-$lang.html")) |
|
| 329 | - $errorFile="$base$statusCode-$lang.html"; |
|
| 330 | - else if(is_file("$base$statusCode.html")) |
|
| 331 | - $errorFile="$base$statusCode.html"; |
|
| 332 | - else if(is_file("$base-$lang.html")) |
|
| 333 | - $errorFile="$base-$lang.html"; |
|
| 326 | + $base = $this->getErrorTemplatePath() . DIRECTORY_SEPARATOR . self::ERROR_FILE_NAME; |
|
| 327 | + $lang = Prado::getPreferredLanguage(); |
|
| 328 | + if (is_file("$base$statusCode-$lang.html")) |
|
| 329 | + $errorFile = "$base$statusCode-$lang.html"; |
|
| 330 | + else if (is_file("$base$statusCode.html")) |
|
| 331 | + $errorFile = "$base$statusCode.html"; |
|
| 332 | + else if (is_file("$base-$lang.html")) |
|
| 333 | + $errorFile = "$base-$lang.html"; |
|
| 334 | 334 | else |
| 335 | - $errorFile="$base.html"; |
|
| 336 | - if(($content=@file_get_contents($errorFile))===false) |
|
| 335 | + $errorFile = "$base.html"; |
|
| 336 | + if (($content = @file_get_contents($errorFile)) === false) |
|
| 337 | 337 | die("Unable to open error template file '$errorFile'."); |
| 338 | 338 | return $content; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | private function getExactTrace($exception) |
| 342 | 342 | { |
| 343 | - $trace=$exception->getTrace(); |
|
| 344 | - $result=null; |
|
| 343 | + $trace = $exception->getTrace(); |
|
| 344 | + $result = null; |
|
| 345 | 345 | // if PHP exception, we want to show the 2nd stack level context |
| 346 | 346 | // because the 1st stack level is of little use (it's in error handler) |
| 347 | - if($exception instanceof TPhpErrorException) |
|
| 347 | + if ($exception instanceof TPhpErrorException) |
|
| 348 | 348 | { |
| 349 | - if(isset($trace[0]['file'])) |
|
| 350 | - $result=$trace[0]; |
|
| 351 | - elseif(isset($trace[1])) |
|
| 352 | - $result=$trace[1]; |
|
| 349 | + if (isset($trace[0]['file'])) |
|
| 350 | + $result = $trace[0]; |
|
| 351 | + elseif (isset($trace[1])) |
|
| 352 | + $result = $trace[1]; |
|
| 353 | 353 | } |
| 354 | - else if($exception instanceof TInvalidOperationException) |
|
| 354 | + else if ($exception instanceof TInvalidOperationException) |
|
| 355 | 355 | { |
| 356 | 356 | // in case of getter or setter error, find out the exact file and row |
| 357 | - if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
|
| 358 | - $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 357 | + if (($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
| 358 | + $result = $this->getPropertyAccessTrace($trace, '__set'); |
|
| 359 | 359 | } |
| 360 | - if($result!==null && strpos($result['file'],': eval()\'d code')!==false) |
|
| 360 | + if ($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
| 361 | 361 | return null; |
| 362 | 362 | |
| 363 | 363 | return $result; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - private function getPropertyAccessTrace($trace,$pattern) |
|
| 366 | + private function getPropertyAccessTrace($trace, $pattern) |
|
| 367 | 367 | { |
| 368 | - $result=null; |
|
| 369 | - foreach($trace as $t) |
|
| 368 | + $result = null; |
|
| 369 | + foreach ($trace as $t) |
|
| 370 | 370 | { |
| 371 | - if(isset($t['function']) && $t['function']===$pattern) |
|
| 372 | - $result=$t; |
|
| 371 | + if (isset($t['function']) && $t['function'] === $pattern) |
|
| 372 | + $result = $t; |
|
| 373 | 373 | else |
| 374 | 374 | break; |
| 375 | 375 | } |
| 376 | 376 | return $result; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - private function getSourceCode($lines,$errorLine) |
|
| 379 | + private function getSourceCode($lines, $errorLine) |
|
| 380 | 380 | { |
| 381 | - $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0; |
|
| 382 | - $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines); |
|
| 381 | + $beginLine = $errorLine - self::SOURCE_LINES >= 0 ? $errorLine - self::SOURCE_LINES : 0; |
|
| 382 | + $endLine = $errorLine + self::SOURCE_LINES <= count($lines) ? $errorLine + self::SOURCE_LINES : count($lines); |
|
| 383 | 383 | |
| 384 | - $source=''; |
|
| 385 | - for($i=$beginLine;$i<$endLine;++$i) |
|
| 384 | + $source = ''; |
|
| 385 | + for ($i = $beginLine; $i < $endLine; ++$i) |
|
| 386 | 386 | { |
| 387 | - if($i===$errorLine-1) |
|
| 387 | + if ($i === $errorLine - 1) |
|
| 388 | 388 | { |
| 389 | - $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 390 | - $source.="<div class=\"error\">".$line."</div>"; |
|
| 389 | + $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
| 390 | + $source .= "<div class=\"error\">" . $line . "</div>"; |
|
| 391 | 391 | } |
| 392 | 392 | else |
| 393 | - $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 393 | + $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
| 394 | 394 | } |
| 395 | 395 | return $source; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | private function addLink($message) |
| 399 | 399 | { |
| 400 | - $baseUrl='http://pradosoft.github.io/docs/manual/class-'; |
|
| 401 | - return preg_replace('/\b(T[A-Z]\w+)\b/',"<a href=\"$baseUrl\${1}\" target=\"_blank\">\${1}</a>",$message); |
|
| 400 | + $baseUrl = 'http://pradosoft.github.io/docs/manual/class-'; |
|
| 401 | + return preg_replace('/\b(T[A-Z]\w+)\b/', "<a href=\"$baseUrl\${1}\" target=\"_blank\">\${1}</a>", $message); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
@@ -82,8 +82,9 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getErrorTemplatePath() |
| 84 | 84 | { |
| 85 | - if($this->_templatePath===null) |
|
| 86 | - $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
| 85 | + if($this->_templatePath===null) { |
|
| 86 | + $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
| 87 | + } |
|
| 87 | 88 | return $this->_templatePath; |
| 88 | 89 | } |
| 89 | 90 | |
@@ -95,10 +96,11 @@ discard block |
||
| 95 | 96 | */ |
| 96 | 97 | public function setErrorTemplatePath($value) |
| 97 | 98 | { |
| 98 | - if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
|
| 99 | - $this->_templatePath=$templatePath; |
|
| 100 | - else |
|
| 101 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 99 | + if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) { |
|
| 100 | + $this->_templatePath=$templatePath; |
|
| 101 | + } else { |
|
| 102 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 103 | + } |
|
| 102 | 104 | } |
| 103 | 105 | |
| 104 | 106 | /** |
@@ -119,21 +121,24 @@ discard block |
||
| 119 | 121 | restore_error_handler(); |
| 120 | 122 | restore_exception_handler(); |
| 121 | 123 | // ensure that we do not enter infinite loop of error handling |
| 122 | - if($handling) |
|
| 123 | - $this->handleRecursiveError($param); |
|
| 124 | - else |
|
| 124 | + if($handling) { |
|
| 125 | + $this->handleRecursiveError($param); |
|
| 126 | + } else |
|
| 125 | 127 | { |
| 126 | 128 | $handling=true; |
| 127 | - if(($response=$this->getResponse())!==null) |
|
| 128 | - $response->clear(); |
|
| 129 | - if(!headers_sent()) |
|
| 130 | - header('Content-Type: text/html; charset=UTF-8'); |
|
| 131 | - if($param instanceof THttpException) |
|
| 132 | - $this->handleExternalError($param->getStatusCode(),$param); |
|
| 133 | - else if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 134 | - $this->displayException($param); |
|
| 135 | - else |
|
| 136 | - $this->handleExternalError(500,$param); |
|
| 129 | + if(($response=$this->getResponse())!==null) { |
|
| 130 | + $response->clear(); |
|
| 131 | + } |
|
| 132 | + if(!headers_sent()) { |
|
| 133 | + header('Content-Type: text/html; charset=UTF-8'); |
|
| 134 | + } |
|
| 135 | + if($param instanceof THttpException) { |
|
| 136 | + $this->handleExternalError($param->getStatusCode(),$param); |
|
| 137 | + } else if($this->getApplication()->getMode()===TApplicationMode::Debug) { |
|
| 138 | + $this->displayException($param); |
|
| 139 | + } else { |
|
| 140 | + $this->handleExternalError(500,$param); |
|
| 141 | + } |
|
| 137 | 142 | } |
| 138 | 143 | } |
| 139 | 144 | |
@@ -152,14 +157,17 @@ discard block |
||
| 152 | 157 | $aTrace = $exception->getTrace(); |
| 153 | 158 | foreach($aTrace as $item) |
| 154 | 159 | { |
| 155 | - if(isset($item['file'])) |
|
| 156 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
| 160 | + if(isset($item['file'])) { |
|
| 161 | + $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
| 162 | + } |
|
| 157 | 163 | } |
| 158 | 164 | } |
| 159 | 165 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
| 160 | 166 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
| 161 | 167 | $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
| 162 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 168 | + if(isset($aRpl[DIRECTORY_SEPARATOR])) { |
|
| 169 | + unset($aRpl[DIRECTORY_SEPARATOR]); |
|
| 170 | + } |
|
| 163 | 171 | $aRpl = array_reverse($aRpl, true); |
| 164 | 172 | |
| 165 | 173 | return str_replace(array_keys($aRpl), $aRpl, $value); |
@@ -174,8 +182,9 @@ discard block |
||
| 174 | 182 | */ |
| 175 | 183 | protected function handleExternalError($statusCode,$exception) |
| 176 | 184 | { |
| 177 | - if(!($exception instanceof THttpException)) |
|
| 178 | - error_log($exception->__toString()); |
|
| 185 | + if(!($exception instanceof THttpException)) { |
|
| 186 | + error_log($exception->__toString()); |
|
| 187 | + } |
|
| 179 | 188 | |
| 180 | 189 | $content=$this->getErrorTemplate($statusCode,$exception); |
| 181 | 190 | |
@@ -184,9 +193,9 @@ discard block |
||
| 184 | 193 | $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug; |
| 185 | 194 | |
| 186 | 195 | $errorMessage = $exception->getMessage(); |
| 187 | - if($isDebug) |
|
| 188 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 189 | - else |
|
| 196 | + if($isDebug) { |
|
| 197 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 198 | + } else |
|
| 190 | 199 | { |
| 191 | 200 | $version=''; |
| 192 | 201 | $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
@@ -219,8 +228,7 @@ discard block |
||
| 219 | 228 | echo "<body><h1>Recursive Error</h1>\n"; |
| 220 | 229 | echo "<pre>".$exception->__toString()."</pre>\n"; |
| 221 | 230 | echo "</body></html>"; |
| 222 | - } |
|
| 223 | - else |
|
| 231 | + } else |
|
| 224 | 232 | { |
| 225 | 233 | error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
| 226 | 234 | header('HTTP/1.0 500 Internal Error'); |
@@ -248,18 +256,17 @@ discard block |
||
| 248 | 256 | $fileName=$exception->getTemplateFile(); |
| 249 | 257 | $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName); |
| 250 | 258 | $source=$this->getSourceCode($lines,$exception->getLineNumber()); |
| 251 | - if($fileName==='') |
|
| 252 | - $fileName='---embedded template---'; |
|
| 259 | + if($fileName==='') { |
|
| 260 | + $fileName='---embedded template---'; |
|
| 261 | + } |
|
| 253 | 262 | $errorLine=$exception->getLineNumber(); |
| 254 | - } |
|
| 255 | - else |
|
| 263 | + } else |
|
| 256 | 264 | { |
| 257 | 265 | if(($trace=$this->getExactTrace($exception))!==null) |
| 258 | 266 | { |
| 259 | 267 | $fileName=$trace['file']; |
| 260 | 268 | $errorLine=$trace['line']; |
| 261 | - } |
|
| 262 | - else |
|
| 269 | + } else |
|
| 263 | 270 | { |
| 264 | 271 | $fileName=$exception->getFile(); |
| 265 | 272 | $errorLine=$exception->getLine(); |
@@ -267,10 +274,11 @@ discard block |
||
| 267 | 274 | $source=$this->getSourceCode(@file($fileName),$errorLine); |
| 268 | 275 | } |
| 269 | 276 | |
| 270 | - if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
| 271 | - $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 272 | - else |
|
| 273 | - $version=''; |
|
| 277 | + if($this->getApplication()->getMode()===TApplicationMode::Debug) { |
|
| 278 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
| 279 | + } else { |
|
| 280 | + $version=''; |
|
| 281 | + } |
|
| 274 | 282 | |
| 275 | 283 | $tokens=array( |
| 276 | 284 | '%%ErrorType%%' => get_class($exception), |
@@ -298,10 +306,12 @@ discard block |
||
| 298 | 306 | { |
| 299 | 307 | $lang=Prado::getPreferredLanguage(); |
| 300 | 308 | $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
| 301 | - if(!is_file($exceptionFile)) |
|
| 302 | - $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
| 303 | - if(($content=@file_get_contents($exceptionFile))===false) |
|
| 304 | - die("Unable to open exception template file '$exceptionFile'."); |
|
| 309 | + if(!is_file($exceptionFile)) { |
|
| 310 | + $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
| 311 | + } |
|
| 312 | + if(($content=@file_get_contents($exceptionFile))===false) { |
|
| 313 | + die("Unable to open exception template file '$exceptionFile'."); |
|
| 314 | + } |
|
| 305 | 315 | return $content; |
| 306 | 316 | } |
| 307 | 317 | |
@@ -325,16 +335,18 @@ discard block |
||
| 325 | 335 | { |
| 326 | 336 | $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
| 327 | 337 | $lang=Prado::getPreferredLanguage(); |
| 328 | - if(is_file("$base$statusCode-$lang.html")) |
|
| 329 | - $errorFile="$base$statusCode-$lang.html"; |
|
| 330 | - else if(is_file("$base$statusCode.html")) |
|
| 331 | - $errorFile="$base$statusCode.html"; |
|
| 332 | - else if(is_file("$base-$lang.html")) |
|
| 333 | - $errorFile="$base-$lang.html"; |
|
| 334 | - else |
|
| 335 | - $errorFile="$base.html"; |
|
| 336 | - if(($content=@file_get_contents($errorFile))===false) |
|
| 337 | - die("Unable to open error template file '$errorFile'."); |
|
| 338 | + if(is_file("$base$statusCode-$lang.html")) { |
|
| 339 | + $errorFile="$base$statusCode-$lang.html"; |
|
| 340 | + } else if(is_file("$base$statusCode.html")) { |
|
| 341 | + $errorFile="$base$statusCode.html"; |
|
| 342 | + } else if(is_file("$base-$lang.html")) { |
|
| 343 | + $errorFile="$base-$lang.html"; |
|
| 344 | + } else { |
|
| 345 | + $errorFile="$base.html"; |
|
| 346 | + } |
|
| 347 | + if(($content=@file_get_contents($errorFile))===false) { |
|
| 348 | + die("Unable to open error template file '$errorFile'."); |
|
| 349 | + } |
|
| 338 | 350 | return $content; |
| 339 | 351 | } |
| 340 | 352 | |
@@ -346,19 +358,21 @@ discard block |
||
| 346 | 358 | // because the 1st stack level is of little use (it's in error handler) |
| 347 | 359 | if($exception instanceof TPhpErrorException) |
| 348 | 360 | { |
| 349 | - if(isset($trace[0]['file'])) |
|
| 350 | - $result=$trace[0]; |
|
| 351 | - elseif(isset($trace[1])) |
|
| 352 | - $result=$trace[1]; |
|
| 353 | - } |
|
| 354 | - else if($exception instanceof TInvalidOperationException) |
|
| 361 | + if(isset($trace[0]['file'])) { |
|
| 362 | + $result=$trace[0]; |
|
| 363 | + } elseif(isset($trace[1])) { |
|
| 364 | + $result=$trace[1]; |
|
| 365 | + } |
|
| 366 | + } else if($exception instanceof TInvalidOperationException) |
|
| 355 | 367 | { |
| 356 | 368 | // in case of getter or setter error, find out the exact file and row |
| 357 | - if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
|
| 358 | - $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 369 | + if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) { |
|
| 370 | + $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + if($result!==null && strpos($result['file'],': eval()\'d code')!==false) { |
|
| 374 | + return null; |
|
| 359 | 375 | } |
| 360 | - if($result!==null && strpos($result['file'],': eval()\'d code')!==false) |
|
| 361 | - return null; |
|
| 362 | 376 | |
| 363 | 377 | return $result; |
| 364 | 378 | } |
@@ -368,10 +382,11 @@ discard block |
||
| 368 | 382 | $result=null; |
| 369 | 383 | foreach($trace as $t) |
| 370 | 384 | { |
| 371 | - if(isset($t['function']) && $t['function']===$pattern) |
|
| 372 | - $result=$t; |
|
| 373 | - else |
|
| 374 | - break; |
|
| 385 | + if(isset($t['function']) && $t['function']===$pattern) { |
|
| 386 | + $result=$t; |
|
| 387 | + } else { |
|
| 388 | + break; |
|
| 389 | + } |
|
| 375 | 390 | } |
| 376 | 391 | return $result; |
| 377 | 392 | } |
@@ -388,9 +403,9 @@ discard block |
||
| 388 | 403 | { |
| 389 | 404 | $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
| 390 | 405 | $source.="<div class=\"error\">".$line."</div>"; |
| 406 | + } else { |
|
| 407 | + $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 391 | 408 | } |
| 392 | - else |
|
| 393 | - $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 394 | 409 | } |
| 395 | 410 | return $source; |
| 396 | 411 | } |