@@ -40,6 +40,7 @@ discard block |
||
40 | 40 | * @param int page size |
41 | 41 | * @param mixed delegate for each data row retrieved. |
42 | 42 | * @param int number of page to fetch on initialization |
43 | + * @param integer $pageSize |
|
43 | 44 | */ |
44 | 45 | public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0) |
45 | 46 | { |
@@ -55,6 +56,8 @@ discard block |
||
55 | 56 | * @param mixed query parameters |
56 | 57 | * @param int page size. |
57 | 58 | * @param int number of page. |
59 | + * @param IMappedStatement $statement |
|
60 | + * @param integer $page |
|
58 | 61 | */ |
59 | 62 | protected function initialize($statement, $parameter, $pageSize, $page) |
60 | 63 | { |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | private $_parameter; |
32 | 32 | private $_prevPageList; |
33 | 33 | private $_nextPageList; |
34 | - private $_delegate=null; |
|
34 | + private $_delegate = null; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Create a new SqlMap paged list. |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | * @param mixed delegate for each data row retrieved. |
42 | 42 | * @param int number of page to fetch on initialization |
43 | 43 | */ |
44 | - public function __construct(IMappedStatement $statement,$parameter, $pageSize, $delegate=null, $page=0) |
|
44 | + public function __construct(IMappedStatement $statement, $parameter, $pageSize, $delegate = null, $page = 0) |
|
45 | 45 | { |
46 | 46 | parent::__construct(); |
47 | 47 | parent::setCustomPaging(true); |
48 | - $this->initialize($statement,$parameter, $pageSize, $page); |
|
49 | - $this->_delegate=$delegate; |
|
48 | + $this->initialize($statement, $parameter, $pageSize, $page); |
|
49 | + $this->_delegate = $delegate; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | { |
115 | 115 | $total = $data instanceof TList ? $data->getCount() : count($data); |
116 | 116 | $pageSize = $this->getPageSize(); |
117 | - if($total < 1) |
|
117 | + if ($total < 1) |
|
118 | 118 | { |
119 | 119 | $param->setData($data); |
120 | 120 | $this->_prevPageList = null; |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - if($param->getNewPageIndex() < 1) |
|
125 | + if ($param->getNewPageIndex() < 1) |
|
126 | 126 | { |
127 | 127 | $this->_prevPageList = null; |
128 | - if($total <= $pageSize) |
|
128 | + if ($total <= $pageSize) |
|
129 | 129 | { |
130 | 130 | $param->setData($data); |
131 | 131 | $this->_nextPageList = null; |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | else |
134 | 134 | { |
135 | 135 | $param->setData(array_slice($data, 0, $pageSize)); |
136 | - $this->_nextPageList = array_slice($data, $pageSize-1,$total); |
|
136 | + $this->_nextPageList = array_slice($data, $pageSize - 1, $total); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | else |
140 | 140 | { |
141 | - if($total <= $pageSize) |
|
141 | + if ($total <= $pageSize) |
|
142 | 142 | { |
143 | 143 | $this->_prevPageList = array_slice($data, 0, $total); |
144 | 144 | $param->setData(array()); |
145 | 145 | $this->_nextPageList = null; |
146 | 146 | } |
147 | - else if($total <= $pageSize*2) |
|
147 | + else if ($total <= $pageSize * 2) |
|
148 | 148 | { |
149 | 149 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
150 | 150 | $param->setData(array_slice($data, $pageSize, $total)); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | { |
155 | 155 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
156 | 156 | $param->setData(array_slice($data, $pageSize, $pageSize)); |
157 | - $this->_nextPageList = array_slice($data, $pageSize*2, $total-$pageSize*2); |
|
157 | + $this->_nextPageList = array_slice($data, $pageSize * 2, $total - $pageSize * 2); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $index = $param->getNewPageIndex(); |
170 | 170 | $pageSize = $this->getPageSize(); |
171 | - return $index < 1 ? array($index, $pageSize*2) : array(($index-1)*$pageSize, $pageSize*3); |
|
171 | + return $index < 1 ? array($index, $pageSize * 2) : array(($index - 1) * $pageSize, $pageSize * 3); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function getIsNextPageAvailable() |
178 | 178 | { |
179 | - return $this->_nextPageList!==null; |
|
179 | + return $this->_nextPageList !== null; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function getIsPreviousPageAvailable() |
186 | 186 | { |
187 | - return $this->_prevPageList!==null; |
|
187 | + return $this->_prevPageList !== null; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function getIsLastPage() |
194 | 194 | { |
195 | - return ($this->_nextPageList===null) || $this->_nextPageList->getCount() < 1; |
|
195 | + return ($this->_nextPageList === null) || $this->_nextPageList->getCount() < 1; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -129,28 +129,24 @@ |
||
129 | 129 | { |
130 | 130 | $param->setData($data); |
131 | 131 | $this->_nextPageList = null; |
132 | - } |
|
133 | - else |
|
132 | + } else |
|
134 | 133 | { |
135 | 134 | $param->setData(array_slice($data, 0, $pageSize)); |
136 | 135 | $this->_nextPageList = array_slice($data, $pageSize-1,$total); |
137 | 136 | } |
138 | - } |
|
139 | - else |
|
137 | + } else |
|
140 | 138 | { |
141 | 139 | if($total <= $pageSize) |
142 | 140 | { |
143 | 141 | $this->_prevPageList = array_slice($data, 0, $total); |
144 | 142 | $param->setData(array()); |
145 | 143 | $this->_nextPageList = null; |
146 | - } |
|
147 | - else if($total <= $pageSize*2) |
|
144 | + } else if($total <= $pageSize*2) |
|
148 | 145 | { |
149 | 146 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
150 | 147 | $param->setData(array_slice($data, $pageSize, $total)); |
151 | 148 | $this->_nextPageList = null; |
152 | - } |
|
153 | - else |
|
149 | + } else |
|
154 | 150 | { |
155 | 151 | $this->_prevPageList = array_slice($data, 0, $pageSize); |
156 | 152 | $param->setData(array_slice($data, $pageSize, $pageSize)); |
@@ -40,6 +40,7 @@ discard block |
||
40 | 40 | * @param mixed The object used to set the parameters in the SQL. |
41 | 41 | * @param string The property of the result object to be used as the key. |
42 | 42 | * @param string The property of the result object to be used as the value (or null) |
43 | + * @param TDbConnection $connection |
|
43 | 44 | * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>. |
44 | 45 | */ |
45 | 46 | public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null); |
@@ -50,6 +51,7 @@ discard block |
||
50 | 51 | * number of row effected. |
51 | 52 | * @param IDbConnection database connection to execute the query |
52 | 53 | * @param mixed The object used to set the parameters in the SQL. |
54 | + * @param TDbConnection $connection |
|
53 | 55 | * @return integer The number of row effected. |
54 | 56 | */ |
55 | 57 | public function executeUpdate($connection, $parameter); |
@@ -62,6 +64,7 @@ discard block |
||
62 | 64 | * @param TList A list to populate the result with. |
63 | 65 | * @param integer The number of rows to skip over. |
64 | 66 | * @param integer The maximum number of rows to return. |
67 | + * @param TDbConnection $connection |
|
65 | 68 | * @return TList A TList of result objects. |
66 | 69 | */ |
67 | 70 | public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1); |
@@ -73,6 +76,7 @@ discard block |
||
73 | 76 | * @param IDbConnection database connection to execute the query |
74 | 77 | * @param mixed The object used to set the parameters in the SQL. |
75 | 78 | * @param object The result object. |
79 | + * @param TDbConnection $connection |
|
76 | 80 | * @return object result. |
77 | 81 | */ |
78 | 82 | public function executeQueryForObject($connection,$parameter, $result=null); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string The property of the result object to be used as the value (or null) |
43 | 43 | * @return TMap A map of object containing the rows keyed by <tt>$keyProperty</tt>. |
44 | 44 | */ |
45 | - public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null); |
|
45 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param integer The maximum number of rows to return. |
65 | 65 | * @return TList A TList of result objects. |
66 | 66 | */ |
67 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1); |
|
67 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | /** |
@@ -75,6 +75,6 @@ discard block |
||
75 | 75 | * @param object The result object. |
76 | 76 | * @return object result. |
77 | 77 | */ |
78 | - public function executeQueryForObject($connection,$parameter, $result=null); |
|
78 | + public function executeQueryForObject($connection, $parameter, $result = null); |
|
79 | 79 | } |
80 | 80 |
@@ -97,6 +97,10 @@ |
||
97 | 97 | return $cacheKey->getHash(); |
98 | 98 | } |
99 | 99 | |
100 | + /** |
|
101 | + * @param integer $skip |
|
102 | + * @param integer $max |
|
103 | + */ |
|
100 | 104 | protected function createCommand($connection, $parameter, $skip=null, $max=null) |
101 | 105 | { |
102 | 106 | return $this->_mappedStatement->getCommand()->create($this->getManager(), |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | return $this->_mappedStatement->getManager(); |
41 | 41 | } |
42 | 42 | |
43 | - public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $skip=-1, $max=-1,$delegate=null) |
|
43 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
|
44 | 44 | { |
45 | 45 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
46 | - $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max)); |
|
46 | + $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty, $skip, $max)); |
|
47 | 47 | $map = $this->getStatement()->getCache()->get($key); |
48 | - if($map===null) |
|
48 | + if ($map === null) |
|
49 | 49 | { |
50 | 50 | $map = $this->_mappedStatement->runQueryForMap( |
51 | - $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
|
51 | + $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
|
52 | 52 | $this->getStatement()->getCache()->set($key, $map); |
53 | 53 | } |
54 | 54 | return $map; |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | return $this->executeInsert($connection, $parameter); |
65 | 65 | } |
66 | 66 | |
67 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null) |
|
67 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1, $delegate = null) |
|
68 | 68 | { |
69 | 69 | $sql = $this->createCommand($connection, $parameter, $skip, $max); |
70 | 70 | $key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max)); |
71 | 71 | $list = $this->getStatement()->getCache()->get($key); |
72 | - if($list===null) |
|
72 | + if ($list === null) |
|
73 | 73 | { |
74 | 74 | $list = $this->_mappedStatement->runQueryForList( |
75 | 75 | $connection, $parameter, $sql, $result, $delegate); |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | return $list; |
79 | 79 | } |
80 | 80 | |
81 | - public function executeQueryForObject($connection, $parameter, $result=null) |
|
81 | + public function executeQueryForObject($connection, $parameter, $result = null) |
|
82 | 82 | { |
83 | 83 | $sql = $this->createCommand($connection, $parameter); |
84 | 84 | $key = $this->getCacheKey(array(clone($sql), $parameter)); |
85 | 85 | $object = $this->getStatement()->getCache()->get($key); |
86 | - if($object===null) |
|
86 | + if ($object === null) |
|
87 | 87 | { |
88 | 88 | $object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result); |
89 | 89 | $this->getStatement()->getCache()->set($key, $object); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return $cacheKey->getHash(); |
98 | 98 | } |
99 | 99 | |
100 | - protected function createCommand($connection, $parameter, $skip=null, $max=null) |
|
100 | + protected function createCommand($connection, $parameter, $skip = null, $max = null) |
|
101 | 101 | { |
102 | 102 | return $this->_mappedStatement->getCommand()->create($this->getManager(), |
103 | 103 | $connection, $this->getStatement(), $parameter, $skip, $max); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * @return TSqlMapper The SqlMap used by this MappedStatement |
|
87 | + * @return TSqlMapManager The SqlMap used by this MappedStatement |
|
88 | 88 | */ |
89 | 89 | public function getManager() |
90 | 90 | { |
@@ -469,6 +469,7 @@ discard block |
||
469 | 469 | * @param IDbConnection database connection |
470 | 470 | * @param mixed insert statement parameter |
471 | 471 | * @param TSqlMapSelectKey select key statement |
472 | + * @param TSqlMapSelectKey $selectKey |
|
472 | 473 | * @return string last insert ID. |
473 | 474 | */ |
474 | 475 | protected function executeSelectKey($connection, $parameter, $selectKey) |
@@ -569,6 +570,7 @@ discard block |
||
569 | 570 | * @param string result object class name |
570 | 571 | * @param array a result set row retrieved from the database |
571 | 572 | * @param object the result object, will create if necessary. |
573 | + * @param string $resultClass |
|
572 | 574 | * @return object result object filled with data |
573 | 575 | */ |
574 | 576 | protected function fillResultClass($resultClass, $row, $resultObject) |
@@ -591,6 +593,7 @@ discard block |
||
591 | 593 | * Apply the result to a TList or an array. |
592 | 594 | * @param array a result set row retrieved from the database |
593 | 595 | * @param object result object, array or list |
596 | + * @param ArrayAccess $resultObject |
|
594 | 597 | * @return object result filled with data. |
595 | 598 | */ |
596 | 599 | protected function fillResultArrayList($row, $resultObject) |
@@ -633,6 +636,7 @@ discard block |
||
633 | 636 | * @param string result map name. |
634 | 637 | * @param array a result set row retrieved from the database |
635 | 638 | * @param object result object to fill, will create new instances if required. |
639 | + * @param string $parentGroup |
|
636 | 640 | * @return object result object filled with data. |
637 | 641 | */ |
638 | 642 | protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
@@ -772,6 +776,7 @@ discard block |
||
772 | 776 | * Converts the first array value to scalar value of given type. |
773 | 777 | * @param array list of results |
774 | 778 | * @param string scalar type. |
779 | + * @param string $type |
|
775 | 780 | * @return mixed scalar value. |
776 | 781 | */ |
777 | 782 | protected function getScalarResult($result, $type) |
@@ -961,6 +966,10 @@ discard block |
||
961 | 966 | public function setKeys($value){ $this->_keys = $value; } |
962 | 967 | |
963 | 968 | public function getMethod(){ return $this->_method; } |
969 | + |
|
970 | + /** |
|
971 | + * @param integer $value |
|
972 | + */ |
|
964 | 973 | public function setMethod($value){ $this->_method = $value; } |
965 | 974 | } |
966 | 975 | |
@@ -1003,6 +1012,7 @@ discard block |
||
1003 | 1012 | * @param string parent node id |
1004 | 1013 | * @param string new node id |
1005 | 1014 | * @param mixed node value |
1015 | + * @param string $node |
|
1006 | 1016 | */ |
1007 | 1017 | public function add($parent, $node, $object='') |
1008 | 1018 | { |
@@ -1168,6 +1178,9 @@ discard block |
||
1168 | 1178 | private $_parameterObject; |
1169 | 1179 | private $_list; |
1170 | 1180 | |
1181 | + /** |
|
1182 | + * @param ArrayAccess $list |
|
1183 | + */ |
|
1171 | 1184 | public function __construct($result, $parameter, &$list) |
1172 | 1185 | { |
1173 | 1186 | $this->_resultObject = $result; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var TPostSelectBinding[] post select statement queue. |
41 | 41 | */ |
42 | - private $_selectQueue=array(); |
|
42 | + private $_selectQueue = array(); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var boolean true when data is mapped to a particular row. |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function executeSQLQueryLimit($connection, $command, $max, $skip) |
163 | 163 | { |
164 | - if($max>-1 || $skip > -1) |
|
164 | + if ($max > -1 || $skip > -1) |
|
165 | 165 | { |
166 | - $maxStr=$max>0?' LIMIT '.$max:''; |
|
167 | - $skipStr=$skip>0?' OFFSET '.$skip:''; |
|
168 | - $command->setText($command->getText().$maxStr.$skipStr); |
|
166 | + $maxStr = $max > 0 ? ' LIMIT ' . $max : ''; |
|
167 | + $skipStr = $skip > 0 ? ' OFFSET ' . $skip : ''; |
|
168 | + $command->setText($command->getText() . $maxStr . $skipStr); |
|
169 | 169 | } |
170 | 170 | $connection->setActive(true); |
171 | 171 | return $command->query(); |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * @param callback row delegate handler |
200 | 200 | * @see executeQueryForList() |
201 | 201 | */ |
202 | - public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null) |
|
202 | + public function executeQueryForList($connection, $parameter, $result = null, $skip = -1, $max = -1, $delegate = null) |
|
203 | 203 | { |
204 | - $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max); |
|
204 | + $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
|
205 | 205 | return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate); |
206 | 206 | } |
207 | 207 | |
@@ -221,17 +221,16 @@ discard block |
||
221 | 221 | * @return array a list of result objects |
222 | 222 | * @see executeQueryForList() |
223 | 223 | */ |
224 | - public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null) |
|
224 | + public function runQueryForList($connection, $parameter, $sql, $result, $delegate = null) |
|
225 | 225 | { |
226 | - $registry=$this->getManager()->getTypeHandlers(); |
|
227 | - $list = $result instanceof ArrayAccess ? $result : |
|
228 | - $this->_statement->createInstanceOfListClass($registry); |
|
226 | + $registry = $this->getManager()->getTypeHandlers(); |
|
227 | + $list = $result instanceof ArrayAccess ? $result : $this->_statement->createInstanceOfListClass($registry); |
|
229 | 228 | $connection->setActive(true); |
230 | 229 | $reader = $sql->query(); |
231 | 230 | //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip); |
232 | - if($delegate!==null) |
|
231 | + if ($delegate !== null) |
|
233 | 232 | { |
234 | - foreach($reader as $row) |
|
233 | + foreach ($reader as $row) |
|
235 | 234 | { |
236 | 235 | $obj = $this->applyResultMap($row); |
237 | 236 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
@@ -241,14 +240,14 @@ discard block |
||
241 | 240 | else |
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | - foreach($reader as $row) |
|
243 | + foreach ($reader as $row) |
|
245 | 244 | { |
246 | 245 | // var_dump($row); |
247 | 246 | $list[] = $this->applyResultMap($row); |
248 | 247 | } |
249 | 248 | } |
250 | 249 | |
251 | - if(!$this->_groupBy->isEmpty()) |
|
250 | + if (!$this->_groupBy->isEmpty()) |
|
252 | 251 | { |
253 | 252 | $list = $this->_groupBy->collect(); |
254 | 253 | $this->initialGroupByResults(); |
@@ -272,7 +271,7 @@ discard block |
||
272 | 271 | * @param callback row delegate handler |
273 | 272 | * @return array An array of object containing the rows keyed by keyProperty. |
274 | 273 | */ |
275 | - public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null) |
|
274 | + public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty = null, $skip = -1, $max = -1, $delegate = null) |
|
276 | 275 | { |
277 | 276 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max); |
278 | 277 | return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate); |
@@ -296,21 +295,20 @@ discard block |
||
296 | 295 | * @return array An array of object containing the rows keyed by keyProperty. |
297 | 296 | * @see executeQueryForMap() |
298 | 297 | */ |
299 | - public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty=null, $delegate=null) |
|
298 | + public function runQueryForMap($connection, $parameter, $command, $keyProperty, $valueProperty = null, $delegate = null) |
|
300 | 299 | { |
301 | 300 | $map = array(); |
302 | 301 | //$recordSet = $this->executeSQLQuery($connection, $sql); |
303 | 302 | $connection->setActive(true); |
304 | 303 | $reader = $command->query(); |
305 | - if($delegate!==null) |
|
304 | + if ($delegate !== null) |
|
306 | 305 | { |
307 | 306 | //while($row = $recordSet->fetchRow()) |
308 | - foreach($reader as $row) |
|
307 | + foreach ($reader as $row) |
|
309 | 308 | { |
310 | 309 | $obj = $this->applyResultMap($row); |
311 | 310 | $key = TPropertyAccess::get($obj, $keyProperty); |
312 | - $value = ($valueProperty===null) ? $obj : |
|
313 | - TPropertyAccess::get($obj, $valueProperty); |
|
311 | + $value = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
314 | 312 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 313 | $this->raiseRowDelegate($delegate, $param); |
316 | 314 | } |
@@ -318,12 +316,11 @@ discard block |
||
318 | 316 | else |
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | - foreach($reader as $row) |
|
319 | + foreach ($reader as $row) |
|
322 | 320 | { |
323 | 321 | $obj = $this->applyResultMap($row); |
324 | 322 | $key = TPropertyAccess::get($obj, $keyProperty); |
325 | - $map[$key] = ($valueProperty===null) ? $obj : |
|
326 | - TPropertyAccess::get($obj, $valueProperty); |
|
323 | + $map[$key] = ($valueProperty === null) ? $obj : TPropertyAccess::get($obj, $valueProperty); |
|
327 | 324 | } |
328 | 325 | } |
329 | 326 | $this->onExecuteQuery($command); |
@@ -338,24 +335,24 @@ discard block |
||
338 | 335 | */ |
339 | 336 | protected function raiseRowDelegate($handler, $param) |
340 | 337 | { |
341 | - if(is_string($handler)) |
|
338 | + if (is_string($handler)) |
|
342 | 339 | { |
343 | - call_user_func($handler,$this,$param); |
|
340 | + call_user_func($handler, $this, $param); |
|
344 | 341 | } |
345 | - else if(is_callable($handler,true)) |
|
342 | + else if (is_callable($handler, true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | - list($object,$method)=$handler; |
|
349 | - if(is_string($object)) // static method call |
|
350 | - call_user_func($handler,$this,$param); |
|
345 | + list($object, $method) = $handler; |
|
346 | + if (is_string($object)) // static method call |
|
347 | + call_user_func($handler, $this, $param); |
|
351 | 348 | else |
352 | 349 | { |
353 | - if(($pos=strrpos($method,'.'))!==false) |
|
350 | + if (($pos = strrpos($method, '.')) !== false) |
|
354 | 351 | { |
355 | - $object=$this->getSubProperty(substr($method,0,$pos)); |
|
356 | - $method=substr($method,$pos+1); |
|
352 | + $object = $this->getSubProperty(substr($method, 0, $pos)); |
|
353 | + $method = substr($method, $pos + 1); |
|
357 | 354 | } |
358 | - $object->$method($this,$param); |
|
355 | + $object->$method($this, $param); |
|
359 | 356 | } |
360 | 357 | } |
361 | 358 | else |
@@ -370,7 +367,7 @@ discard block |
||
370 | 367 | * @param mixed The result object. |
371 | 368 | * @return ${return} |
372 | 369 | */ |
373 | - public function executeQueryForObject($connection, $parameter, $result=null) |
|
370 | + public function executeQueryForObject($connection, $parameter, $result = null) |
|
374 | 371 | { |
375 | 372 | $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter); |
376 | 373 | return $this->runQueryForObject($connection, $sql, $result); |
@@ -393,10 +390,10 @@ discard block |
||
393 | 390 | { |
394 | 391 | $object = null; |
395 | 392 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
393 | + foreach ($command->query() as $row) |
|
397 | 394 | $object = $this->applyResultMap($row, $result); |
398 | 395 | |
399 | - if(!$this->_groupBy->isEmpty()) |
|
396 | + if (!$this->_groupBy->isEmpty()) |
|
400 | 397 | { |
401 | 398 | $list = $this->_groupBy->collect(); |
402 | 399 | $this->initialGroupByResults(); |
@@ -424,7 +421,7 @@ discard block |
||
424 | 421 | // var_dump($command,$parameter); |
425 | 422 | $result = $command->execute(); |
426 | 423 | |
427 | - if($generatedKey===null) |
|
424 | + if ($generatedKey === null) |
|
428 | 425 | $generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter); |
429 | 426 | |
430 | 427 | $this->executePostSelect($connection); |
@@ -440,10 +437,10 @@ discard block |
||
440 | 437 | */ |
441 | 438 | protected function getPreGeneratedSelectKey($connection, $parameter) |
442 | 439 | { |
443 | - if($this->_statement instanceof TSqlMapInsert) |
|
440 | + if ($this->_statement instanceof TSqlMapInsert) |
|
444 | 441 | { |
445 | 442 | $selectKey = $this->_statement->getSelectKey(); |
446 | - if(($selectKey!==null) && !$selectKey->getIsAfter()) |
|
443 | + if (($selectKey !== null) && !$selectKey->getIsAfter()) |
|
447 | 444 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
448 | 445 | } |
449 | 446 | } |
@@ -456,10 +453,10 @@ discard block |
||
456 | 453 | */ |
457 | 454 | protected function getPostGeneratedSelectKey($connection, $parameter) |
458 | 455 | { |
459 | - if($this->_statement instanceof TSqlMapInsert) |
|
456 | + if ($this->_statement instanceof TSqlMapInsert) |
|
460 | 457 | { |
461 | 458 | $selectKey = $this->_statement->getSelectKey(); |
462 | - if(($selectKey!==null) && $selectKey->getIsAfter()) |
|
459 | + if (($selectKey !== null) && $selectKey->getIsAfter()) |
|
463 | 460 | return $this->executeSelectKey($connection, $parameter, $selectKey); |
464 | 461 | } |
465 | 462 | } |
@@ -476,7 +473,7 @@ discard block |
||
476 | 473 | $mappedStatement = $this->getManager()->getMappedStatement($selectKey->getID()); |
477 | 474 | $generatedKey = $mappedStatement->executeQueryForObject( |
478 | 475 | $connection, $parameter, null); |
479 | - if(strlen($prop = $selectKey->getProperty()) > 0) |
|
476 | + if (strlen($prop = $selectKey->getProperty()) > 0) |
|
480 | 477 | TPropertyAccess::set($parameter, $prop, $generatedKey); |
481 | 478 | return $generatedKey; |
482 | 479 | } |
@@ -490,7 +487,7 @@ discard block |
||
490 | 487 | */ |
491 | 488 | public function executeUpdate($connection, $parameter) |
492 | 489 | { |
493 | - $sql = $this->_command->create($this->getManager(),$connection, $this->_statement, $parameter); |
|
490 | + $sql = $this->_command->create($this->getManager(), $connection, $this->_statement, $parameter); |
|
494 | 491 | $affectedRows = $sql->execute(); |
495 | 492 | //$this->executeSQLQuery($connection, $sql); |
496 | 493 | $this->executePostSelect($connection); |
@@ -504,7 +501,7 @@ discard block |
||
504 | 501 | */ |
505 | 502 | protected function executePostSelect($connection) |
506 | 503 | { |
507 | - while(count($this->_selectQueue)) |
|
504 | + while (count($this->_selectQueue)) |
|
508 | 505 | { |
509 | 506 | $postSelect = array_shift($this->_selectQueue); |
510 | 507 | $method = $postSelect->getMethod(); |
@@ -513,15 +510,15 @@ discard block |
||
513 | 510 | $keys = $postSelect->getKeys(); |
514 | 511 | $resultObject = $postSelect->getResultObject(); |
515 | 512 | |
516 | - if($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
513 | + if ($method == self::QUERY_FOR_LIST || $method == self::QUERY_FOR_ARRAY) |
|
517 | 514 | { |
518 | 515 | $values = $statement->executeQueryForList($connection, $keys, null); |
519 | 516 | |
520 | - if($method == self::QUERY_FOR_ARRAY) |
|
517 | + if ($method == self::QUERY_FOR_ARRAY) |
|
521 | 518 | $values = $values->toArray(); |
522 | 519 | TPropertyAccess::set($resultObject, $property, $values); |
523 | 520 | } |
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
521 | + else if ($method == self::QUERY_FOR_OBJECT) |
|
525 | 522 | { |
526 | 523 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 524 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -544,23 +541,23 @@ discard block |
||
544 | 541 | * @param object the result object, will create if necessary. |
545 | 542 | * @return object the result filled with data, null if not filled. |
546 | 543 | */ |
547 | - protected function applyResultMap($row, &$resultObject=null) |
|
544 | + protected function applyResultMap($row, &$resultObject = null) |
|
548 | 545 | { |
549 | - if($row === false) return null; |
|
546 | + if ($row === false) return null; |
|
550 | 547 | |
551 | 548 | $resultMapName = $this->_statement->getResultMap(); |
552 | 549 | $resultClass = $this->_statement->getResultClass(); |
553 | 550 | |
554 | - $obj=null; |
|
555 | - if($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
551 | + $obj = null; |
|
552 | + if ($this->getManager()->getResultMaps()->contains($resultMapName)) |
|
556 | 553 | $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject); |
557 | - else if(strlen($resultClass) > 0) |
|
554 | + else if (strlen($resultClass) > 0) |
|
558 | 555 | $obj = $this->fillResultClass($resultClass, $row, $resultObject); |
559 | 556 | else |
560 | 557 | $obj = $this->fillDefaultResultMap(null, $row, $resultObject); |
561 | - if(class_exists('TActiveRecord',false) && $obj instanceof TActiveRecord) |
|
558 | + if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) |
|
562 | 559 | //Create a new clean active record. |
563 | - $obj=TActiveRecord::createRecord(get_class($obj),$obj); |
|
560 | + $obj = TActiveRecord::createRecord(get_class($obj), $obj); |
|
564 | 561 | return $obj; |
565 | 562 | } |
566 | 563 | |
@@ -573,15 +570,15 @@ discard block |
||
573 | 570 | */ |
574 | 571 | protected function fillResultClass($resultClass, $row, $resultObject) |
575 | 572 | { |
576 | - if($resultObject===null) |
|
573 | + if ($resultObject === null) |
|
577 | 574 | { |
578 | 575 | $registry = $this->getManager()->getTypeHandlers(); |
579 | - $resultObject = $this->_statement->createInstanceOfResultClass($registry,$row); |
|
576 | + $resultObject = $this->_statement->createInstanceOfResultClass($registry, $row); |
|
580 | 577 | } |
581 | 578 | |
582 | - if($resultObject instanceOf ArrayAccess) |
|
579 | + if ($resultObject instanceOf ArrayAccess) |
|
583 | 580 | return $this->fillResultArrayList($row, $resultObject); |
584 | - else if(is_object($resultObject)) |
|
581 | + else if (is_object($resultObject)) |
|
585 | 582 | return $this->fillResultObjectProperty($row, $resultObject); |
586 | 583 | else |
587 | 584 | return $this->fillDefaultResultMap(null, $row, $resultObject); |
@@ -595,11 +592,11 @@ discard block |
||
595 | 592 | */ |
596 | 593 | protected function fillResultArrayList($row, $resultObject) |
597 | 594 | { |
598 | - if($resultObject instanceof TList) |
|
599 | - foreach($row as $v) |
|
595 | + if ($resultObject instanceof TList) |
|
596 | + foreach ($row as $v) |
|
600 | 597 | $resultObject[] = $v; |
601 | 598 | else |
602 | - foreach($row as $k => $v) |
|
599 | + foreach ($row as $k => $v) |
|
603 | 600 | $resultObject[$k] = $v; |
604 | 601 | return $resultObject; |
605 | 602 | } |
@@ -613,17 +610,17 @@ discard block |
||
613 | 610 | protected function fillResultObjectProperty($row, $resultObject) |
614 | 611 | { |
615 | 612 | $index = 0; |
616 | - $registry=$this->getManager()->getTypeHandlers(); |
|
617 | - foreach($row as $k=>$v) |
|
613 | + $registry = $this->getManager()->getTypeHandlers(); |
|
614 | + foreach ($row as $k=>$v) |
|
618 | 615 | { |
619 | 616 | $property = new TResultProperty; |
620 | - if(is_string($k) && strlen($k) > 0) |
|
617 | + if (is_string($k) && strlen($k) > 0) |
|
621 | 618 | $property->setColumn($k); |
622 | 619 | $property->setColumnIndex(++$index); |
623 | - $type = gettype(TPropertyAccess::get($resultObject,$k)); |
|
620 | + $type = gettype(TPropertyAccess::get($resultObject, $k)); |
|
624 | 621 | $property->setType($type); |
625 | - $value = $property->getPropertyValue($registry,$row); |
|
626 | - TPropertyAccess::set($resultObject, $k,$value); |
|
622 | + $value = $property->getPropertyValue($registry, $row); |
|
623 | + TPropertyAccess::set($resultObject, $k, $value); |
|
627 | 624 | } |
628 | 625 | return $resultObject; |
629 | 626 | } |
@@ -635,21 +632,21 @@ discard block |
||
635 | 632 | * @param object result object to fill, will create new instances if required. |
636 | 633 | * @return object result object filled with data. |
637 | 634 | */ |
638 | - protected function fillResultMap($resultMapName, $row, $parentGroup=null, &$resultObject=null) |
|
635 | + protected function fillResultMap($resultMapName, $row, $parentGroup = null, &$resultObject = null) |
|
639 | 636 | { |
640 | 637 | $resultMap = $this->getManager()->getResultMap($resultMapName); |
641 | 638 | $registry = $this->getManager()->getTypeHandlers(); |
642 | - $resultMap = $resultMap->resolveSubMap($registry,$row); |
|
639 | + $resultMap = $resultMap->resolveSubMap($registry, $row); |
|
643 | 640 | |
644 | - if($resultObject===null) |
|
641 | + if ($resultObject === null) |
|
645 | 642 | $resultObject = $resultMap->createInstanceOfResult($registry); |
646 | 643 | |
647 | - if(is_object($resultObject)) |
|
644 | + if (is_object($resultObject)) |
|
648 | 645 | { |
649 | - if(strlen($resultMap->getGroupBy()) > 0) |
|
646 | + if (strlen($resultMap->getGroupBy()) > 0) |
|
650 | 647 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
651 | 648 | else |
652 | - foreach($resultMap->getColumns() as $property) |
|
649 | + foreach ($resultMap->getColumns() as $property) |
|
653 | 650 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
654 | 651 | } |
655 | 652 | else |
@@ -671,26 +668,26 @@ discard block |
||
671 | 668 | { |
672 | 669 | $group = $this->getResultMapGroupKey($resultMap, $row); |
673 | 670 | |
674 | - if(empty($parent)) |
|
671 | + if (empty($parent)) |
|
675 | 672 | { |
676 | 673 | $rootObject = array('object'=>$resultObject, 'property' => null); |
677 | 674 | $this->_groupBy->add(null, $group, $rootObject); |
678 | 675 | } |
679 | 676 | |
680 | - foreach($resultMap->getColumns() as $property) |
|
677 | + foreach ($resultMap->getColumns() as $property) |
|
681 | 678 | { |
682 | 679 | //set properties. |
683 | 680 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
684 | 681 | $nested = $property->getResultMapping(); |
685 | 682 | |
686 | 683 | //nested property |
687 | - if($this->getManager()->getResultMaps()->contains($nested)) |
|
684 | + if ($this->getManager()->getResultMaps()->contains($nested)) |
|
688 | 685 | { |
689 | 686 | $nestedMap = $this->getManager()->getResultMap($nested); |
690 | 687 | $groupKey = $this->getResultMapGroupKey($nestedMap, $row); |
691 | 688 | |
692 | 689 | //add the node reference first |
693 | - if(empty($parent)) |
|
690 | + if (empty($parent)) |
|
694 | 691 | $this->_groupBy->add($group, $groupKey, ''); |
695 | 692 | |
696 | 693 | //get the nested result mapping value |
@@ -698,7 +695,7 @@ discard block |
||
698 | 695 | |
699 | 696 | //add it to the object tree graph |
700 | 697 | $groupObject = array('object'=>$value, 'property' => $property->getProperty()); |
701 | - if(empty($parent)) |
|
698 | + if (empty($parent)) |
|
702 | 699 | $this->_groupBy->add($group, $groupKey, $groupObject); |
703 | 700 | else |
704 | 701 | $this->_groupBy->add($parent, $groupKey, $groupObject); |
@@ -716,10 +713,10 @@ discard block |
||
716 | 713 | protected function getResultMapGroupKey($resultMap, $row) |
717 | 714 | { |
718 | 715 | $groupBy = $resultMap->getGroupBy(); |
719 | - if(isset($row[$groupBy])) |
|
720 | - return $resultMap->getID().$row[$groupBy]; |
|
716 | + if (isset($row[$groupBy])) |
|
717 | + return $resultMap->getID() . $row[$groupBy]; |
|
721 | 718 | else |
722 | - return $resultMap->getID().crc32(serialize($row)); |
|
719 | + return $resultMap->getID() . crc32(serialize($row)); |
|
723 | 720 | } |
724 | 721 | |
725 | 722 | /** |
@@ -732,16 +729,16 @@ discard block |
||
732 | 729 | */ |
733 | 730 | protected function fillDefaultResultMap($resultMap, $row, $resultObject) |
734 | 731 | { |
735 | - if($resultObject===null) |
|
736 | - $resultObject=''; |
|
732 | + if ($resultObject === null) |
|
733 | + $resultObject = ''; |
|
737 | 734 | |
738 | - if($resultMap!==null) |
|
735 | + if ($resultMap !== null) |
|
739 | 736 | $result = $this->fillArrayResultMap($resultMap, $row, $resultObject); |
740 | 737 | else |
741 | 738 | $result = $row; |
742 | 739 | |
743 | 740 | //if scalar result types |
744 | - if(count($result) == 1 && ($type = gettype($resultObject))!= 'array') |
|
741 | + if (count($result) == 1 && ($type = gettype($resultObject)) != 'array') |
|
745 | 742 | return $this->getScalarResult($result, $type); |
746 | 743 | else |
747 | 744 | return $result; |
@@ -757,13 +754,13 @@ discard block |
||
757 | 754 | protected function fillArrayResultMap($resultMap, $row, $resultObject) |
758 | 755 | { |
759 | 756 | $result = array(); |
760 | - $registry=$this->getManager()->getTypeHandlers(); |
|
761 | - foreach($resultMap->getColumns() as $column) |
|
757 | + $registry = $this->getManager()->getTypeHandlers(); |
|
758 | + foreach ($resultMap->getColumns() as $column) |
|
762 | 759 | { |
763 | - if(($column->getType()===null) |
|
764 | - && ($resultObject!==null) && !is_object($resultObject)) |
|
760 | + if (($column->getType() === null) |
|
761 | + && ($resultObject !== null) && !is_object($resultObject)) |
|
765 | 762 | $column->setType(gettype($resultObject)); |
766 | - $result[$column->getProperty()] = $column->getPropertyValue($registry,$row); |
|
763 | + $result[$column->getProperty()] = $column->getPropertyValue($registry, $row); |
|
767 | 764 | } |
768 | 765 | return $result; |
769 | 766 | } |
@@ -793,26 +790,26 @@ discard block |
||
793 | 790 | $select = $property->getSelect(); |
794 | 791 | $key = $property->getProperty(); |
795 | 792 | $nested = $property->getNestedResultMap(); |
796 | - $registry=$this->getManager()->getTypeHandlers(); |
|
797 | - if($key === '') |
|
793 | + $registry = $this->getManager()->getTypeHandlers(); |
|
794 | + if ($key === '') |
|
798 | 795 | { |
799 | - $resultObject = $property->getPropertyValue($registry,$row); |
|
796 | + $resultObject = $property->getPropertyValue($registry, $row); |
|
800 | 797 | } |
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
798 | + else if (strlen($select) == 0 && ($nested === null)) |
|
802 | 799 | { |
803 | - $value = $property->getPropertyValue($registry,$row); |
|
800 | + $value = $property->getPropertyValue($registry, $row); |
|
804 | 801 | |
805 | 802 | $this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null); |
806 | - if(is_array($resultObject) || is_object($resultObject)) |
|
803 | + if (is_array($resultObject) || is_object($resultObject)) |
|
807 | 804 | TPropertyAccess::set($resultObject, $key, $value); |
808 | 805 | else |
809 | 806 | $resultObject = $value; |
810 | 807 | } |
811 | - else if($nested!==null) |
|
808 | + else if ($nested !== null) |
|
812 | 809 | { |
813 | - if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
810 | + if ($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
|
814 | 811 | { |
815 | - if(strlen($resultMap->getGroupBy()) <= 0) |
|
812 | + if (strlen($resultMap->getGroupBy()) <= 0) |
|
816 | 813 | throw new TSqlMapExecutionException( |
817 | 814 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 815 | get_class($resultObject), $key); |
@@ -820,7 +817,7 @@ discard block |
||
820 | 817 | else |
821 | 818 | { |
822 | 819 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | - if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
820 | + if ($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
|
824 | 821 | $obj = null; |
825 | 822 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 823 | } |
@@ -849,10 +846,10 @@ discard block |
||
849 | 846 | $postSelect->setResultProperty($property); |
850 | 847 | $postSelect->setKeys($key); |
851 | 848 | |
852 | - if($property->instanceOfListType($resultObject)) |
|
849 | + if ($property->instanceOfListType($resultObject)) |
|
853 | 850 | { |
854 | 851 | $values = null; |
855 | - if($property->getLazyLoad()) |
|
852 | + if ($property->getLazyLoad()) |
|
856 | 853 | { |
857 | 854 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 855 | $resultObject, $property->getProperty()); |
@@ -861,12 +858,12 @@ discard block |
||
861 | 858 | else |
862 | 859 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
863 | 860 | } |
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
861 | + else if ($property->instanceOfArrayType($resultObject)) |
|
865 | 862 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
866 | 863 | else |
867 | 864 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
868 | 865 | |
869 | - if(!$property->getLazyLoad()) |
|
866 | + if (!$property->getLazyLoad()) |
|
870 | 867 | $this->_selectQueue[] = $postSelect; |
871 | 868 | } |
872 | 869 | |
@@ -877,23 +874,23 @@ discard block |
||
877 | 874 | * @param array current row data. |
878 | 875 | * @return array list of primary key values. |
879 | 876 | */ |
880 | - protected function getPostSelectKeys($resultMap, $property,$row) |
|
877 | + protected function getPostSelectKeys($resultMap, $property, $row) |
|
881 | 878 | { |
882 | 879 | $value = $property->getColumn(); |
883 | - if(is_int(strpos($value.',',0)) || is_int(strpos($value, '=',0))) |
|
880 | + if (is_int(strpos($value . ',', 0)) || is_int(strpos($value, '=', 0))) |
|
884 | 881 | { |
885 | 882 | $keys = array(); |
886 | - foreach(explode(',', $value) as $entry) |
|
883 | + foreach (explode(',', $value) as $entry) |
|
887 | 884 | { |
888 | - $pair =explode('=',$entry); |
|
885 | + $pair = explode('=', $entry); |
|
889 | 886 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 887 | } |
891 | 888 | return $keys; |
892 | 889 | } |
893 | 890 | else |
894 | 891 | { |
895 | - $registry=$this->getManager()->getTypeHandlers(); |
|
896 | - return $property->getPropertyValue($registry,$row); |
|
892 | + $registry = $this->getManager()->getTypeHandlers(); |
|
893 | + return $property->getPropertyValue($registry, $row); |
|
897 | 894 | } |
898 | 895 | } |
899 | 896 | |
@@ -907,7 +904,7 @@ discard block |
||
907 | 904 | protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject) |
908 | 905 | { |
909 | 906 | $dataFound = false; |
910 | - foreach($resultMap->getColumns() as $property) |
|
907 | + foreach ($resultMap->getColumns() as $property) |
|
911 | 908 | { |
912 | 909 | $this->_IsRowDataFound = false; |
913 | 910 | $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
@@ -929,7 +926,7 @@ discard block |
||
929 | 926 | if (!count($this->_selectQueue)) $exprops[] = "\0$cn\0_selectQueue"; |
930 | 927 | if (is_null($this->_groupBy)) $exprops[] = "\0$cn\0_groupBy"; |
931 | 928 | if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; |
932 | - return array_diff(parent::__sleep(),$exprops); |
|
929 | + return array_diff(parent::__sleep(), $exprops); |
|
933 | 930 | } |
934 | 931 | } |
935 | 932 | |
@@ -942,26 +939,26 @@ discard block |
||
942 | 939 | */ |
943 | 940 | class TPostSelectBinding |
944 | 941 | { |
945 | - private $_statement=null; |
|
946 | - private $_property=null; |
|
947 | - private $_resultObject=null; |
|
948 | - private $_keys=null; |
|
949 | - private $_method=TMappedStatement::QUERY_FOR_LIST; |
|
942 | + private $_statement = null; |
|
943 | + private $_property = null; |
|
944 | + private $_resultObject = null; |
|
945 | + private $_keys = null; |
|
946 | + private $_method = TMappedStatement::QUERY_FOR_LIST; |
|
950 | 947 | |
951 | - public function getStatement(){ return $this->_statement; } |
|
952 | - public function setStatement($value){ $this->_statement = $value; } |
|
948 | + public function getStatement() { return $this->_statement; } |
|
949 | + public function setStatement($value) { $this->_statement = $value; } |
|
953 | 950 | |
954 | - public function getResultProperty(){ return $this->_property; } |
|
955 | - public function setResultProperty($value){ $this->_property = $value; } |
|
951 | + public function getResultProperty() { return $this->_property; } |
|
952 | + public function setResultProperty($value) { $this->_property = $value; } |
|
956 | 953 | |
957 | - public function getResultObject(){ return $this->_resultObject; } |
|
958 | - public function setResultObject($value){ $this->_resultObject = $value; } |
|
954 | + public function getResultObject() { return $this->_resultObject; } |
|
955 | + public function setResultObject($value) { $this->_resultObject = $value; } |
|
959 | 956 | |
960 | - public function getKeys(){ return $this->_keys; } |
|
961 | - public function setKeys($value){ $this->_keys = $value; } |
|
957 | + public function getKeys() { return $this->_keys; } |
|
958 | + public function setKeys($value) { $this->_keys = $value; } |
|
962 | 959 | |
963 | - public function getMethod(){ return $this->_method; } |
|
964 | - public function setMethod($value){ $this->_method = $value; } |
|
960 | + public function getMethod() { return $this->_method; } |
|
961 | + public function setMethod($value) { $this->_method = $value; } |
|
965 | 962 | } |
966 | 963 | |
967 | 964 | /** |
@@ -1004,26 +1001,26 @@ discard block |
||
1004 | 1001 | * @param string new node id |
1005 | 1002 | * @param mixed node value |
1006 | 1003 | */ |
1007 | - public function add($parent, $node, $object='') |
|
1004 | + public function add($parent, $node, $object = '') |
|
1008 | 1005 | { |
1009 | - if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) |
|
1010 | - && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) |
|
1006 | + if (isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
1007 | + && isset($this->_entries[$node]) && ($this->_entries[$node] !== null)) |
|
1011 | 1008 | { |
1012 | 1009 | $this->_entries[$node] = $object; |
1013 | 1010 | return; |
1014 | 1011 | } |
1015 | 1012 | $this->_entries[$node] = $object; |
1016 | - if(empty($parent)) |
|
1013 | + if (empty($parent)) |
|
1017 | 1014 | { |
1018 | - if(isset($this->_entries[$node])) |
|
1015 | + if (isset($this->_entries[$node])) |
|
1019 | 1016 | return; |
1020 | 1017 | $this->_tree[$node] = array(); |
1021 | 1018 | } |
1022 | 1019 | $found = $this->addNode($this->_tree, $parent, $node); |
1023 | - if(!$found && !empty($parent)) |
|
1020 | + if (!$found && !empty($parent)) |
|
1024 | 1021 | { |
1025 | 1022 | $this->_tree[$parent] = array(); |
1026 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
1023 | + if (!isset($this->_entries[$parent]) || $object !== '') |
|
1027 | 1024 | $this->_entries[$parent] = $object; |
1028 | 1025 | $this->addNode($this->_tree, $parent, $node); |
1029 | 1026 | } |
@@ -1040,11 +1037,11 @@ discard block |
||
1040 | 1037 | { |
1041 | 1038 | $found = false; |
1042 | 1039 | reset($childs); |
1043 | - for($i = 0, $k = count($childs); $i < $k; $i++) |
|
1040 | + for ($i = 0, $k = count($childs); $i < $k; $i++) |
|
1044 | 1041 | { |
1045 | 1042 | $key = key($childs); |
1046 | 1043 | next($childs); |
1047 | - if($key == $parent) |
|
1044 | + if ($key == $parent) |
|
1048 | 1045 | { |
1049 | 1046 | $found = true; |
1050 | 1047 | $childs[$key][$node] = array(); |
@@ -1062,7 +1059,7 @@ discard block |
||
1062 | 1059 | */ |
1063 | 1060 | public function collect() |
1064 | 1061 | { |
1065 | - while(count($this->_tree) > 0) |
|
1062 | + while (count($this->_tree) > 0) |
|
1066 | 1063 | $this->collectChildren(null, $this->_tree); |
1067 | 1064 | return $this->getCollection(); |
1068 | 1065 | } |
@@ -1074,8 +1071,8 @@ discard block |
||
1074 | 1071 | protected function hasChildren(&$nodes) |
1075 | 1072 | { |
1076 | 1073 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1074 | + foreach ($nodes as $node) |
|
1075 | + if (count($node) != 0) |
|
1079 | 1076 | return true; |
1080 | 1077 | return $hasChildren; |
1081 | 1078 | } |
@@ -1089,10 +1086,10 @@ discard block |
||
1089 | 1086 | { |
1090 | 1087 | $noChildren = !$this->hasChildren($nodes); |
1091 | 1088 | $childs = array(); |
1092 | - for(reset($nodes); $key = key($nodes);) |
|
1089 | + for (reset($nodes); $key = key($nodes);) |
|
1093 | 1090 | { |
1094 | 1091 | next($nodes); |
1095 | - if($noChildren) |
|
1092 | + if ($noChildren) |
|
1096 | 1093 | { |
1097 | 1094 | $childs[] = $key; |
1098 | 1095 | unset($nodes[$key]); |
@@ -1100,7 +1097,7 @@ discard block |
||
1100 | 1097 | else |
1101 | 1098 | $this->collectChildren($key, $nodes[$key]); |
1102 | 1099 | } |
1103 | - if(count($childs) > 0) |
|
1100 | + if (count($childs) > 0) |
|
1104 | 1101 | $this->onChildNodesVisited($parent, $childs); |
1105 | 1102 | } |
1106 | 1103 | |
@@ -1111,7 +1108,7 @@ discard block |
||
1111 | 1108 | */ |
1112 | 1109 | protected function onChildNodesVisited($parent, $nodes) |
1113 | 1110 | { |
1114 | - if(empty($parent) || empty($this->_entries[$parent])) |
|
1111 | + if (empty($parent) || empty($this->_entries[$parent])) |
|
1115 | 1112 | return; |
1116 | 1113 | |
1117 | 1114 | $parentObject = $this->_entries[$parent]['object']; |
@@ -1119,21 +1116,21 @@ discard block |
||
1119 | 1116 | |
1120 | 1117 | $list = TPropertyAccess::get($parentObject, $property); |
1121 | 1118 | |
1122 | - foreach($nodes as $node) |
|
1119 | + foreach ($nodes as $node) |
|
1123 | 1120 | { |
1124 | - if($list instanceof TList) |
|
1121 | + if ($list instanceof TList) |
|
1125 | 1122 | $parentObject->{$property}[] = $this->_entries[$node]['object']; |
1126 | - else if(is_array($list)) |
|
1123 | + else if (is_array($list)) |
|
1127 | 1124 | $list[] = $this->_entries[$node]['object']; |
1128 | 1125 | else |
1129 | 1126 | throw new TSqlMapExecutionException( |
1130 | 1127 | 'sqlmap_property_must_be_list'); |
1131 | 1128 | } |
1132 | 1129 | |
1133 | - if(is_array($list)) |
|
1130 | + if (is_array($list)) |
|
1134 | 1131 | TPropertyAccess::set($parentObject, $property, $list); |
1135 | 1132 | |
1136 | - if($this->_entries[$parent]['property'] === null) |
|
1133 | + if ($this->_entries[$parent]['property'] === null) |
|
1137 | 1134 | $this->_list[] = $parentObject; |
1138 | 1135 | } |
1139 | 1136 | |
@@ -1151,7 +1148,7 @@ discard block |
||
1151 | 1148 | if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
1152 | 1149 | if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
1153 | 1150 | if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
1154 | - return array_diff(parent::__sleep(),$exprops); |
|
1151 | + return array_diff(parent::__sleep(), $exprops); |
|
1155 | 1152 | } |
1156 | 1153 | } |
1157 | 1154 |
@@ -237,8 +237,7 @@ discard block |
||
237 | 237 | $param = new TResultSetListItemParameter($obj, $parameter, $list); |
238 | 238 | $this->raiseRowDelegate($delegate, $param); |
239 | 239 | } |
240 | - } |
|
241 | - else |
|
240 | + } else |
|
242 | 241 | { |
243 | 242 | //var_dump($sql,$parameter); |
244 | 243 | foreach($reader as $row) |
@@ -314,8 +313,7 @@ discard block |
||
314 | 313 | $param = new TResultSetMapItemParameter($key, $value, $parameter, $map); |
315 | 314 | $this->raiseRowDelegate($delegate, $param); |
316 | 315 | } |
317 | - } |
|
318 | - else |
|
316 | + } else |
|
319 | 317 | { |
320 | 318 | //while($row = $recordSet->fetchRow()) |
321 | 319 | foreach($reader as $row) |
@@ -341,8 +339,7 @@ discard block |
||
341 | 339 | if(is_string($handler)) |
342 | 340 | { |
343 | 341 | call_user_func($handler,$this,$param); |
344 | - } |
|
345 | - else if(is_callable($handler,true)) |
|
342 | + } else if(is_callable($handler,true)) |
|
346 | 343 | { |
347 | 344 | // an array: 0 - object, 1 - method name/path |
348 | 345 | list($object,$method)=$handler; |
@@ -357,8 +354,7 @@ discard block |
||
357 | 354 | } |
358 | 355 | $object->$method($this,$param); |
359 | 356 | } |
360 | - } |
|
361 | - else |
|
357 | + } else |
|
362 | 358 | throw new TInvalidDataValueException('sqlmap_invalid_delegate', $this->getID(), $handler); |
363 | 359 | } |
364 | 360 | |
@@ -393,8 +389,9 @@ discard block |
||
393 | 389 | { |
394 | 390 | $object = null; |
395 | 391 | $connection->setActive(true); |
396 | - foreach($command->query() as $row) |
|
397 | - $object = $this->applyResultMap($row, $result); |
|
392 | + foreach($command->query() as $row) { |
|
393 | + $object = $this->applyResultMap($row, $result); |
|
394 | + } |
|
398 | 395 | |
399 | 396 | if(!$this->_groupBy->isEmpty()) |
400 | 397 | { |
@@ -520,8 +517,7 @@ discard block |
||
520 | 517 | if($method == self::QUERY_FOR_ARRAY) |
521 | 518 | $values = $values->toArray(); |
522 | 519 | TPropertyAccess::set($resultObject, $property, $values); |
523 | - } |
|
524 | - else if($method == self::QUERY_FOR_OBJECT) |
|
520 | + } else if($method == self::QUERY_FOR_OBJECT) |
|
525 | 521 | { |
526 | 522 | $value = $statement->executeQueryForObject($connection, $keys, null); |
527 | 523 | TPropertyAccess::set($resultObject, $property, $value); |
@@ -596,11 +592,13 @@ discard block |
||
596 | 592 | protected function fillResultArrayList($row, $resultObject) |
597 | 593 | { |
598 | 594 | if($resultObject instanceof TList) |
599 | - foreach($row as $v) |
|
600 | - $resultObject[] = $v; |
|
595 | + foreach($row as $v) { |
|
596 | + $resultObject[] = $v; |
|
597 | + } |
|
601 | 598 | else |
602 | - foreach($row as $k => $v) |
|
603 | - $resultObject[$k] = $v; |
|
599 | + foreach($row as $k => $v) { |
|
600 | + $resultObject[$k] = $v; |
|
601 | + } |
|
604 | 602 | return $resultObject; |
605 | 603 | } |
606 | 604 | |
@@ -649,10 +647,10 @@ discard block |
||
649 | 647 | if(strlen($resultMap->getGroupBy()) > 0) |
650 | 648 | return $this->addResultMapGroupBy($resultMap, $row, $parentGroup, $resultObject); |
651 | 649 | else |
652 | - foreach($resultMap->getColumns() as $property) |
|
653 | - $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
|
654 | - } |
|
655 | - else |
|
650 | + foreach($resultMap->getColumns() as $property) { |
|
651 | + $this->setObjectProperty($resultMap, $property, $row, $resultObject); |
|
652 | + } |
|
653 | + } else |
|
656 | 654 | { |
657 | 655 | $resultObject = $this->fillDefaultResultMap($resultMap, $row, $resultObject); |
658 | 656 | } |
@@ -797,8 +795,7 @@ discard block |
||
797 | 795 | if($key === '') |
798 | 796 | { |
799 | 797 | $resultObject = $property->getPropertyValue($registry,$row); |
800 | - } |
|
801 | - else if(strlen($select) == 0 && ($nested===null)) |
|
798 | + } else if(strlen($select) == 0 && ($nested===null)) |
|
802 | 799 | { |
803 | 800 | $value = $property->getPropertyValue($registry,$row); |
804 | 801 | |
@@ -807,8 +804,7 @@ discard block |
||
807 | 804 | TPropertyAccess::set($resultObject, $key, $value); |
808 | 805 | else |
809 | 806 | $resultObject = $value; |
810 | - } |
|
811 | - else if($nested!==null) |
|
807 | + } else if($nested!==null) |
|
812 | 808 | { |
813 | 809 | if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject)) |
814 | 810 | { |
@@ -816,16 +812,14 @@ discard block |
||
816 | 812 | throw new TSqlMapExecutionException( |
817 | 813 | 'sqlmap_non_groupby_array_list_type', $resultMap->getID(), |
818 | 814 | get_class($resultObject), $key); |
819 | - } |
|
820 | - else |
|
815 | + } else |
|
821 | 816 | { |
822 | 817 | $obj = $nested->createInstanceOfResult($this->getManager()->getTypeHandlers()); |
823 | 818 | if($this->fillPropertyWithResultMap($nested, $row, $obj) == false) |
824 | 819 | $obj = null; |
825 | 820 | TPropertyAccess::set($resultObject, $key, $obj); |
826 | 821 | } |
827 | - } |
|
828 | - else //'select' ResultProperty |
|
822 | + } else //'select' ResultProperty |
|
829 | 823 | { |
830 | 824 | $this->enquequePostSelect($select, $resultMap, $property, $row, $resultObject); |
831 | 825 | } |
@@ -857,11 +851,9 @@ discard block |
||
857 | 851 | $values = TLazyLoadList::newInstance($statement, $key, |
858 | 852 | $resultObject, $property->getProperty()); |
859 | 853 | TPropertyAccess::set($resultObject, $property->getProperty(), $values); |
860 | - } |
|
861 | - else |
|
854 | + } else |
|
862 | 855 | $postSelect->setMethod(self::QUERY_FOR_LIST); |
863 | - } |
|
864 | - else if($property->instanceOfArrayType($resultObject)) |
|
856 | + } else if($property->instanceOfArrayType($resultObject)) |
|
865 | 857 | $postSelect->setMethod(self::QUERY_FOR_ARRAY); |
866 | 858 | else |
867 | 859 | $postSelect->setMethod(self::QUERY_FOR_OBJECT); |
@@ -889,8 +881,7 @@ discard block |
||
889 | 881 | $keys[trim($pair[0])] = $row[trim($pair[1])]; |
890 | 882 | } |
891 | 883 | return $keys; |
892 | - } |
|
893 | - else |
|
884 | + } else |
|
894 | 885 | { |
895 | 886 | $registry=$this->getManager()->getTypeHandlers(); |
896 | 887 | return $property->getPropertyValue($registry,$row); |
@@ -1048,8 +1039,7 @@ discard block |
||
1048 | 1039 | { |
1049 | 1040 | $found = true; |
1050 | 1041 | $childs[$key][$node] = array(); |
1051 | - } |
|
1052 | - else |
|
1042 | + } else |
|
1053 | 1043 | { |
1054 | 1044 | $found = $found || $this->addNode($childs[$key], $parent, $node); |
1055 | 1045 | } |
@@ -1062,8 +1052,9 @@ discard block |
||
1062 | 1052 | */ |
1063 | 1053 | public function collect() |
1064 | 1054 | { |
1065 | - while(count($this->_tree) > 0) |
|
1066 | - $this->collectChildren(null, $this->_tree); |
|
1055 | + while(count($this->_tree) > 0) { |
|
1056 | + $this->collectChildren(null, $this->_tree); |
|
1057 | + } |
|
1067 | 1058 | return $this->getCollection(); |
1068 | 1059 | } |
1069 | 1060 | |
@@ -1074,9 +1065,10 @@ discard block |
||
1074 | 1065 | protected function hasChildren(&$nodes) |
1075 | 1066 | { |
1076 | 1067 | $hasChildren = false; |
1077 | - foreach($nodes as $node) |
|
1078 | - if(count($node) != 0) |
|
1068 | + foreach($nodes as $node) { |
|
1069 | + if(count($node) != 0) |
|
1079 | 1070 | return true; |
1071 | + } |
|
1080 | 1072 | return $hasChildren; |
1081 | 1073 | } |
1082 | 1074 | |
@@ -1096,8 +1088,7 @@ discard block |
||
1096 | 1088 | { |
1097 | 1089 | $childs[] = $key; |
1098 | 1090 | unset($nodes[$key]); |
1099 | - } |
|
1100 | - else |
|
1091 | + } else |
|
1101 | 1092 | $this->collectChildren($key, $nodes[$key]); |
1102 | 1093 | } |
1103 | 1094 | if(count($childs) > 0) |
@@ -21,6 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class TPreparedCommand |
23 | 23 | { |
24 | + /** |
|
25 | + * @param TSqlMapStatement $statement |
|
26 | + */ |
|
24 | 27 | public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null) |
25 | 28 | { |
26 | 29 | $sqlText = $statement->getSQLText(); |
@@ -43,6 +46,9 @@ discard block |
||
43 | 46 | return $command; |
44 | 47 | } |
45 | 48 | |
49 | + /** |
|
50 | + * @param TSqlMapManager $manager |
|
51 | + */ |
|
46 | 52 | protected function applyParameterMap($manager,$command,$prepared, $statement, $parameterObject) |
47 | 53 | { |
48 | 54 | $properties = $prepared->getParameterNames(false); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class TPreparedCommand |
23 | 23 | { |
24 | - public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null) |
|
24 | + public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject, $skip = null, $max = null) |
|
25 | 25 | { |
26 | 26 | $sqlText = $statement->getSQLText(); |
27 | 27 | |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | $connection->setActive(true); |
30 | 30 | $sql = $prepared->getPreparedSql(); |
31 | 31 | |
32 | - if($sqlText instanceof TSimpleDynamicSql) |
|
32 | + if ($sqlText instanceof TSimpleDynamicSql) |
|
33 | 33 | $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject); |
34 | 34 | |
35 | - if($max!==null || $skip!==null) |
|
35 | + if ($max !== null || $skip !== null) |
|
36 | 36 | { |
37 | 37 | $builder = TDbMetaData::getInstance($connection)->createCommandBuilder(); |
38 | - $sql = $builder->applyLimitOffset($sql,$max,$skip); |
|
38 | + $sql = $builder->applyLimitOffset($sql, $max, $skip); |
|
39 | 39 | } |
40 | 40 | $command = $connection->createCommand($sql); |
41 | 41 | $this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject); |
@@ -43,23 +43,23 @@ discard block |
||
43 | 43 | return $command; |
44 | 44 | } |
45 | 45 | |
46 | - protected function applyParameterMap($manager,$command,$prepared, $statement, $parameterObject) |
|
46 | + protected function applyParameterMap($manager, $command, $prepared, $statement, $parameterObject) |
|
47 | 47 | { |
48 | 48 | $properties = $prepared->getParameterNames(false); |
49 | 49 | //$parameters = $prepared->getParameterValues(); |
50 | - $registry=$manager->getTypeHandlers(); |
|
50 | + $registry = $manager->getTypeHandlers(); |
|
51 | 51 | if ($properties) |
52 | - for($i = 0, $k=$properties->getCount(); $i<$k; $i++) |
|
52 | + for ($i = 0, $k = $properties->getCount(); $i < $k; $i++) |
|
53 | 53 | { |
54 | 54 | $property = $statement->parameterMap()->getProperty($i); |
55 | - $value = $statement->parameterMap()->getPropertyValue($registry,$property, $parameterObject); |
|
55 | + $value = $statement->parameterMap()->getPropertyValue($registry, $property, $parameterObject); |
|
56 | 56 | $dbType = $property->getDbType(); |
57 | - if($dbType=='') //relies on PHP lax comparison |
|
58 | - $command->bindValue($i+1,$value, TDbCommandBuilder::getPdoType($value)); |
|
59 | - else if(strpos($dbType, 'PDO::')===0) |
|
60 | - $command->bindValue($i+1,$value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT |
|
57 | + if ($dbType == '') //relies on PHP lax comparison |
|
58 | + $command->bindValue($i + 1, $value, TDbCommandBuilder::getPdoType($value)); |
|
59 | + else if (strpos($dbType, 'PDO::') === 0) |
|
60 | + $command->bindValue($i + 1, $value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT |
|
61 | 61 | else |
62 | - $command->bindValue($i+1,$value); |
|
62 | + $command->bindValue($i + 1, $value); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -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 | } |
@@ -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 |
@@ -68,8 +68,7 @@ |
||
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; |
@@ -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 | } |
@@ -265,8 +265,9 @@ |
||
265 | 265 | */ |
266 | 266 | public function flushCacheModels() |
267 | 267 | { |
268 | - foreach($this->_cacheModels as $cache) |
|
269 | - $cache->flush(); |
|
268 | + foreach($this->_cacheModels as $cache) { |
|
269 | + $cache->flush(); |
|
270 | + } |
|
270 | 271 | } |
271 | 272 | } |
272 | 273 |
@@ -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 @@ |
||
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 | } |
@@ -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 |
@@ -189,8 +189,7 @@ discard block |
||
189 | 189 | $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
190 | 190 | $this->_active=true; |
191 | 191 | $this->setConnectionCharset(); |
192 | - } |
|
193 | - catch(PDOException $e) |
|
192 | + } catch(PDOException $e) |
|
194 | 193 | { |
195 | 194 | throw new TDbException('dbconnection_open_failed',$e->getMessage()); |
196 | 195 | } |
@@ -343,8 +342,7 @@ discard block |
||
343 | 342 | { |
344 | 343 | $this->_pdo->beginTransaction(); |
345 | 344 | return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); |
346 | - } |
|
347 | - else |
|
345 | + } else |
|
348 | 346 | throw new TDbException('dbconnection_connection_inactive'); |
349 | 347 | } |
350 | 348 |