Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
53.57% |
15 / 28 |
CRAP | |
63.06% |
70 / 111 |
| TPDOConnectionObj | |
0.00% |
0 / 1 |
|
53.57% |
15 / 28 |
92.26 | |
63.06% |
70 / 111 |
| __construct | |
0.00% |
0 / 1 |
2.03 | |
80.00% |
4 / 5 |
|||
| getFakeConnectionArray | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getTPDOConnection | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| setTPDOConnection | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| makeConfigArray | |
100.00% |
1 / 1 |
3 | |
100.00% |
12 / 12 |
|||
| connect | |
0.00% |
0 / 1 |
4.01 | |
90.91% |
10 / 11 |
|||
| getDBMS | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setDBMS | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getPort | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setPort | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| getHost | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setHost | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getDataBaseName | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setDataBaseName | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getUsername | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setUsername | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getPassword | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setPassword | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getUtfDecode | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setUtfDecode | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| executeSql | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getError | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getInstance | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| beginTransaction | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| inTransaction | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| commit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| rollBack | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getLastInsertId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| 1 | <?php |
| 2 | /* |
| 3 | * Formdin Framework |
| 4 | * Copyright (C) 2012 Ministério do Planejamento |
| 5 | * Criado por Luís Eugênio Barbosa |
| 6 | * Essa versão é um Fork https://github.com/bjverde/formDin |
| 7 | * |
| 8 | * ---------------------------------------------------------------------------- |
| 9 | * This file is part of Formdin Framework. |
| 10 | * |
| 11 | * Formdin Framework is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public License version 3 |
| 13 | * as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License version 3 |
| 21 | * along with this program; if not, see <http://www.gnu.org/licenses/> |
| 22 | * or write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 23 | * Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | * ---------------------------------------------------------------------------- |
| 25 | * Este arquivo é parte do Framework Formdin. |
| 26 | * |
| 27 | * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou |
| 28 | * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação |
| 29 | * do Software Livre (FSF). |
| 30 | * |
| 31 | * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA |
| 32 | * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou |
| 33 | * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português |
| 34 | * para maiores detalhes. |
| 35 | * |
| 36 | * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título |
| 37 | * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 38 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 39 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 40 | */ |
| 41 | |
| 42 | |
| 43 | |
| 44 | /*** |
| 45 | * This TPDOConnectionObj class is just a possible improvement of the TPDOConnection class. |
| 46 | * The TPDOConnection class makes use of many static methods which |
| 47 | * Do unit tests. Moreover, this change does not cause backwards compatibility problem. |
| 48 | * |
| 49 | * |
| 50 | * Essa classe TPDOConnectionObj é apenas uma possível melhoria da classe TPDOConnection. |
| 51 | * A classe TPDOConnection faz uso de muitos metodos estaticos o que ficulta na hora de |
| 52 | * fazer testes unitarios. Alem disso esse mudança não gera problema de retro compatibilidade. |
| 53 | */ |
| 54 | class TPDOConnectionObj |
| 55 | { |
| 56 | |
| 57 | private $tpdo = null; |
| 58 | |
| 59 | /** |
| 60 | * @param boolean $connect : use MAIN connect |
| 61 | */ |
| 62 | public function __construct($connect = true) |
| 63 | { |
| 64 | $tpdo = New TPDOConnection(); |
| 65 | //$configArray = $this->getFakeConnectionArray(); |
| 66 | if( $connect ){ |
| 67 | $tpdo::connect(null,true,null,null); |
| 68 | } |
| 69 | $this->setTPDOConnection($tpdo); |
| 70 | } |
| 71 | private function getFakeConnectionArray(){ |
| 72 | $configArray= array( |
| 73 | 'DBMS' => DBMS_MYSQL |
| 74 | ,'PORT' => null |
| 75 | ,'HOST' => 'locahost' |
| 76 | ,'DATABASE' => 'fake' |
| 77 | ,'USERNAME' => 'fake' |
| 78 | ,'PASSWORD' => 'fake' |
| 79 | ); |
| 80 | return $configArray; |
| 81 | } |
| 82 | //-------------------------------------------------------------------------------------- |
| 83 | public function getTPDOConnection() |
| 84 | { |
| 85 | return $this->tpdo; |
| 86 | } |
| 87 | public function setTPDOConnection($TPDOConnection) |
| 88 | { |
| 89 | $this->tpdo = $TPDOConnection; |
| 90 | } |
| 91 | //-------------------------------------------------------------------------------------- |
| 92 | /** |
| 93 | * Gera o Array de configuração com base nos atributos dos metodos |
| 94 | * @return array |
| 95 | */ |
| 96 | public function makeConfigArray(){ |
| 97 | $configArray = null; |
| 98 | $hasDBMS = FormDinHelper::issetOrNotZero($this->getDBMS()); |
| 99 | $hasDBas = FormDinHelper::issetOrNotZero($this->getDataBaseName()); |
| 100 | if($hasDBMS && $hasDBas){ |
| 101 | $configArray= array( |
| 102 | 'DBMS' => $this->getDBMS() |
| 103 | ,'PORT' => $this->getPort() |
| 104 | ,'HOST' => $this->getHost() |
| 105 | ,'DATABASE' => $this->getDataBaseName() |
| 106 | ,'USERNAME' => $this->getUsername() |
| 107 | ,'PASSWORD' => $this->getPassword() |
| 108 | ); |
| 109 | } |
| 110 | return $configArray; |
| 111 | } |
| 112 | //-------------------------------------------------------------------------------------- |
| 113 | /** |
| 114 | * Establishes the connection to the database. the main connection is informed in $configfile |
| 115 | * the secondary connections are informed in $configArray. The $configArray prevails over $configfile. |
| 116 | * In this case $configfile will be ignored. |
| 117 | * |
| 118 | * @param string $configFile - 1: nome do arquivo na pasta <APP>/includes/<nome_arquivo>.php |
| 119 | * @param boolean $boolRequired - 2: Default TRUE = connection is mandatory |
| 120 | * @param boolean $boolUtfDecode - 3: Default TRUE = faz o Decode / Encode UTF8 |
| 121 | * @param array $configArray - 4: Usa array de configuração, prevalecendo sobre o $configFile |
| 122 | * @return void |
| 123 | */ |
| 124 | public function connect( $configFile = null, $boolRequired = true, $boolUtfDecode = null, $configArray = null ) |
| 125 | { |
| 126 | $hasConfigArray = FormDinHelper::issetOrNotZero($configArray); |
| 127 | if(!$hasConfigArray){ |
| 128 | $configArray = $this->makeConfigArray(); |
| 129 | } |
| 130 | if( empty($configFile) ){ |
| 131 | $hasConfigArray = FormDinHelper::issetOrNotZero($configArray); |
| 132 | } |
| 133 | $tpdo = $this->getTPDOConnection(); |
| 134 | if($hasConfigArray){ |
| 135 | $tpdo::connect(null,$boolRequired,$boolUtfDecode,$configArray); |
| 136 | }else{ |
| 137 | $tpdo::connect($configFile,$boolRequired,$boolUtfDecode,null); |
| 138 | } |
| 139 | $this->setTPDOConnection($tpdo); |
| 140 | } |
| 141 | //-------------------------------------------------------------------------------------- |
| 142 | public function getDBMS() |
| 143 | { |
| 144 | //return $this->tpdo::getDBMS(); |
| 145 | $tpdo = $this->getTPDOConnection(); |
| 146 | $attribute = $tpdo::getDBMS(); |
| 147 | return $attribute; |
| 148 | } |
| 149 | public function setDBMS( $banco = null ) |
| 150 | { |
| 151 | //$this->tpdo::setBanco($banco); |
| 152 | $tpdo = $this->getTPDOConnection(); |
| 153 | $tpdo::setBanco($banco); |
| 154 | $this->setTPDOConnection($tpdo); |
| 155 | } |
| 156 | //-------------------------------------------------------------------------------------- |
| 157 | public function getPort() |
| 158 | { |
| 159 | //return $this->tpdo::getPort(); |
| 160 | $tpdo = $this->getTPDOConnection(); |
| 161 | $attribute = $tpdo::getPort(); |
| 162 | return $attribute; |
| 163 | } |
| 164 | public function setPort($port = null ) |
| 165 | { |
| 166 | //$this->tpdo::setPort($port); |
| 167 | $tpdo = $this->getTPDOConnection(); |
| 168 | $tpdo::setPort($port); |
| 169 | $this->setTPDOConnection($tpdo); |
| 170 | } |
| 171 | //-------------------------------------------------------------------------------------- |
| 172 | public function getHost() |
| 173 | { |
| 174 | //return $this->tpdo::getHost(); |
| 175 | $tpdo = $this->getTPDOConnection(); |
| 176 | $attribute = $tpdo::getHost(); |
| 177 | return $attribute; |
| 178 | } |
| 179 | public function setHost($host) |
| 180 | { |
| 181 | //$this->tpdo::setHost($host); |
| 182 | $tpdo = $this->getTPDOConnection(); |
| 183 | $tpdo::setHost($host); |
| 184 | $this->setTPDOConnection($tpdo); |
| 185 | } |
| 186 | //-------------------------------------------------------------------------------------- |
| 187 | public function getDataBaseName() |
| 188 | { |
| 189 | //return $this->tpdo::getDataBaseName(); |
| 190 | $tpdo = $this->getTPDOConnection(); |
| 191 | $attribute = $tpdo::getDataBaseName(); |
| 192 | return $attribute; |
| 193 | } |
| 194 | public function setDataBaseName($host) |
| 195 | { |
| 196 | //$this->tpdo::setDataBaseName($host); |
| 197 | $tpdo = $this->getTPDOConnection(); |
| 198 | $tpdo::setDataBaseName($host); |
| 199 | $this->setTPDOConnection($tpdo); |
| 200 | } |
| 201 | //-------------------------------------------------------------------------------------- |
| 202 | public function getUsername() |
| 203 | { |
| 204 | //return $this->tpdo::getUsername(); |
| 205 | $tpdo = $this->getTPDOConnection(); |
| 206 | $attribute = $tpdo::getUsername(); |
| 207 | return $attribute; |
| 208 | } |
| 209 | public function setUsername($username) |
| 210 | { |
| 211 | //$this->tpdo::setUsername($username); |
| 212 | $tpdo = $this->getTPDOConnection(); |
| 213 | $tpdo::setUsername($username); |
| 214 | $this->setTPDOConnection($tpdo); |
| 215 | } |
| 216 | //-------------------------------------------------------------------------------------- |
| 217 | public function getPassword() |
| 218 | { |
| 219 | //return $this->tpdo::getPassword(); |
| 220 | $tpdo = $this->getTPDOConnection(); |
| 221 | $attribute = $tpdo::getPassword(); |
| 222 | return $attribute; |
| 223 | } |
| 224 | public function setPassword($password) |
| 225 | { |
| 226 | //$this->tpdo::setPassword($password); |
| 227 | $tpdo = $this->getTPDOConnection(); |
| 228 | $tpdo::setPassword($password); |
| 229 | $this->setTPDOConnection($tpdo); |
| 230 | } |
| 231 | //-------------------------------------------------------------------------------------- |
| 232 | public function getUtfDecode() |
| 233 | { |
| 234 | //return $this->tpdo::getUtfDecode(); |
| 235 | $tpdo = $this->getTPDOConnection(); |
| 236 | $attribute = $tpdo::getUtfDecode(); |
| 237 | return $attribute; |
| 238 | } |
| 239 | public function setUtfDecode( $boolNewValue = null ) |
| 240 | { |
| 241 | //$this->tpdo::setUtfDecode($boolNewValue); |
| 242 | $tpdo = $this->getTPDOConnection(); |
| 243 | $tpdo::setUtfDecode($boolNewValue); |
| 244 | $this->setTPDOConnection($tpdo); |
| 245 | } |
| 246 | //-------------------------------------------------------------------------------------- |
| 247 | public function executeSql($sql, $arrParams = null) |
| 248 | { |
| 249 | $tpdo = $this->getTPDOConnection(); |
| 250 | $result = $tpdo::executeSql($sql,$arrParams); |
| 251 | return $result; |
| 252 | } |
| 253 | //-------------------------------------------------------------------------------------- |
| 254 | public function getError() |
| 255 | { |
| 256 | $tpdo = $this->getTPDOConnection(); |
| 257 | $result = $tpdo::getError(); |
| 258 | return $result; |
| 259 | } |
| 260 | //-------------------------------------------------------------------------------------- |
| 261 | public function getInstance() |
| 262 | { |
| 263 | $tpdo = $this->getTPDOConnection(); |
| 264 | $instance = $tpdo::getInstance(); |
| 265 | return $instance; |
| 266 | } |
| 267 | //-------------------------------------------------------------------------------------- |
| 268 | public function beginTransaction() |
| 269 | { |
| 270 | //$this->tpdo::rollBack(); |
| 271 | $tpdo = $this->getTPDOConnection(); |
| 272 | //$tpdo::rollBack(); |
| 273 | $instance = $tpdo::getInstance(); |
| 274 | $instance->beginTransaction(); |
| 275 | $this->setTPDOConnection($tpdo); |
| 276 | } |
| 277 | //-------------------------------------------------------------------------------------- |
| 278 | public function inTransaction() |
| 279 | { |
| 280 | $instance = $this->getInstance(); |
| 281 | return $instance->inTransaction(); |
| 282 | } |
| 283 | //-------------------------------------------------------------------------------------- |
| 284 | public function commit() |
| 285 | { |
| 286 | //$this->tpdo::commit(); |
| 287 | $tpdo = $this->getTPDOConnection(); |
| 288 | //$tpdo::commit(); |
| 289 | $instance = $tpdo::getInstance(); |
| 290 | $instance->commit(); |
| 291 | $this->setTPDOConnection($tpdo); |
| 292 | } |
| 293 | //-------------------------------------------------------------------------------------- |
| 294 | public function rollBack() |
| 295 | { |
| 296 | //$this->tpdo::rollBack(); |
| 297 | $tpdo = $this->getTPDOConnection(); |
| 298 | //$tpdo::rollBack(); |
| 299 | $instance = $tpdo::getInstance(); |
| 300 | $instance->rollBack(); |
| 301 | $this->setTPDOConnection($tpdo); |
| 302 | } |
| 303 | //-------------------------------------------------------------------------------------- |
| 304 | public function getLastInsertId() |
| 305 | { |
| 306 | $instance = $this->getInstance(); |
| 307 | $id = $instance->lastInsertId(); |
| 308 | return $id; |
| 309 | } |
| 310 | } |
| 311 | ?> |