@@ -34,8 +34,9 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private function getInstance(): ?PDO |
| 36 | 36 | {
|
| 37 | - if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao") ) |
|
| 38 | - $this->database .= "Homologacao"; |
|
| 37 | + if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao") ) {
|
|
| 38 | + $this->database .= "Homologacao"; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | if (!isset($this->instance)) {
|
| 41 | 42 | $this->instance = Connect::getInstance($this->database); |
@@ -340,18 +341,26 @@ discard block |
||
| 340 | 341 | $indexed = $params == array_values($params); |
| 341 | 342 | foreach($params as $k=>$v) {
|
| 342 | 343 | if (is_object($v)) {
|
| 343 | - if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s');
|
|
| 344 | - else continue; |
|
| 344 | + if ($v instanceof \DateTime) {
|
|
| 345 | + $v = $v->format('Y-m-d H:i:s');
|
|
| 346 | + } else {
|
|
| 347 | + continue; |
|
| 348 | + } |
|
| 349 | + } elseif (is_string($v)) {
|
|
| 350 | + $v="'$v'"; |
|
| 351 | + } elseif ($v === null) {
|
|
| 352 | + $v='NULL'; |
|
| 353 | + } elseif (is_array($v)) {
|
|
| 354 | + $v = implode(',', $v);
|
|
| 345 | 355 | } |
| 346 | - elseif (is_string($v)) $v="'$v'"; |
|
| 347 | - elseif ($v === null) $v='NULL'; |
|
| 348 | - elseif (is_array($v)) $v = implode(',', $v);
|
|
| 349 | 356 | |
| 350 | 357 | if ($indexed) {
|
| 351 | 358 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1);
|
| 352 | - } |
|
| 353 | - else {
|
|
| 354 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
| 359 | + } else {
|
|
| 360 | + if ($k[0] != ':') {
|
|
| 361 | + $k = ':'.$k; |
|
| 362 | + } |
|
| 363 | + //add leading colon if it was left out |
|
| 355 | 364 | $sql_string = str_replace($k,$v,$sql_string); |
| 356 | 365 | } |
| 357 | 366 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private function getInstance(): ?PDO |
| 36 | 36 | {
|
| 37 | - if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao") ) |
|
| 37 | + if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao")) |
|
| 38 | 38 | $this->database .= "Homologacao"; |
| 39 | 39 | |
| 40 | 40 | if (!isset($this->instance)) {
|
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $this->prepare->execute($params); |
| 59 | 59 | $this->setLogSQL($query, $params); |
| 60 | 60 | } catch (PDOException $e) {
|
| 61 | - Connect::setError($e,$query); |
|
| 61 | + Connect::setError($e, $query); |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param $prepare |
| 70 | 70 | * @return int |
| 71 | 71 | */ |
| 72 | - protected function count($prepare=null): ?int |
|
| 72 | + protected function count($prepare = null): ?int |
|
| 73 | 73 | {
|
| 74 | 74 | try {
|
| 75 | 75 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param $prepare |
| 88 | 88 | * @return array|false |
| 89 | 89 | */ |
| 90 | - protected function fetchArrayAssoc($prepare=null): ?array |
|
| 90 | + protected function fetchArrayAssoc($prepare = null): ?array |
|
| 91 | 91 | {
|
| 92 | 92 | try {
|
| 93 | 93 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @param $prepare |
| 105 | 105 | * @return array|false |
| 106 | 106 | */ |
| 107 | - protected function fetchArrayObj($prepare=null): ?array |
|
| 107 | + protected function fetchArrayObj($prepare = null): ?array |
|
| 108 | 108 | {
|
| 109 | 109 | try {
|
| 110 | 110 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param String|null $class |
| 123 | 123 | * @return array|false |
| 124 | 124 | */ |
| 125 | - protected function fetchArrayClass($prepare=null, String $class=null): ?array |
|
| 125 | + protected function fetchArrayClass($prepare = null, String $class = null): ?array |
|
| 126 | 126 | {
|
| 127 | 127 | try {
|
| 128 | 128 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param $prepare |
| 141 | 141 | * @return array|false |
| 142 | 142 | */ |
| 143 | - protected function fetchOneAssoc($prepare=null): ?array |
|
| 143 | + protected function fetchOneAssoc($prepare = null): ?array |
|
| 144 | 144 | {
|
| 145 | 145 | try {
|
| 146 | 146 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param $prepare |
| 157 | 157 | * @return stdClass|false |
| 158 | 158 | */ |
| 159 | - protected function fetchOneObj($prepare=null): ?stdClass |
|
| 159 | + protected function fetchOneObj($prepare = null): ?stdClass |
|
| 160 | 160 | {
|
| 161 | 161 | try {
|
| 162 | 162 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @param String|null $class |
| 174 | 174 | * @return array|false |
| 175 | 175 | */ |
| 176 | - protected function fetchOneClass($prepare=null, String $class=null): ?object |
|
| 176 | + protected function fetchOneClass($prepare = null, String $class = null): ?object |
|
| 177 | 177 | {
|
| 178 | 178 | try {
|
| 179 | 179 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -259,21 +259,21 @@ discard block |
||
| 259 | 259 | private function setLogSQL($sql_string, array $params = null) {
|
| 260 | 260 | if (!empty($params)) {
|
| 261 | 261 | $indexed = $params == array_values($params); |
| 262 | - foreach($params as $k=>$v) {
|
|
| 262 | + foreach ($params as $k=>$v) {
|
|
| 263 | 263 | if (is_object($v)) {
|
| 264 | 264 | if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s');
|
| 265 | 265 | else continue; |
| 266 | 266 | } |
| 267 | - elseif (is_string($v)) $v="'$v'"; |
|
| 268 | - elseif ($v === null) $v='NULL'; |
|
| 267 | + elseif (is_string($v)) $v = "'$v'"; |
|
| 268 | + elseif ($v === null) $v = 'NULL'; |
|
| 269 | 269 | elseif (is_array($v)) $v = implode(',', $v);
|
| 270 | 270 | |
| 271 | 271 | if ($indexed) {
|
| 272 | 272 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1);
|
| 273 | 273 | } |
| 274 | 274 | else {
|
| 275 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
| 276 | - $sql_string = str_replace($k,$v,$sql_string); |
|
| 275 | + if ($k[0] != ':') $k = ':' . $k; //add leading colon if it was left out |
|
| 276 | + $sql_string = str_replace($k, $v, $sql_string); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -51,8 +51,9 @@ discard block |
||
| 51 | 51 | $sql = "INSERT INTO {$this->tableName} ({$fields}) VALUES ({$numparams})";
|
| 52 | 52 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; die(); }
|
| 53 | 53 | $result = $this->executeSQL($sql, $values); |
| 54 | - if (empty($result)) |
|
| 55 | - return false; |
|
| 54 | + if (empty($result)) {
|
|
| 55 | + return false; |
|
| 56 | + } |
|
| 56 | 57 | return true; |
| 57 | 58 | } |
| 58 | 59 | |
@@ -66,8 +67,9 @@ discard block |
||
| 66 | 67 | $query = "INSERT INTO $this->tableName"; |
| 67 | 68 | $values = []; |
| 68 | 69 | $dataColumns = array_keys($params); |
| 69 | - if (isset ($dataColumns[0])) |
|
| 70 | - $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 70 | + if (isset ($dataColumns[0])) {
|
|
| 71 | + $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 72 | + } |
|
| 71 | 73 | $query .= ' VALUES (';
|
| 72 | 74 | |
| 73 | 75 | foreach ($dataColumns as $index => $column) {
|
@@ -78,8 +80,9 @@ discard block |
||
| 78 | 80 | $query .= ')'; |
| 79 | 81 | |
| 80 | 82 | $result = $this->executeSQL($query, $values); |
| 81 | - if (empty($result)) |
|
| 82 | - return false; |
|
| 83 | + if (empty($result)) {
|
|
| 84 | + return false; |
|
| 85 | + } |
|
| 83 | 86 | return true; |
| 84 | 87 | } else {
|
| 85 | 88 | return false; |
@@ -104,8 +107,9 @@ discard block |
||
| 104 | 107 | if (isset($where)) { $sql .= " WHERE $where"; }
|
| 105 | 108 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; die(); }
|
| 106 | 109 | $result = $this->executeSQL($sql, $values); |
| 107 | - if (empty($result)) |
|
| 108 | - return false; |
|
| 110 | + if (empty($result)) {
|
|
| 111 | + return false; |
|
| 112 | + } |
|
| 109 | 113 | return true; |
| 110 | 114 | } |
| 111 | 115 | |
@@ -126,12 +130,14 @@ discard block |
||
| 126 | 130 | } |
| 127 | 131 | $query = rtrim($query, ", "); |
| 128 | 132 | |
| 129 | - if (!empty($where)) |
|
| 130 | - $query .= " WHERE {$where}";
|
|
| 133 | + if (!empty($where)) {
|
|
| 134 | + $query .= " WHERE {$where}";
|
|
| 135 | + } |
|
| 131 | 136 | |
| 132 | 137 | $result = $this->executeSQL($query, $values); |
| 133 | - if (empty($result)) |
|
| 134 | - return false; |
|
| 138 | + if (empty($result)) {
|
|
| 139 | + return false; |
|
| 140 | + } |
|
| 135 | 141 | return true; |
| 136 | 142 | } else {
|
| 137 | 143 | return false; |
@@ -150,8 +156,9 @@ discard block |
||
| 150 | 156 | if (!empty($where)) { $sql .= " WHERE $where"; }
|
| 151 | 157 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; die(); }
|
| 152 | 158 | $result = $this->executeSQL($sql, $values); |
| 153 | - if (empty($result)) |
|
| 154 | - return false; |
|
| 159 | + if (empty($result)) {
|
|
| 160 | + return false; |
|
| 161 | + } |
|
| 155 | 162 | return true; |
| 156 | 163 | } |
| 157 | 164 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param string $where |
| 135 | 135 | * @return bool|null |
| 136 | 136 | */ |
| 137 | - public function updateObject(object $object, string $where){
|
|
| 137 | + public function updateObject(object $object, string $where) {
|
|
| 138 | 138 | $args = []; |
| 139 | 139 | $params = []; |
| 140 | 140 | foreach ($object as $chave => $valor) {
|
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | /** |
| 207 | 207 | * @return string|null |
| 208 | 208 | */ |
| 209 | - public function getLogSQL():?string |
|
| 209 | + public function getLogSQL(): ?string |
|
| 210 | 210 | {
|
| 211 | 211 | return $this->logSQL; |
| 212 | 212 | } |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | * @param array|null $params |
| 11 | 11 | */ |
| 12 | 12 | public function __construct(array $params = null){ |
| 13 | - if (!empty($params)) |
|
| 14 | - $this->fromMapToModel($params); |
|
| 13 | + if (!empty($params)) {
|
|
| 14 | + $this->fromMapToModel($params); |
|
| 15 | + } |
|
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | /** |
@@ -70,7 +71,9 @@ discard block |
||
| 70 | 71 | $data = (object) $this->toMap(); |
| 71 | 72 | $re_2 = new ReflectionObject($data); |
| 72 | 73 | $classname = get_class($this); |
| 73 | - if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
|
| 74 | + if ($pos = strrpos($classname, '\\')) {
|
|
| 75 | + $classname = substr($classname, $pos + 1); |
|
| 76 | + } |
|
| 74 | 77 | return $classname .' {' . implode(', ', array_map( |
| 75 | 78 | function($p_0) use ($data) |
| 76 | 79 | { |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @param array|null $params |
| 11 | 11 | */ |
| 12 | - public function __construct(array $params = null){ |
|
| 12 | + public function __construct(array $params = null) { |
|
| 13 | 13 | if (!empty($params)) |
| 14 | 14 | $this->fromMapToModel($params); |
| 15 | 15 | } |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | $re_2 = new ReflectionObject($data); |
| 72 | 72 | $classname = get_class($this); |
| 73 | 73 | if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
| 74 | - return $classname .' {' . implode(', ', array_map( |
|
| 74 | + return $classname . ' {' . implode(', ', array_map( |
|
| 75 | 75 | function($p_0) use ($data) |
| 76 | 76 | { |
| 77 | 77 | $p_0->setAccessible(true); |
| 78 | - return $p_0->getName() .': '. $p_0->getValue($data); |
|
| 79 | - }, $re_2->getProperties())) .'}'; |
|
| 78 | + return $p_0->getName() . ': ' . $p_0->getValue($data); |
|
| 79 | + }, $re_2->getProperties())) . '}'; |
|
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @return string|null |
| 86 | 86 | */ |
| 87 | 87 | public function __get($attribute) { |
| 88 | - return $this->{$attribute}??"" ; |
|
| 88 | + return $this->{$attribute} ?? ""; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,6 +94,6 @@ discard block |
||
| 94 | 94 | * @return void |
| 95 | 95 | */ |
| 96 | 96 | public function __set($attribute, $value): void { |
| 97 | - $this->{$attribute} = $value ; |
|
| 97 | + $this->{$attribute} = $value; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | \ No newline at end of file |