@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $con = NOSQLParserTrait::initConnection($model, $con); |
| 27 | 27 | $collection = $con->selectCollection($model->getSchema()->name); |
| 28 | 28 | $result = $collection->findOne(['_id' => new ObjectId($pk)]); |
| 29 | - if(null !== $result) { |
|
| 29 | + if (null !== $result) { |
|
| 30 | 30 | $model->feed($result->getArrayCopy()); |
| 31 | 31 | } else { |
| 32 | 32 | throw new ApiException(t('Document not found'), 404); |
@@ -53,21 +53,21 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $resultSet->count = $collection->countDocuments($filters, $nosqlOptions); |
| 55 | 55 | |
| 56 | - $nosqlOptions["limit"] = (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)); |
|
| 57 | - $page = (integer)(array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1); |
|
| 56 | + $nosqlOptions["limit"] = (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)); |
|
| 57 | + $page = (integer) (array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1); |
|
| 58 | 58 | $nosqlOptions["skip"] = ($page === 1) ? 0 : ($page - 1) * $nosqlOptions["limit"]; |
| 59 | 59 | |
| 60 | 60 | if ((array_key_exists(Api::API_ORDER_FIELD, $criteria)) && (is_array($criteria[Api::API_ORDER_FIELD]))) { |
| 61 | 61 | $nosqlOptions["sort"] = []; |
| 62 | 62 | foreach ($criteria[Api::API_ORDER_FIELD] as $field => $direction) { |
| 63 | - $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1; |
|
| 63 | + $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1; |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $results = $collection->find($filters, $nosqlOptions); |
| 68 | 68 | /** @var $result */ |
| 69 | 69 | $items = $results->toArray(); |
| 70 | - foreach($items as $item) { |
|
| 70 | + foreach ($items as $item) { |
|
| 71 | 71 | $model->feed($item->getArrayCopy(), true); |
| 72 | 72 | $resultSet->items[] = $model->getDtoCopy(true); |
| 73 | 73 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // Check index collation |
| 97 | 97 | $options = []; |
| 98 | 98 | $indexes = $collection->listIndexes(); |
| 99 | - foreach($indexes as $index) { |
|
| 99 | + foreach ($indexes as $index) { |
|
| 100 | 100 | $indexInfo = $index->__debugInfo(); |
| 101 | 101 | if (empty(array_diff(array_keys($index["key"]), array_keys($filters)))) { |
| 102 | 102 | if (array_key_exists("collation", $indexInfo)) { |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if (array_key_exists("collation", $options)) { |
| 111 | - foreach($filters as $key=>$filter) { |
|
| 111 | + foreach ($filters as $key=>$filter) { |
|
| 112 | 112 | if (is_string($criteria[$key])) { |
| 113 | 113 | $filters[$key] = $criteria[$key]; |
| 114 | 114 | } |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | break; |
| 148 | 148 | } |
| 149 | 149 | } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) { |
| 150 | - $filterValue = (integer)$filterValue; |
|
| 150 | + $filterValue = (integer) $filterValue; |
|
| 151 | 151 | } else { |
| 152 | - $filterValue = (float)$filterValue; |
|
| 152 | + $filterValue = (float) $filterValue; |
|
| 153 | 153 | } |
| 154 | 154 | $filterValue = [ |
| 155 | 155 | '$eq' => $filterValue, |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public function __get($name) |
| 25 | 25 | { |
| 26 | 26 | $value = null; |
| 27 | - if(null !== $this->dto && property_exists($this->dto, $name)) { |
|
| 27 | + if (null !== $this->dto && property_exists($this->dto, $name)) { |
|
| 28 | 28 | $value = $this->dto->$name; |
| 29 | 29 | } |
| 30 | 30 | return $value; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __set($name, $value) |
| 38 | 38 | { |
| 39 | - if(null !== $this->dto && property_exists($this->dto, $name)) { |
|
| 39 | + if (null !== $this->dto && property_exists($this->dto, $name)) { |
|
| 40 | 40 | $this->dto->$name = $value; |
| 41 | 41 | $this->addChanges($name); |
| 42 | 42 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function __call($name, $arguments) |
| 47 | 47 | { |
| 48 | - if(preg_match('/^(set|get)/', $name)) { |
|
| 48 | + if (preg_match('/^(set|get)/', $name)) { |
|
| 49 | 49 | $property = strtolower(str_replace(['set', 'Set', 'get', 'Get'], '', $name)); |
| 50 | - if(false !== stripos($name, 'set')) { |
|
| 50 | + if (false !== stripos($name, 'set')) { |
|
| 51 | 51 | $this->dto->$property = $arguments[0]; |
| 52 | 52 | } else { |
| 53 | 53 | return $this->dto->$property; |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | public function feed(array $data, $withName = false) { |
| 65 | 65 | $name = ''; |
| 66 | 66 | $sep = ''; |
| 67 | - foreach($data as $key => $value) { |
|
| 68 | - if($value instanceof ObjectId) { |
|
| 67 | + foreach ($data as $key => $value) { |
|
| 68 | + if ($value instanceof ObjectId) { |
|
| 69 | 69 | $this->dto->setPk($value->jsonSerialize()['$oid']); |
| 70 | 70 | $name = $this->dto->getPk(); |
| 71 | - } elseif($key === '_last_update') { |
|
| 71 | + } elseif ($key === '_last_update') { |
|
| 72 | 72 | $this->dto->setLastUpdate($value instanceof UTCDateTime ? $value : null); |
| 73 | 73 | } else { |
| 74 | 74 | if (is_object($value)) { |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | $this->$key = $value; |
| 82 | - if(in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
| 82 | + if (in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
| 83 | 83 | $name .= $sep . $value; |
| 84 | 84 | $sep = ' '; |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | - if($withName) { |
|
| 88 | + if ($withName) { |
|
| 89 | 89 | $this->dto->setName($name); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -74,18 +74,18 @@ |
||
| 74 | 74 | * @throws \PSFS\base\exception\GeneratorException |
| 75 | 75 | */ |
| 76 | 76 | protected function hydrate() { |
| 77 | - if(empty($this->domain)) { |
|
| 77 | + if (empty($this->domain)) { |
|
| 78 | 78 | throw new NOSQLParserException(t('Domain not defined'), NOSQLParserException::NOSQL_PARSER_DOMAIN_NOT_DEFINED); |
| 79 | 79 | } |
| 80 | 80 | $paths = NOSQLService::getDomainPaths($this->domain); |
| 81 | 81 | $schemaFilename = $paths['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json'; |
| 82 | - if(file_exists($schemaFilename)) { |
|
| 82 | + if (file_exists($schemaFilename)) { |
|
| 83 | 83 | $schema = Cache::getInstance()->getDataFromFile($schemaFilename, Cache::JSON, true); |
| 84 | 84 | $class = get_called_class(); |
| 85 | 85 | $this->schema = new CollectionDto(false); |
| 86 | - foreach($schema as $collection) { |
|
| 86 | + foreach ($schema as $collection) { |
|
| 87 | 87 | $collectionName = $collection['name']; |
| 88 | - if(false !== strpos($class, $collectionName)) { |
|
| 88 | + if (false !== strpos($class, $collectionName)) { |
|
| 89 | 89 | $this->schema->fromArray($collection); |
| 90 | 90 | break; |
| 91 | 91 | } |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | private function extractTypes() { |
| 63 | 63 | $baseClass = new \ReflectionClass(NOSQLBase::class); |
| 64 | - if(null !== $baseClass) { |
|
| 64 | + if (null !== $baseClass) { |
|
| 65 | 65 | $types = []; |
| 66 | - foreach($baseClass->getConstants() as $constant) { |
|
| 66 | + foreach ($baseClass->getConstants() as $constant) { |
|
| 67 | 67 | $types[] = $constant; |
| 68 | 68 | } |
| 69 | 69 | $this->setTypes($types); |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | public function getDomains() { |
| 86 | 86 | $domains = []; |
| 87 | 87 | $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE); |
| 88 | - if(!empty($storedDomains)) { |
|
| 89 | - foreach($storedDomains as $domain => $data) { |
|
| 88 | + if (!empty($storedDomains)) { |
|
| 89 | + foreach ($storedDomains as $domain => $data) { |
|
| 90 | 90 | $domainLabel = str_replace(['@', '/'], '', $domain); |
| 91 | - if('ROOT' !== $domainLabel) { |
|
| 91 | + if ('ROOT' !== $domainLabel) { |
|
| 92 | 92 | $domains[] = $domainLabel; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | public static function getDomainPaths($module) { |
| 100 | 100 | $domains = Router::getInstance()->getDomains(); |
| 101 | 101 | $path = null; |
| 102 | - foreach($domains as $domain => $paths) { |
|
| 103 | - if(preg_match("/^@" . $module . "\//i", $domain)) { |
|
| 102 | + foreach ($domains as $domain => $paths) { |
|
| 103 | + if (preg_match("/^@" . $module . "\//i", $domain)) { |
|
| 104 | 104 | $path = $paths; |
| 105 | 105 | break; |
| 106 | 106 | } |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | public function getCollections($module) { |
| 116 | 116 | $collections = []; |
| 117 | 117 | $path = self::getDomainPaths($module); |
| 118 | - if(null === $path) { |
|
| 118 | + if (null === $path) { |
|
| 119 | 119 | throw new ApiException(t("Module not found"), 404); |
| 120 | 120 | } |
| 121 | 121 | $schemaFilename = $path['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json'; |
| 122 | - if(file_exists($schemaFilename)) { |
|
| 122 | + if (file_exists($schemaFilename)) { |
|
| 123 | 123 | $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE); |
| 124 | 124 | } |
| 125 | 125 | return $collections; |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'Base', |
| 143 | 143 | '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models', |
| 144 | 144 | ]; |
| 145 | - foreach($collections as $raw) { |
|
| 145 | + foreach ($collections as $raw) { |
|
| 146 | 146 | $collection = new CollectionDto(false); |
| 147 | 147 | $collection->fromArray($raw); |
| 148 | - foreach($files as $template => $path) { |
|
| 148 | + foreach ($files as $template => $path) { |
|
| 149 | 149 | GeneratorHelper::createDir($path); |
| 150 | 150 | $templateDump = $tpl->dump($template, [ |
| 151 | 151 | 'domain' => $module, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | 'properties' => $collection->properties, |
| 154 | 154 | ]); |
| 155 | 155 | $force = false; |
| 156 | - if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) { |
|
| 156 | + if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) { |
|
| 157 | 157 | $force = true; |
| 158 | 158 | } |
| 159 | 159 | $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force); |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | try { |
| 192 | 192 | $collection = $db->selectCollection($collectionDto['name']); |
| 193 | 193 | $textIndexes = []; |
| 194 | - foreach($collectionDto['properties'] as $property) { |
|
| 195 | - if(in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) { |
|
| 194 | + foreach ($collectionDto['properties'] as $property) { |
|
| 195 | + if (in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) { |
|
| 196 | 196 | $textIndexes[$property['name']] = 'text'; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | - if(count($textIndexes)) { |
|
| 199 | + if (count($textIndexes)) { |
|
| 200 | 200 | $collection->createIndex($textIndexes, ['name' => 'idx_text_' . $collectionDto['name']]); |
| 201 | 201 | } |
| 202 | 202 | } catch (\Exception $exception) { |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $db = ParserService::getInstance()->createConnection($module); |
| 214 | 214 | $collections = $this->getCollections($module); |
| 215 | 215 | $success = true; |
| 216 | - foreach($collections as $raw) { |
|
| 216 | + foreach ($collections as $raw) { |
|
| 217 | 217 | $jsonSchema = $this->parseCollection($raw); |
| 218 | 218 | try { |
| 219 | 219 | /** @var BSONDocument $result */ |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | ]); |
| 225 | 225 | $response = $result->getArrayCopy(); |
| 226 | 226 | $success = array_key_exists('ok', $response) && $response['ok'] > 0; |
| 227 | - } catch(\Exception $exception) { |
|
| 228 | - if($exception->getCode() !== 48) { |
|
| 227 | + } catch (\Exception $exception) { |
|
| 228 | + if ($exception->getCode() !== 48) { |
|
| 229 | 229 | $success = false; |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | $property = new StringPropertyDto(false); |
| 260 | 260 | break; |
| 261 | 261 | } |
| 262 | - if(array_key_exists('type', $rawProperty)) { |
|
| 262 | + if (array_key_exists('type', $rawProperty)) { |
|
| 263 | 263 | $property->bsonType = $rawProperty['type']; |
| 264 | 264 | } |
| 265 | - if(array_key_exists('description', $rawProperty)) { |
|
| 265 | + if (array_key_exists('description', $rawProperty)) { |
|
| 266 | 266 | $property->description = $rawProperty['description']; |
| 267 | 267 | } |
| 268 | 268 | if (array_key_exists('required', $rawProperty) && $rawProperty['required']) { |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | public function getValidations() { |
| 281 | 281 | $fieldTypes = new \ReflectionClass(Field::class); |
| 282 | 282 | $validations = []; |
| 283 | - foreach($fieldTypes->getConstants() as $validation) { |
|
| 283 | + foreach ($fieldTypes->getConstants() as $validation) { |
|
| 284 | 284 | $validations[] = $validation; |
| 285 | 285 | } |
| 286 | 286 | return $validations; |