@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | if (array_key_exists($alias, $array)) |
| 60 | 60 | $value = $array[$alias]; |
| 61 | 61 | |
| 62 | - if(!empty($configuration->getType())) |
|
| 62 | + if (!empty($configuration->getType())) |
|
| 63 | 63 | { |
| 64 | 64 | $type = $configuration->getType(); |
| 65 | 65 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $value = new $type($value, false); |
| 69 | 69 | } |
| 70 | - catch(NoDataFoundException $e) |
|
| 70 | + catch (NoDataFoundException $e) |
|
| 71 | 71 | { |
| 72 | 72 | $value = new $type(); |
| 73 | 73 | } |
@@ -50,14 +50,16 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | // Se o campo for do tipo que deve ser ignorado, |
| 52 | 52 | // não meche nele... |
| 53 | - if ($configuration->ignore()) |
|
| 54 | - return; |
|
| 53 | + if ($configuration->ignore()) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 55 | 56 | |
| 56 | 57 | $value = null; |
| 57 | 58 | $alias = $configuration->getAlias(); |
| 58 | 59 | |
| 59 | - if (array_key_exists($alias, $array)) |
|
| 60 | - $value = $array[$alias]; |
|
| 60 | + if (array_key_exists($alias, $array)) { |
|
| 61 | + $value = $array[$alias]; |
|
| 62 | + } |
|
| 61 | 63 | |
| 62 | 64 | if(!empty($configuration->getType())) |
| 63 | 65 | { |
@@ -66,8 +68,7 @@ discard block |
||
| 66 | 68 | try |
| 67 | 69 | { |
| 68 | 70 | $value = new $type($value, false); |
| 69 | - } |
|
| 70 | - catch(NoDataFoundException $e) |
|
| 71 | + } catch(NoDataFoundException $e) |
|
| 71 | 72 | { |
| 72 | 73 | $value = new $type(); |
| 73 | 74 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | /** |
| 16 | 16 | * Extrai as informações existentes em uma classe |
| 17 | - * @param $object |
|
| 17 | + * @param \Silk\Model\AbstractMappableModel $object |
|
| 18 | 18 | * @return array |
| 19 | 19 | */ |
| 20 | 20 | public static function extract($object, $parent = true) |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | $class = (new \ReflectionClass($object))->getProperties(); |
| 25 | 25 | |
| 26 | - if($parent == false) |
|
| 26 | + if ($parent == false) |
|
| 27 | 27 | $class = (new \ReflectionClass($object))->getParentClass()->getProperties(); |
| 28 | 28 | |
| 29 | 29 | foreach ($class as $property) { |
@@ -23,14 +23,16 @@ |
||
| 23 | 23 | |
| 24 | 24 | $class = (new \ReflectionClass($object))->getProperties(); |
| 25 | 25 | |
| 26 | - if($parent == false) |
|
| 27 | - $class = (new \ReflectionClass($object))->getParentClass()->getProperties(); |
|
| 26 | + if($parent == false) { |
|
| 27 | + $class = (new \ReflectionClass($object))->getParentClass()->getProperties(); |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | foreach ($class as $property) { |
| 30 | 31 | $config = new PropertyConfiguration($property, $object); |
| 31 | 32 | |
| 32 | - if ($config->ignore() || $config->shouldIgnoreIfNull()) |
|
| 33 | - continue; |
|
| 33 | + if ($config->ignore() || $config->shouldIgnoreIfNull()) { |
|
| 34 | + continue; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | $name = $config->getAlias(); |
| 36 | 38 | $data = $config->getValue(); |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | if ($this->value instanceof MappableModelInterface) { |
| 103 | 103 | return $this->value->getId(); |
| 104 | 104 | } |
| 105 | - else if($this->value instanceof \DateTime){ |
|
| 105 | + else if ($this->value instanceof \DateTime) { |
|
| 106 | 106 | return $this->value->format('Y-m-d'); |
| 107 | 107 | } |
| 108 | 108 | return $this->value; |
@@ -63,17 +63,21 @@ discard block |
||
| 63 | 63 | $this->setName($property->getName()); |
| 64 | 64 | $this->setValue($property->getValue($object)); |
| 65 | 65 | |
| 66 | - if (array_key_exists('alias', $config)) |
|
| 67 | - $this->setAlias($config['alias']); |
|
| 66 | + if (array_key_exists('alias', $config)) { |
|
| 67 | + $this->setAlias($config['alias']); |
|
| 68 | + } |
|
| 68 | 69 | |
| 69 | - if (array_key_exists('ignore', $config)) |
|
| 70 | - $this->setIgnore($config['ignore']); |
|
| 70 | + if (array_key_exists('ignore', $config)) { |
|
| 71 | + $this->setIgnore($config['ignore']); |
|
| 72 | + } |
|
| 71 | 73 | |
| 72 | - if (array_key_exists('ignoreIfNull', $config)) |
|
| 73 | - $this->setIgnoreIfNull($config['ignoreIfNull']); |
|
| 74 | + if (array_key_exists('ignoreIfNull', $config)) { |
|
| 75 | + $this->setIgnoreIfNull($config['ignoreIfNull']); |
|
| 76 | + } |
|
| 74 | 77 | |
| 75 | - if (array_key_exists('type', $config)) |
|
| 76 | - $this->setType($config['type']); |
|
| 78 | + if (array_key_exists('type', $config)) { |
|
| 79 | + $this->setType($config['type']); |
|
| 80 | + } |
|
| 77 | 81 | } |
| 78 | 82 | |
| 79 | 83 | /** |
@@ -101,8 +105,7 @@ discard block |
||
| 101 | 105 | { |
| 102 | 106 | if ($this->value instanceof MappableModelInterface) { |
| 103 | 107 | return $this->value->getId(); |
| 104 | - } |
|
| 105 | - else if($this->value instanceof \DateTime){ |
|
| 108 | + } else if($this->value instanceof \DateTime){ |
|
| 106 | 109 | return $this->value->format('Y-m-d'); |
| 107 | 110 | } |
| 108 | 111 | return $this->value; |
@@ -181,8 +184,9 @@ discard block |
||
| 181 | 184 | */ |
| 182 | 185 | public function getAlias() |
| 183 | 186 | { |
| 184 | - if (!empty($this->alias)) |
|
| 185 | - return $this->alias; |
|
| 187 | + if (!empty($this->alias)) { |
|
| 188 | + return $this->alias; |
|
| 189 | + } |
|
| 186 | 190 | |
| 187 | 191 | return $this->name; |
| 188 | 192 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->lazy = $lazy; |
| 75 | 75 | |
| 76 | 76 | // Se não for lazy load, carrega o objeto |
| 77 | - if(!$this->lazy) |
|
| 77 | + if (!$this->lazy) |
|
| 78 | 78 | $this->populate($this->where); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function __call($name, $arg) |
| 91 | 91 | { |
| 92 | 92 | // Carrega o objeto se por lazy load |
| 93 | - if($this->lazy) |
|
| 93 | + if ($this->lazy) |
|
| 94 | 94 | $this->populate($this->where); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | { |
| 126 | 126 | // Se for numérico ou string, presume-se |
| 127 | 127 | // que é uma chave primária. |
| 128 | - if(is_numeric($param) || is_string($param)) |
|
| 128 | + if (is_numeric($param) || is_string($param)) |
|
| 129 | 129 | { |
| 130 | 130 | $this->populateFromId($param); |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | // Verifica se é um comando do tipo where |
| 134 | 134 | // que pode ser usado diretamente como parâmetro |
| 135 | 135 | // no TableGateway do Zend Framework 2. |
| 136 | - else if(!is_null($param)) |
|
| 136 | + else if (!is_null($param)) |
|
| 137 | 137 | { |
| 138 | 138 | $this->populateFromWhere($param); |
| 139 | 139 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | private function populateFromId($id) |
| 152 | 152 | { |
| 153 | - if(empty($this->primaryKey)) |
|
| 153 | + if (empty($this->primaryKey)) |
|
| 154 | 154 | throw new NoPrimaryKeyException(); |
| 155 | 155 | |
| 156 | 156 | $this->populateFromWhere([$this->primaryKey => $id]); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $resultSet = $this->tableGateway->select($where); |
| 171 | 171 | |
| 172 | - if($resultSet->count() === 0) |
|
| 172 | + if ($resultSet->count() === 0) |
|
| 173 | 173 | throw new NoDataFoundException(); |
| 174 | 174 | |
| 175 | 175 | $array = $resultSet->toArray()[0]; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * Método a ser executado antes de salvar o objeto. |
| 181 | 181 | * @return mixed |
| 182 | 182 | */ |
| 183 | - protected function beforeSave(){} |
|
| 183 | + protected function beforeSave() {} |
|
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * Método responsável por salvar um objeto no banco de dados |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function save($callBeforeSave = true) |
| 194 | 194 | { |
| 195 | - if($callBeforeSave) { |
|
| 195 | + if ($callBeforeSave) { |
|
| 196 | 196 | $this->beforeSave(); |
| 197 | 197 | $this->tableGateway = new TableGateway($this, Reader::getConfig($this)['table']); |
| 198 | 198 | } |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $this->tableGateway = new TableGateway($this, Reader::getConfig($this)['parent']); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if(empty($this->getId())) |
|
| 204 | + if (empty($this->getId())) |
|
| 205 | 205 | { |
| 206 | 206 | return $this->insert($callBeforeSave); |
| 207 | 207 | } |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | $table = new TableGateway(self::getInstance(), Reader::getConfig(self::getInstance())['table']); |
| 227 | 227 | $resultSet = $table->select($where); |
| 228 | 228 | |
| 229 | - if($resultSet->count() === 0) |
|
| 229 | + if ($resultSet->count() === 0) |
|
| 230 | 230 | throw new NoDataFoundException(); |
| 231 | 231 | |
| 232 | 232 | $list = new ArrayList(); |
| 233 | 233 | |
| 234 | - foreach($resultSet->toArray() as $array) |
|
| 234 | + foreach ($resultSet->toArray() as $array) |
|
| 235 | 235 | { |
| 236 | 236 | $obj = self::getInstance(); |
| 237 | 237 | Populator::populate($obj, $array); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $this->tableGateway->insert(Extractor::extract($this, $parent)); |
| 255 | 255 | $id = $this->tableGateway->getLastInsertValue(); |
| 256 | 256 | |
| 257 | - if($parent) |
|
| 257 | + if ($parent) |
|
| 258 | 258 | $this->setId($id); |
| 259 | 259 | |
| 260 | 260 | return $id; |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | { |
| 289 | 289 | $this->tableGateway = new TableGateway($this); |
| 290 | 290 | |
| 291 | - if(!empty($this->primaryKey)) |
|
| 291 | + if (!empty($this->primaryKey)) |
|
| 292 | 292 | { |
| 293 | 293 | return $this->tableGateway->delete([$this->primaryKey => $this->getId()]); |
| 294 | 294 | } |
@@ -74,8 +74,9 @@ discard block |
||
| 74 | 74 | $this->lazy = $lazy; |
| 75 | 75 | |
| 76 | 76 | // Se não for lazy load, carrega o objeto |
| 77 | - if(!$this->lazy) |
|
| 78 | - $this->populate($this->where); |
|
| 77 | + if(!$this->lazy) { |
|
| 78 | + $this->populate($this->where); |
|
| 79 | + } |
|
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | /** |
@@ -90,8 +91,9 @@ discard block |
||
| 90 | 91 | public function __call($name, $arg) |
| 91 | 92 | { |
| 92 | 93 | // Carrega o objeto se por lazy load |
| 93 | - if($this->lazy) |
|
| 94 | - $this->populate($this->where); |
|
| 94 | + if($this->lazy) { |
|
| 95 | + $this->populate($this->where); |
|
| 96 | + } |
|
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | /** |
@@ -150,8 +152,9 @@ discard block |
||
| 150 | 152 | */ |
| 151 | 153 | private function populateFromId($id) |
| 152 | 154 | { |
| 153 | - if(empty($this->primaryKey)) |
|
| 154 | - throw new NoPrimaryKeyException(); |
|
| 155 | + if(empty($this->primaryKey)) { |
|
| 156 | + throw new NoPrimaryKeyException(); |
|
| 157 | + } |
|
| 155 | 158 | |
| 156 | 159 | $this->populateFromWhere([$this->primaryKey => $id]); |
| 157 | 160 | } |
@@ -169,8 +172,9 @@ discard block |
||
| 169 | 172 | { |
| 170 | 173 | $resultSet = $this->tableGateway->select($where); |
| 171 | 174 | |
| 172 | - if($resultSet->count() === 0) |
|
| 173 | - throw new NoDataFoundException(); |
|
| 175 | + if($resultSet->count() === 0) { |
|
| 176 | + throw new NoDataFoundException(); |
|
| 177 | + } |
|
| 174 | 178 | |
| 175 | 179 | $array = $resultSet->toArray()[0]; |
| 176 | 180 | Populator::populate($this, $array); |
@@ -195,8 +199,7 @@ discard block |
||
| 195 | 199 | if($callBeforeSave) { |
| 196 | 200 | $this->beforeSave(); |
| 197 | 201 | $this->tableGateway = new TableGateway($this, Reader::getConfig($this)['table']); |
| 198 | - } |
|
| 199 | - else |
|
| 202 | + } else |
|
| 200 | 203 | { |
| 201 | 204 | $this->tableGateway = new TableGateway($this, Reader::getConfig($this)['parent']); |
| 202 | 205 | } |
@@ -204,8 +207,7 @@ discard block |
||
| 204 | 207 | if(empty($this->getId())) |
| 205 | 208 | { |
| 206 | 209 | return $this->insert($callBeforeSave); |
| 207 | - } |
|
| 208 | - else |
|
| 210 | + } else |
|
| 209 | 211 | { |
| 210 | 212 | return $this->update(); |
| 211 | 213 | } |
@@ -226,8 +228,9 @@ discard block |
||
| 226 | 228 | $table = new TableGateway(self::getInstance(), Reader::getConfig(self::getInstance())['table']); |
| 227 | 229 | $resultSet = $table->select($where); |
| 228 | 230 | |
| 229 | - if($resultSet->count() === 0) |
|
| 230 | - throw new NoDataFoundException(); |
|
| 231 | + if($resultSet->count() === 0) { |
|
| 232 | + throw new NoDataFoundException(); |
|
| 233 | + } |
|
| 231 | 234 | |
| 232 | 235 | $list = new ArrayList(); |
| 233 | 236 | |
@@ -254,8 +257,9 @@ discard block |
||
| 254 | 257 | $this->tableGateway->insert(Extractor::extract($this, $parent)); |
| 255 | 258 | $id = $this->tableGateway->getLastInsertValue(); |
| 256 | 259 | |
| 257 | - if($parent) |
|
| 258 | - $this->setId($id); |
|
| 260 | + if($parent) { |
|
| 261 | + $this->setId($id); |
|
| 262 | + } |
|
| 259 | 263 | |
| 260 | 264 | return $id; |
| 261 | 265 | } |
@@ -291,8 +295,7 @@ discard block |
||
| 291 | 295 | if(!empty($this->primaryKey)) |
| 292 | 296 | { |
| 293 | 297 | return $this->tableGateway->delete([$this->primaryKey => $this->getId()]); |
| 294 | - } |
|
| 295 | - else |
|
| 298 | + } else |
|
| 296 | 299 | { |
| 297 | 300 | return $this->tableGateway->delete(Extractor::extract($this)); |
| 298 | 301 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | if(!empty($adapter)) |
| 29 | 29 | $this->adapter = $adapter; |
| 30 | 30 | else |
| 31 | - $this->adapter = GlobalAdapterFeature::getStaticAdapter(); |
|
| 31 | + $this->adapter = GlobalAdapterFeature::getStaticAdapter(); |
|
| 32 | 32 | |
| 33 | 33 | $this->updateContext(); |
| 34 | 34 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | $this->table = $this->config['table']; |
| 27 | 27 | |
| 28 | - if(!empty($adapter)) |
|
| 28 | + if (!empty($adapter)) |
|
| 29 | 29 | $this->adapter = $adapter; |
| 30 | 30 | else |
| 31 | 31 | $this->adapter = GlobalAdapterFeature::getStaticAdapter(); |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | protected function updateContext() |
| 37 | 37 | { |
| 38 | - if(isset($this->config['schema'])){ |
|
| 39 | - $sql = 'USE ' . $this->config['schema'] . ';'; |
|
| 38 | + if (isset($this->config['schema'])) { |
|
| 39 | + $sql = 'USE '.$this->config['schema'].';'; |
|
| 40 | 40 | $this->adapter->getDriver()->getConnection()->execute($sql); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -20,15 +20,17 @@ |
||
| 20 | 20 | { |
| 21 | 21 | $this->config = Reader::getConfig($object); |
| 22 | 22 | |
| 23 | - if (!array_key_exists('table', $this->config)) |
|
| 24 | - throw new NoTableFoundException(); |
|
| 23 | + if (!array_key_exists('table', $this->config)) { |
|
| 24 | + throw new NoTableFoundException(); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | $this->table = $this->config['table']; |
| 27 | 28 | |
| 28 | - if(!empty($adapter)) |
|
| 29 | - $this->adapter = $adapter; |
|
| 30 | - else |
|
| 31 | - $this->adapter = GlobalAdapterFeature::getStaticAdapter(); |
|
| 29 | + if(!empty($adapter)) { |
|
| 30 | + $this->adapter = $adapter; |
|
| 31 | + } else { |
|
| 32 | + $this->adapter = GlobalAdapterFeature::getStaticAdapter(); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $this->updateContext(); |
| 34 | 36 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * @param $key |
|
| 34 | + * @param string $key |
|
| 35 | 35 | * @param Adapter $adapter |
| 36 | 36 | * @return $this |
| 37 | 37 | */ |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Silk\Database; |
| 4 | 4 | |
| 5 | 5 | use Zend\Db\Adapter\Adapter; |
| 6 | -use Zend\Db\TableGateway\TableGateway; |
|
| 7 | 6 | use Zend\Db\TableGateway\Feature\GlobalAdapterFeature; |
| 8 | 7 | |
| 9 | 8 | /** |