@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public function __construct($hydrate = true) |
16 | 16 | { |
17 | 17 | parent::__construct(); |
18 | - if($hydrate) { |
|
18 | + if ($hydrate) { |
|
19 | 19 | $this->fromArray(Request::getInstance()->getData()); |
20 | 20 | } |
21 | 21 | } |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | /** @var \ReflectionProperty $property */ |
44 | 44 | foreach ($properties as $property) { |
45 | 45 | $value = $property->getValue($this); |
46 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
46 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
47 | 47 | $dto[$property->getName()] = $value->toArray(); |
48 | - } elseif(is_array($value)) { |
|
49 | - foreach($value as &$arrValue) { |
|
50 | - if($arrValue instanceof Dto) { |
|
48 | + } elseif (is_array($value)) { |
|
49 | + foreach ($value as &$arrValue) { |
|
50 | + if ($arrValue instanceof Dto) { |
|
51 | 51 | $arrValue = $arrValue->toArray(); |
52 | 52 | } |
53 | 53 | } |
54 | 54 | $dto[$property->getName()] = $value; |
55 | - } else { |
|
55 | + }else { |
|
56 | 56 | $dto[$property->getName()] = $property->getValue($this); |
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
60 | - } catch (\Exception $e) { |
|
61 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
60 | + }catch (\Exception $e) { |
|
61 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
62 | 62 | } |
63 | 63 | return $dto; |
64 | 64 | } |
@@ -80,32 +80,32 @@ discard block |
||
80 | 80 | protected function parseDtoField(array $properties, $key, $value = null) { |
81 | 81 | $type = 'string'; |
82 | 82 | $is_array = false; |
83 | - if(array_key_exists($key, $properties)) { |
|
83 | + if (array_key_exists($key, $properties)) { |
|
84 | 84 | $type = $properties[$key]; |
85 | - if(preg_match('/(\[\]|Array)/i', $type)) { |
|
85 | + if (preg_match('/(\[\]|Array)/i', $type)) { |
|
86 | 86 | $type = preg_replace('/(\[\]|Array)/i', '', $type); |
87 | 87 | $is_array = true; |
88 | 88 | } |
89 | 89 | } |
90 | 90 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
91 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
92 | - if(null !== $value && is_array($value)) { |
|
93 | - if($is_array) { |
|
91 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
92 | + if (null !== $value && is_array($value)) { |
|
93 | + if ($is_array) { |
|
94 | 94 | $this->$key = []; |
95 | - foreach($value as $data) { |
|
96 | - if(null !== $data && is_array($data)) { |
|
95 | + foreach ($value as $data) { |
|
96 | + if (null !== $data && is_array($data)) { |
|
97 | 97 | $dto = new $type(false); |
98 | 98 | $dto->fromArray($data); |
99 | 99 | array_push($this->$key, $dto); |
100 | 100 | } |
101 | 101 | } |
102 | - } else { |
|
102 | + }else { |
|
103 | 103 | $this->$key = new $type(false); |
104 | 104 | $this->$key->fromArray($value); |
105 | 105 | } |
106 | 106 | } |
107 | - } else { |
|
108 | - switch($type) { |
|
107 | + }else { |
|
108 | + switch ($type) { |
|
109 | 109 | default: |
110 | 110 | case 'string': |
111 | 111 | $this->$key = $value; |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function json($response, $statusCode = 200) |
27 | 27 | { |
28 | - if(Config::getParam('profiling.enable')) { |
|
29 | - if(is_array($response)) { |
|
28 | + if (Config::getParam('profiling.enable')) { |
|
29 | + if (is_array($response)) { |
|
30 | 30 | $response['profiling'] = Inspector::getStats(); |
31 | - } elseif($response instanceof JsonResponse) { |
|
31 | + } elseif ($response instanceof JsonResponse) { |
|
32 | 32 | $response = ProfilingJsonResponse::createFromPrevious($response, Inspector::getStats()); |
33 | 33 | } |
34 | 34 | } |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | $this->decodeJsonResponse($response); |
37 | 37 | |
38 | 38 | $mask = JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING; |
39 | - if(Config::getParam('output.json.strict_numbers')) { |
|
39 | + if (Config::getParam('output.json.strict_numbers')) { |
|
40 | 40 | $mask = JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING | JSON_NUMERIC_CHECK; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $data = json_encode($response, $mask); |
44 | - if(json_last_error() !== JSON_ERROR_NONE) { |
|
44 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
45 | 45 | Logger::log(json_last_error_msg(), LOG_CRIT); |
46 | 46 | } |
47 | 47 | |
48 | - if(Config::getParam('angular.protection', false)) { |
|
49 | - $data = ")]}',\n" . $data; |
|
48 | + if (Config::getParam('angular.protection', false)) { |
|
49 | + $data = ")]}',\n".$data; |
|
50 | 50 | } |
51 | 51 | $this->setStatus($statusCode); |
52 | 52 | ResponseHelper::setDebugHeaders([]); |
@@ -37,20 +37,20 @@ discard block |
||
37 | 37 | $behaviors = $tableMap->getBehaviors(); |
38 | 38 | foreach ($map::getFieldNames() as $field) { |
39 | 39 | $fDto = self::parseFormField($domain, $tableMap, $field, $behaviors); |
40 | - if(null !== $fDto) { |
|
40 | + if (null !== $fDto) { |
|
41 | 41 | $form->addField($fDto); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - if(array_key_exists('i18n', $behaviors)) { |
|
46 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); |
|
47 | - if(null !== $relateI18n) { |
|
45 | + if (array_key_exists('i18n', $behaviors)) { |
|
46 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); |
|
47 | + if (null !== $relateI18n) { |
|
48 | 48 | $i18NTableMap = $relateI18n->getLocalTable(); |
49 | - foreach($i18NTableMap->getColumns() as $columnMap) { |
|
49 | + foreach ($i18NTableMap->getColumns() as $columnMap) { |
|
50 | 50 | $columnName = self::getColumnMapName($columnMap); |
51 | - if(!$form->fieldExists($columnName)) { |
|
51 | + if (!$form->fieldExists($columnName)) { |
|
52 | 52 | $fDto = self::parseFormField($domain, $i18NTableMap, $columnMap->getPhpName(), $i18NTableMap->getBehaviors()); |
53 | - if(null !== $fDto) { |
|
53 | + if (null !== $fDto) { |
|
54 | 54 | $fDto->pk = false; |
55 | 55 | $fDto->required = true; |
56 | 56 | $form->addField($fDto); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $fDto->entity = $relatedModel; |
81 | 81 | $relatedField = $foreignTable->getColumn($mappedColumn->getRelatedColumnName()); |
82 | 82 | $fDto->relatedField = $relatedField->getPhpName(); |
83 | - $fDto->url = Router::getInstance()->getRoute(strtolower($domain) . '-api-' . $relatedModel); |
|
83 | + $fDto->url = Router::getInstance()->getRoute(strtolower($domain).'-api-'.$relatedModel); |
|
84 | 84 | return $fDto; |
85 | 85 | } |
86 | 86 | |
@@ -187,14 +187,14 @@ discard block |
||
187 | 187 | { |
188 | 188 | $column = null; |
189 | 189 | try { |
190 | - foreach($tableMap->getColumns() as $tableMapColumn) { |
|
190 | + foreach ($tableMap->getColumns() as $tableMapColumn) { |
|
191 | 191 | $columnName = $tableMapColumn->getPhpName(); |
192 | - if(preg_match('/^'.$field.'$/i', $columnName)) { |
|
192 | + if (preg_match('/^'.$field.'$/i', $columnName)) { |
|
193 | 193 | $column = $tableMapColumn; |
194 | 194 | break; |
195 | 195 | } |
196 | 196 | } |
197 | - } catch (\Exception $e) { |
|
197 | + }catch (\Exception $e) { |
|
198 | 198 | Logger::log($e->getMessage(), LOG_DEBUG); |
199 | 199 | } |
200 | 200 | return $column; |
@@ -208,18 +208,18 @@ discard block |
||
208 | 208 | private static function addQueryFilter(ColumnMap $column, ModelCriteria &$query, $value = null) |
209 | 209 | { |
210 | 210 | $tableField = $column->getFullyQualifiedName(); |
211 | - if(is_array($value)) { |
|
211 | + if (is_array($value)) { |
|
212 | 212 | $query->add($tableField, $value, Criteria::IN); |
213 | 213 | } elseif (preg_match('/^\[/', $value) && preg_match('/\]$/', $value)) { |
214 | 214 | $query->add($tableField, explode(',', preg_replace('/(\[|\])/', '', $value)), Criteria::IN); |
215 | 215 | } elseif (preg_match('/^(\'|\")(.*)(\'|\")$/', $value)) { |
216 | 216 | $text = preg_replace('/(\'|\")/', '', $value); |
217 | 217 | $text = preg_replace('/\ /', '%', $text); |
218 | - $query->add($tableField, '%' . $text . '%', Criteria::LIKE); |
|
219 | - } else { |
|
220 | - if(null !== $column->getValueSet()) { |
|
218 | + $query->add($tableField, '%'.$text.'%', Criteria::LIKE); |
|
219 | + }else { |
|
220 | + if (null !== $column->getValueSet()) { |
|
221 | 221 | $valueSet = $column->getValueSet(); |
222 | - if(in_array($value, $valueSet)) { |
|
222 | + if (in_array($value, $valueSet)) { |
|
223 | 223 | $value = array_search($value, $valueSet); |
224 | 224 | } |
225 | 225 | } |
@@ -239,31 +239,31 @@ discard block |
||
239 | 239 | $sep = ''; |
240 | 240 | foreach ($tableMap->getColumns() as $column) { |
241 | 241 | if ($column->isText()) { |
242 | - $exp .= $sep . 'IFNULL(' . $column->getFullyQualifiedName() . ',"")'; |
|
242 | + $exp .= $sep.'IFNULL('.$column->getFullyQualifiedName().',"")'; |
|
243 | 243 | $sep = ', " ", '; |
244 | 244 | } |
245 | 245 | } |
246 | - foreach($tableMap->getRelations() as $relation) { |
|
247 | - if(preg_match('/I18n$/i', $relation->getName())) { |
|
246 | + foreach ($tableMap->getRelations() as $relation) { |
|
247 | + if (preg_match('/I18n$/i', $relation->getName())) { |
|
248 | 248 | $localeTableMap = $relation->getLocalTable(); |
249 | 249 | foreach ($localeTableMap->getColumns() as $column) { |
250 | 250 | if ($column->isText()) { |
251 | - $exp .= $sep . 'IFNULL(' . $column->getFullyQualifiedName() . ',"")'; |
|
251 | + $exp .= $sep.'IFNULL('.$column->getFullyQualifiedName().',"")'; |
|
252 | 252 | $sep = ', " ", '; |
253 | 253 | } |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | foreach ($extraColumns as $extra => $name) { |
258 | - if(!preg_match("/(COUNT|DISTINCT|SUM|MAX|MIN|GROUP)/i", $extra)) { |
|
259 | - $exp .= $sep . $extra; |
|
258 | + if (!preg_match("/(COUNT|DISTINCT|SUM|MAX|MIN|GROUP)/i", $extra)) { |
|
259 | + $exp .= $sep.$extra; |
|
260 | 260 | $sep = ', " ", '; |
261 | 261 | } |
262 | 262 | } |
263 | 263 | $exp .= ")"; |
264 | 264 | $text = preg_replace('/(\'|\")/', '', $value); |
265 | 265 | $text = preg_replace('/\ /', '%', $text); |
266 | - $query->where($exp . Criteria::LIKE . '"%' . $text . '%"'); |
|
266 | + $query->where($exp.Criteria::LIKE.'"%'.$text.'%"'); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public static function extractQuery($modelNameNamespace, ConnectionInterface $con = null) |
290 | 290 | { |
291 | - $queryReflector = new \ReflectionClass($modelNameNamespace . "Query"); |
|
291 | + $queryReflector = new \ReflectionClass($modelNameNamespace."Query"); |
|
292 | 292 | /** @var \Propel\Runtime\ActiveQuery\ModelCriteria $query */ |
293 | 293 | $query = $queryReflector->getMethod('create')->invoke($con); |
294 | 294 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | } elseif ($mappedColumn->isText()) { |
318 | 318 | if ($mappedColumn->getSize() > 100) { |
319 | 319 | $fDto = self::createField($field, Field::TEXTAREA_TYPE, $required); |
320 | - } else { |
|
320 | + }else { |
|
321 | 321 | $fDto = self::generateStringField($field, $required); |
322 | 322 | } |
323 | 323 | } elseif ($mappedColumn->getType() === PropelTypes::BOOLEAN) { |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | } elseif (in_array($mappedColumn->getType(), [PropelTypes::ENUM, PropelTypes::SET])) { |
334 | 334 | $fDto = self::generateEnumField($field, $required); |
335 | 335 | foreach ($mappedColumn->getValueSet() as $value) { |
336 | - switch(Config::getParam('api.field.case', TableMap::TYPE_PHPNAME)) { |
|
336 | + switch (Config::getParam('api.field.case', TableMap::TYPE_PHPNAME)) { |
|
337 | 337 | default: |
338 | 338 | case TableMap::TYPE_PHPNAME: |
339 | 339 | $fieldName = $mappedColumn->getPhpName(); |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | $fDto->pk = true; |
358 | 358 | } |
359 | 359 | } |
360 | - switch(Config::getParam('api.field.case', TableMap::TYPE_PHPNAME)) { |
|
360 | + switch (Config::getParam('api.field.case', TableMap::TYPE_PHPNAME)) { |
|
361 | 361 | default: |
362 | 362 | case TableMap::TYPE_PHPNAME: |
363 | 363 | $fDto->name = $mappedColumn->getPhpName(); |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public static function extractPrimaryKeyColumnName(TableMap $tableMap) { |
383 | 383 | $modelPk = null; |
384 | - foreach($tableMap->getPrimaryKeys() as $pk) { |
|
384 | + foreach ($tableMap->getPrimaryKeys() as $pk) { |
|
385 | 385 | $modelPk = $pk; |
386 | 386 | break; |
387 | 387 | } |
@@ -390,15 +390,15 @@ discard block |
||
390 | 390 | |
391 | 391 | private static function mapResult(ActiveRecordInterface $model, array $data = []) { |
392 | 392 | $result = []; |
393 | - foreach($data as $key => $value) { |
|
393 | + foreach ($data as $key => $value) { |
|
394 | 394 | try { |
395 | 395 | $realValue = $model->getByName($key); |
396 | - } catch(\Exception $e) { |
|
396 | + }catch (\Exception $e) { |
|
397 | 397 | $realValue = $value; |
398 | 398 | } |
399 | - if(Api::API_MODEL_KEY_FIELD === $key) { |
|
399 | + if (Api::API_MODEL_KEY_FIELD === $key) { |
|
400 | 400 | $result[$key] = (integer)$realValue; |
401 | - } else { |
|
401 | + }else { |
|
402 | 402 | $result[$key] = $realValue; |
403 | 403 | } |
404 | 404 | } |
@@ -415,14 +415,14 @@ discard block |
||
415 | 415 | $objTableMap = get_class($formatter->getTableMap()); |
416 | 416 | /** @var TableMapTrait $objTableMap */ |
417 | 417 | $objData = $data; |
418 | - foreach($objTableMap::getFieldNames() as $field) { |
|
419 | - if(!array_key_exists($field, $objData)) { |
|
418 | + foreach ($objTableMap::getFieldNames() as $field) { |
|
419 | + if (!array_key_exists($field, $objData)) { |
|
420 | 420 | $objData[$field] = null; |
421 | 421 | } |
422 | 422 | } |
423 | 423 | $obj = @$formatter->getAllObjectsFromRow($objData); |
424 | 424 | $result = self::mapResult($obj, $data); |
425 | - if(!preg_match('/' . $modelPk->getPhpName() . '/i', $query[Api::API_FIELDS_RESULT_FIELD])) { |
|
425 | + if (!preg_match('/'.$modelPk->getPhpName().'/i', $query[Api::API_FIELDS_RESULT_FIELD])) { |
|
426 | 426 | unset($result[$modelPk->getPhpName()]); |
427 | 427 | } |
428 | 428 | return $result; |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public static function getFieldTypes() { |
435 | 435 | $configType = Config::getParam('api.field.case'); |
436 | - switch($configType) { |
|
436 | + switch ($configType) { |
|
437 | 437 | default: |
438 | 438 | case 'UpperCamelCase': |
439 | 439 | case TableMap::TYPE_PHPNAME: |
@@ -459,11 +459,11 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | public static function getColumnMapName(ColumnMap $field) { |
462 | - switch(self::getFieldTypes()) { |
|
462 | + switch (self::getFieldTypes()) { |
|
463 | 463 | default: |
464 | 464 | case 'UpperCamelCase': |
465 | 465 | case TableMap::TYPE_PHPNAME: |
466 | - $columnName =$field->getPhpName(); |
|
466 | + $columnName = $field->getPhpName(); |
|
467 | 467 | break; |
468 | 468 | case 'camelCase': |
469 | 469 | case 'lowerCamelCase': |