@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | $dns .= '@' . Config::getParam('nosql.host', 'localhost', $lowerDomain); |
| 29 | 29 | |
| 30 | 30 | $database = Config::getParam('nosql.database', 'nosql', $lowerDomain); |
| 31 | - if(null !== Config::getParam('nosql.replicaset')) { |
|
| 31 | + if (null !== Config::getParam('nosql.replicaset')) { |
|
| 32 | 32 | $dns .= '/' . $database . '?ssl=true&replicaSet=' . Config::getParam('nosql.replicaset', null, $lowerDomain); |
| 33 | 33 | $dns .= '&authSource=admin&serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000'; |
| 34 | 34 | } else { |
| 35 | - if(strtolower($protocol) !== 'mongodb+srv') { |
|
| 35 | + if (strtolower($protocol) !== 'mongodb+srv') { |
|
| 36 | 36 | $dns .= ':' . Config::getParam('nosql.port', '27017', $lowerDomain); |
| 37 | 37 | } |
| 38 | 38 | $dns .= '/' . $database . "?authSource=admin"; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function checkAndSave($domain, $collection, NOSQLModelDto $dto) { |
| 54 | 54 | $errors = $dto->validate(); |
| 55 | - if(empty($errors)) { |
|
| 55 | + if (empty($errors)) { |
|
| 56 | 56 | |
| 57 | 57 | } else { |
| 58 | 58 | throw new ApiException(t('Dto not valid'), 400); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function hydrateModelFromRequest(array $data, $className) { |
| 70 | 70 | $model = null; |
| 71 | 71 | $reflectionClass = new \ReflectionClass($className); |
| 72 | - if($reflectionClass->isSubclassOf(NOSQLBase::class)) { |
|
| 72 | + if ($reflectionClass->isSubclassOf(NOSQLBase::class)) { |
|
| 73 | 73 | /** @var NOSQLActiveRecord $modelName */ |
| 74 | 74 | $modelName = $className::MODEL_CLASS; |
| 75 | 75 | $model = $modelName::fromArray($data); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $con = NOSQLParserTrait::initConnection($model, $con); |
| 29 | 29 | $collection = $con->selectCollection($model->getSchema()->name); |
| 30 | 30 | $result = $collection->findOne(['_id' => new ObjectId($pk)]); |
| 31 | - if(null !== $result) { |
|
| 31 | + if (null !== $result) { |
|
| 32 | 32 | $model->feed($result->getArrayCopy()); |
| 33 | 33 | } else { |
| 34 | 34 | throw new ApiException(t('Document not found'), 404); |
@@ -55,21 +55,21 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $resultSet->count = $collection->countDocuments($filters, $nosqlOptions); |
| 57 | 57 | |
| 58 | - $nosqlOptions["limit"] = (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)); |
|
| 59 | - $page = (integer)(array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1); |
|
| 58 | + $nosqlOptions["limit"] = (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)); |
|
| 59 | + $page = (integer) (array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1); |
|
| 60 | 60 | $nosqlOptions["skip"] = ($page === 1) ? 0 : ($page - 1) * $nosqlOptions["limit"]; |
| 61 | 61 | |
| 62 | 62 | if ((array_key_exists(Api::API_ORDER_FIELD, $criteria)) && (is_array($criteria[Api::API_ORDER_FIELD]))) { |
| 63 | 63 | $nosqlOptions["sort"] = []; |
| 64 | 64 | foreach ($criteria[Api::API_ORDER_FIELD] as $field => $direction) { |
| 65 | - $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1; |
|
| 65 | + $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1; |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $results = $collection->find($filters, $nosqlOptions); |
| 70 | 70 | /** @var $result */ |
| 71 | 71 | $items = $results->toArray(); |
| 72 | - foreach($items as $item) { |
|
| 72 | + foreach ($items as $item) { |
|
| 73 | 73 | $model->feed($item->getArrayCopy(), true); |
| 74 | 74 | $resultSet->items[] = $model->getDtoCopy(true); |
| 75 | 75 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | // Check index collation |
| 99 | 99 | $options = []; |
| 100 | 100 | $indexes = $collection->listIndexes(); |
| 101 | - foreach($indexes as $index) { |
|
| 101 | + foreach ($indexes as $index) { |
|
| 102 | 102 | $indexInfo = $index->__debugInfo(); |
| 103 | 103 | if (empty(array_diff(array_keys($index["key"]), array_keys($filters)))) { |
| 104 | 104 | if (array_key_exists("collation", $indexInfo)) { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | if (array_key_exists("collation", $options)) { |
| 113 | - foreach($filters as $key=>$filter) { |
|
| 113 | + foreach ($filters as $key=>$filter) { |
|
| 114 | 114 | if (is_string($criteria[$key])) { |
| 115 | 115 | $filters[$key] = $criteria[$key]; |
| 116 | 116 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $filterValue = $criteria[$property->name]; |
| 130 | 130 | $matchOperator = is_array($filterValue) ? $filterValue[0] : self::NOSQL_EQUAL_OPERATOR; |
| 131 | 131 | if (is_array($filterValue)) { |
| 132 | - if(in_array($matchOperator, [ |
|
| 132 | + if (in_array($matchOperator, [ |
|
| 133 | 133 | self::NOSQL_NOT_NULL_OPERATOR, |
| 134 | 134 | self::NOSQL_IN_OPERATOR, |
| 135 | 135 | ], true)) { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | self::NOSQL_IN_OPERATOR => $filterValue, |
| 145 | 145 | ]; |
| 146 | 146 | } |
| 147 | - } elseif(in_array($filterValue, [ |
|
| 147 | + } elseif (in_array($filterValue, [ |
|
| 148 | 148 | self::NOSQL_NOT_NULL_OPERATOR, |
| 149 | 149 | ], true)) { |
| 150 | 150 | $filterValue = [ |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | break; |
| 169 | 169 | } |
| 170 | 170 | } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) { |
| 171 | - $filterValue = (integer)$filterValue; |
|
| 171 | + $filterValue = (integer) $filterValue; |
|
| 172 | 172 | } else { |
| 173 | - $filterValue = (float)$filterValue; |
|
| 173 | + $filterValue = (float) $filterValue; |
|
| 174 | 174 | } |
| 175 | 175 | $filterValue = [ |
| 176 | 176 | self::NOSQL_EQUAL_OPERATOR => $filterValue, |