@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function addProperties($config) |
| 29 | 29 | { |
| 30 | - foreach($config as $name => $type) { |
|
| 30 | + foreach ($config as $name => $type) { |
|
| 31 | 31 | $this->addProperty($name, $type); |
| 32 | 32 | } |
| 33 | 33 | return $this; |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | public function addProperty($name, $type) |
| 37 | 37 | { |
| 38 | 38 | $format = $this->getFormat(); |
| 39 | - foreach($format as $field) { |
|
| 40 | - if($field['name'] == $name) { |
|
| 39 | + foreach ($format as $field) { |
|
| 40 | + if ($field['name'] == $name) { |
|
| 41 | 41 | throw new Exception("Property $name exists"); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $format = $this->getFormat(); |
| 56 | 56 | $last = array_pop($format); |
| 57 | - if($last['name'] != $name) { |
|
| 57 | + if ($last['name'] != $name) { |
|
| 58 | 58 | throw new Exception("Remove only last property"); |
| 59 | 59 | } |
| 60 | 60 | $this->mapper->getClient()->evaluate("box.space[$this->id]:format(...)", [$format]); |
@@ -82,13 +82,13 @@ discard block |
||
| 82 | 82 | public function createIndex($config) |
| 83 | 83 | { |
| 84 | 84 | |
| 85 | - if(!is_array($config)) { |
|
| 85 | + if (!is_array($config)) { |
|
| 86 | 86 | $config = ['fields' => $config]; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | - if(!array_key_exists('fields', $config)) { |
|
| 91 | - if(array_values($config) != $config) { |
|
| 90 | + if (!array_key_exists('fields', $config)) { |
|
| 91 | + if (array_values($config) != $config) { |
|
| 92 | 92 | throw new Exception("Invalid index configuration"); |
| 93 | 93 | } |
| 94 | 94 | $config = [ |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | ]; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if(!is_array($config['fields'])) { |
|
| 99 | + if (!is_array($config['fields'])) { |
|
| 100 | 100 | $config['fields'] = [$config['fields']]; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | 'parts' => [] |
| 105 | 105 | ]; |
| 106 | 106 | |
| 107 | - foreach($config as $k => $v) { |
|
| 108 | - if($k != 'name' && $k != 'fields') { |
|
| 107 | + foreach ($config as $k => $v) { |
|
| 108 | + if ($k != 'name' && $k != 'fields') { |
|
| 109 | 109 | $options[$k] = $v; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - foreach($config['fields'] as $property) { |
|
| 114 | - if(!$this->getPropertyType($property)) { |
|
| 113 | + foreach ($config['fields'] as $property) { |
|
| 114 | + if (!$this->getPropertyType($property)) { |
|
| 115 | 115 | throw new Exception("Unknown property $property", 1); |
| 116 | 116 | } |
| 117 | - $options['parts'][] = $this->getPropertyIndex($property)+1; |
|
| 117 | + $options['parts'][] = $this->getPropertyIndex($property) + 1; |
|
| 118 | 118 | $options['parts'][] = $this->getPropertyType($property); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | public function getFormat() |
| 142 | 142 | { |
| 143 | - if(!$this->format) { |
|
| 144 | - if($this->isSpecial()) { |
|
| 143 | + if (!$this->format) { |
|
| 144 | + if ($this->isSpecial()) { |
|
| 145 | 145 | $this->format = $this->mapper->getClient() |
| 146 | 146 | ->getSpace(280)->select([$this->id])->getData()[0][6]; |
| 147 | 147 | |
| 148 | 148 | } else { |
| 149 | 149 | $this->format = $this->mapper->findOne('_space', ['id' => $this->id])->format; |
| 150 | 150 | } |
| 151 | - if(!$this->format) { |
|
| 151 | + if (!$this->format) { |
|
| 152 | 152 | $this->format = []; |
| 153 | 153 | } |
| 154 | 154 | $this->parseFormat(); |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | $this->formatTypesHash = []; |
| 173 | 173 | $this->formatNamesHash = []; |
| 174 | - foreach($this->format as $key => $row) { |
|
| 174 | + foreach ($this->format as $key => $row) { |
|
| 175 | 175 | $this->formatTypesHash[$row['name']] = $row['type']; |
| 176 | 176 | $this->formatNamesHash[$row['name']] = $key; |
| 177 | 177 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | public function getPropertyType($name) |
| 188 | 188 | { |
| 189 | - if(!$this->hasProperty($name)) { |
|
| 189 | + if (!$this->hasProperty($name)) { |
|
| 190 | 190 | throw new Exception("No property $name"); |
| 191 | 191 | } |
| 192 | 192 | return $this->formatTypesHash[$name]; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | public function getPropertyIndex($name) |
| 196 | 196 | { |
| 197 | - if(!$this->hasProperty($name)) { |
|
| 197 | + if (!$this->hasProperty($name)) { |
|
| 198 | 198 | throw new Exception("No property $name"); |
| 199 | 199 | } |
| 200 | 200 | return $this->formatNamesHash[$name]; |
@@ -202,14 +202,14 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | public function getIndexes() |
| 204 | 204 | { |
| 205 | - if(!$this->indexes) { |
|
| 206 | - if($this->isSpecial()) { |
|
| 205 | + if (!$this->indexes) { |
|
| 206 | + if ($this->isSpecial()) { |
|
| 207 | 207 | $this->indexes = []; |
| 208 | 208 | $indexTuples = $this->mapper->getClient()->getSpace(288)->select([$this->id])->getData(); |
| 209 | 209 | $indexFormat = $this->mapper->getSchema()->getSpace(288)->getFormat(); |
| 210 | - foreach($indexTuples as $tuple) { |
|
| 210 | + foreach ($indexTuples as $tuple) { |
|
| 211 | 211 | $instance = (object) []; |
| 212 | - foreach($indexFormat as $index => $format) { |
|
| 212 | + foreach ($indexFormat as $index => $format) { |
|
| 213 | 213 | $instance->{$format['name']} = $tuple[$index]; |
| 214 | 214 | } |
| 215 | 215 | $this->indexes[] = $instance; |
@@ -227,44 +227,44 @@ discard block |
||
| 227 | 227 | $keys = array_keys($params); |
| 228 | 228 | |
| 229 | 229 | $keys = []; |
| 230 | - foreach($params as $name => $value) { |
|
| 230 | + foreach ($params as $name => $value) { |
|
| 231 | 231 | $keys[] = $this->getPropertyIndex($name); |
| 232 | 232 | } |
| 233 | - if($keys == [0]) { |
|
| 233 | + if ($keys == [0]) { |
|
| 234 | 234 | // primary index |
| 235 | 235 | return 0; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // equals |
| 239 | - foreach($this->getIndexes() as $index) { |
|
| 239 | + foreach ($this->getIndexes() as $index) { |
|
| 240 | 240 | $equals = false; |
| 241 | - if(count($keys) == count($index->parts)) { |
|
| 241 | + if (count($keys) == count($index->parts)) { |
|
| 242 | 242 | // same length |
| 243 | 243 | $equals = true; |
| 244 | - foreach($index->parts as $part) { |
|
| 244 | + foreach ($index->parts as $part) { |
|
| 245 | 245 | $equals = $equals && in_array($part[0], $keys); |
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if($equals) { |
|
| 249 | + if ($equals) { |
|
| 250 | 250 | return $index->iid; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // index part |
| 255 | - foreach($this->getIndexes() as $index) { |
|
| 255 | + foreach ($this->getIndexes() as $index) { |
|
| 256 | 256 | $partial = []; |
| 257 | - foreach($index->parts as $n => $part) { |
|
| 258 | - if(!array_key_exists($n, $keys)) { |
|
| 257 | + foreach ($index->parts as $n => $part) { |
|
| 258 | + if (!array_key_exists($n, $keys)) { |
|
| 259 | 259 | break; |
| 260 | 260 | } |
| 261 | - if($keys[$n] != $part[0]) { |
|
| 261 | + if ($keys[$n] != $part[0]) { |
|
| 262 | 262 | break; |
| 263 | 263 | } |
| 264 | 264 | $partial[] = $keys[$n]; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if(count($partial) == count($keys)) { |
|
| 267 | + if (count($partial) == count($keys)) { |
|
| 268 | 268 | return $index->iid; |
| 269 | 269 | } |
| 270 | 270 | } |
@@ -275,21 +275,21 @@ discard block |
||
| 275 | 275 | public function getIndexValues($indexId, $params) |
| 276 | 276 | { |
| 277 | 277 | $index = null; |
| 278 | - foreach($this->getIndexes() as $candidate) { |
|
| 279 | - if($candidate->iid == $indexId) { |
|
| 278 | + foreach ($this->getIndexes() as $candidate) { |
|
| 279 | + if ($candidate->iid == $indexId) { |
|
| 280 | 280 | $index = $candidate; |
| 281 | 281 | break; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - if(!$index) { |
|
| 284 | + if (!$index) { |
|
| 285 | 285 | throw new Exception("Undefined index: $indexId"); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $format = $this->getFormat(); |
| 289 | 289 | $values = []; |
| 290 | - foreach($index->parts as $part) { |
|
| 290 | + foreach ($index->parts as $part) { |
|
| 291 | 291 | $name = $format[$part[0]]['name']; |
| 292 | - if(!array_key_exists($name, $params)) { |
|
| 292 | + if (!array_key_exists($name, $params)) { |
|
| 293 | 293 | break; |
| 294 | 294 | } |
| 295 | 295 | $values[] = $this->mapper->getSchema()->formatValue($part[1], $params[$name]); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | public function getPrimaryIndex() |
| 301 | 301 | { |
| 302 | 302 | $indexes = $this->getIndexes(); |
| 303 | - if(!count($indexes)) { |
|
| 303 | + if (!count($indexes)) { |
|
| 304 | 304 | throw new Exception("No primary index"); |
| 305 | 305 | } |
| 306 | 306 | return $indexes[0]; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function getTupleKey($tuple) |
| 310 | 310 | { |
| 311 | 311 | $key = []; |
| 312 | - foreach($this->getPrimaryIndex()->parts as $part) { |
|
| 312 | + foreach ($this->getPrimaryIndex()->parts as $part) { |
|
| 313 | 313 | $key[] = $tuple[$part[0]]; |
| 314 | 314 | } |
| 315 | 315 | return count($key) == 1 ? $key[0] : implode(':', $key); |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | $key = []; |
| 322 | 322 | |
| 323 | - foreach($this->getPrimaryIndex()->parts as $part) { |
|
| 323 | + foreach ($this->getPrimaryIndex()->parts as $part) { |
|
| 324 | 324 | $name = $this->getFormat()[$part[0]]['name']; |
| 325 | - if(!property_exists($instance, $name)) { |
|
| 325 | + if (!property_exists($instance, $name)) { |
|
| 326 | 326 | throw new Exception("Field $name is undefined", 1); |
| 327 | 327 | } |
| 328 | 328 | $key[] = $instance->$name; |
@@ -334,10 +334,10 @@ discard block |
||
| 334 | 334 | public function getRepository() |
| 335 | 335 | { |
| 336 | 336 | $class = Repository::class; |
| 337 | - foreach($this->mapper->getPlugins() as $plugin) { |
|
| 337 | + foreach ($this->mapper->getPlugins() as $plugin) { |
|
| 338 | 338 | $repositoryClass = $plugin->getRepositoryClass($this); |
| 339 | - if($repositoryClass) { |
|
| 340 | - if($class != Repository::class) { |
|
| 339 | + if ($repositoryClass) { |
|
| 340 | + if ($class != Repository::class) { |
|
| 341 | 341 | throw new Exception('Repository class override'); |
| 342 | 342 | } |
| 343 | 343 | $class = $repositoryClass; |