@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $dns .= '@' . Config::getParam('nosql.host', 'localhost', $lowerDomain); |
28 | 28 | |
29 | 29 | $database = Config::getParam('nosql.database', 'nosql', $lowerDomain); |
30 | - if(null !== Config::getParam('nosql.replicaset')) { |
|
30 | + if (null !== Config::getParam('nosql.replicaset')) { |
|
31 | 31 | $dns .= '/' . $database . '?ssl=true&replicaSet=' . Config::getParam('nosql.replicaset', null, $lowerDomain); |
32 | 32 | $dns .= '&authSource=admin&serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000'; |
33 | 33 | } else { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function checkAndSave($domain, $collection, NOSQLModelDto $dto) { |
51 | 51 | $errors = $dto->validate(); |
52 | - if(empty($errors)) { |
|
52 | + if (empty($errors)) { |
|
53 | 53 | |
54 | 54 | } else { |
55 | 55 | throw new ApiException(t('Dto not valid'), 400); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function hydrateModelFromRequest(array $data, $className) { |
67 | 67 | $model = null; |
68 | 68 | $reflectionClass = new \ReflectionClass($className); |
69 | - if($reflectionClass->isSubclassOf(NOSQLBase::class)) { |
|
69 | + if ($reflectionClass->isSubclassOf(NOSQLBase::class)) { |
|
70 | 70 | /** @var NOSQLActiveRecord $modelName */ |
71 | 71 | $modelName = $className::MODEL_CLASS; |
72 | 72 | $model = $modelName::fromArray($data); |
@@ -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, |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | 'indexes' => $collection->indexes, |
155 | 155 | ]); |
156 | 156 | $force = false; |
157 | - if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) { |
|
157 | + if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) { |
|
158 | 158 | $force = true; |
159 | 159 | } |
160 | 160 | $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force); |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | private function createTextIndex(Database $db, $collectionDto) { |
192 | 192 | try { |
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 = $db->selectCollection($collectionDto['name']); |
201 | 201 | $collection->createIndex($textIndexes, ['name' => 'idx_text_' . $collectionDto['name']]); |
202 | 202 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | private function createIndexes(Database $db, $collectionDto, array $indexes = []) { |
215 | 215 | try { |
216 | 216 | $collection = $db->selectCollection($collectionDto['name']); |
217 | - if(count($indexes)) { |
|
217 | + if (count($indexes)) { |
|
218 | 218 | $collection->createIndexes($indexes); |
219 | 219 | } |
220 | 220 | } catch (\Exception $exception) { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $db = ParserService::getInstance()->createConnection($module); |
232 | 232 | $collections = $this->getCollections($module); |
233 | 233 | $success = true; |
234 | - foreach($collections as $raw) { |
|
234 | + foreach ($collections as $raw) { |
|
235 | 235 | $jsonSchema = $this->parseCollection($raw); |
236 | 236 | try { |
237 | 237 | /** @var BSONDocument $result */ |
@@ -242,21 +242,21 @@ discard block |
||
242 | 242 | ]); |
243 | 243 | $response = $result->getArrayCopy(); |
244 | 244 | $success = array_key_exists('ok', $response) && $response['ok'] > 0; |
245 | - } catch(\Exception $exception) { |
|
246 | - if($exception->getCode() !== 48) { |
|
245 | + } catch (\Exception $exception) { |
|
246 | + if ($exception->getCode() !== 48) { |
|
247 | 247 | $success = false; |
248 | 248 | } |
249 | 249 | } |
250 | - if($success) { |
|
250 | + if ($success) { |
|
251 | 251 | if (Config::getParam("nosql.sync.defaultIndex", false, $module)) { |
252 | 252 | $this->createTextIndex($db, $raw); |
253 | 253 | } |
254 | 254 | $indexToCreate = []; |
255 | - foreach($raw['indexes'] as $index) { |
|
255 | + foreach ($raw['indexes'] as $index) { |
|
256 | 256 | $dbIndex = []; |
257 | - foreach($index['properties'] as $idx) { |
|
257 | + foreach ($index['properties'] as $idx) { |
|
258 | 258 | list($property, $direction) = explode('.', $idx); |
259 | - switch(strtoupper($direction)) { |
|
259 | + switch (strtoupper($direction)) { |
|
260 | 260 | case 'ASC': $dbIndex[$property] = 1; break; |
261 | 261 | case 'DESC': $dbIndex[$property] = -1; break; |
262 | 262 | } |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | $property = new StringPropertyDto(false); |
298 | 298 | break; |
299 | 299 | } |
300 | - if(array_key_exists('type', $rawProperty)) { |
|
300 | + if (array_key_exists('type', $rawProperty)) { |
|
301 | 301 | $property->bsonType = $rawProperty['type']; |
302 | 302 | } |
303 | - if(array_key_exists('description', $rawProperty)) { |
|
303 | + if (array_key_exists('description', $rawProperty)) { |
|
304 | 304 | $property->description = $rawProperty['description']; |
305 | 305 | } |
306 | 306 | if (array_key_exists('required', $rawProperty) && $rawProperty['required']) { |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function getValidations() { |
319 | 319 | $fieldTypes = new \ReflectionClass(Field::class); |
320 | 320 | $validations = []; |
321 | - foreach($fieldTypes->getConstants() as $validation) { |
|
321 | + foreach ($fieldTypes->getConstants() as $validation) { |
|
322 | 322 | $validations[] = $validation; |
323 | 323 | } |
324 | 324 | return $validations; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function setPk(string $id) |
53 | 53 | { |
54 | - if(!empty($this->_id)) { |
|
54 | + if (!empty($this->_id)) { |
|
55 | 55 | throw new NOSQLValidationException(t('Primary key already defined'), NOSQLValidationException::NOSQL_VALIDATION_ID_ALREADY_DEFINED); |
56 | 56 | } |
57 | 57 | $this->_id = $id; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | public function getLastUpdate($format = null) |
65 | 65 | { |
66 | 66 | $value = $this->_last_update; |
67 | - if(null !== $format) { |
|
67 | + if (null !== $format) { |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | return $value; |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | public function validate($throwException = false) { |
105 | 105 | $errors = []; |
106 | 106 | $reflection = new \ReflectionClass(get_called_class()); |
107 | - foreach($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { |
|
107 | + foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { |
|
108 | 108 | $required = InjectorHelper::checkIsRequired($property->getDocComment()); |
109 | 109 | $value = $property->getValue($this); |
110 | - if($required && $this->checkEmpty($value)) { |
|
111 | - if($throwException) { |
|
110 | + if ($required && $this->checkEmpty($value)) { |
|
111 | + if ($throwException) { |
|
112 | 112 | throw new NOSQLValidationException(t('Empty value for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_REQUIRED); |
113 | 113 | } else { |
114 | 114 | $errors[] = $property->getName(); |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | public function toArray() |
128 | 128 | { |
129 | 129 | $array = parent::toArray(); |
130 | - if(null !== $this->getPk()) { |
|
130 | + if (null !== $this->getPk()) { |
|
131 | 131 | $array['_id'] = $this->getPk(); |
132 | 132 | } |
133 | - if(null !== $this->getName()) { |
|
133 | + if (null !== $this->getName()) { |
|
134 | 134 | $array[Api::API_LIST_NAME_FIELD] = $this->getName(); |
135 | 135 | } |
136 | 136 | $array['_last_update'] = $this->getLastUpdate(\DateTime::ATOM); |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | if (!is_numeric($value)) { |
155 | 155 | $errors[] = $property->getName(); |
156 | 156 | } else { |
157 | - if(NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) { |
|
158 | - $property->setValue($this, (integer)$value); |
|
157 | + if (NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) { |
|
158 | + $property->setValue($this, (integer) $value); |
|
159 | 159 | } else { |
160 | - $property->setValue($this, (float)$value); |
|
160 | + $property->setValue($this, (float) $value); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | break; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | if (!in_array($value, [true, false, 0, 1])) { |
180 | 180 | $errors[] = $property->getName(); |
181 | 181 | } |
182 | - $property->setValue($this, (bool)$value); |
|
182 | + $property->setValue($this, (bool) $value); |
|
183 | 183 | break; |
184 | 184 | case NOSQLBase::NOSQL_TYPE_DATE: |
185 | 185 | case NOSQLBase::NOSQL_TYPE_TIMESTAMP: |
186 | 186 | $dateTime = new \DateTime($value, new \DateTimeZone('UTC')); |
187 | - if(!$dateTime) { |
|
187 | + if (!$dateTime) { |
|
188 | 188 | $errors[] = $property->getName(); |
189 | 189 | } else { |
190 | 190 | $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
191 | - $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000)); |
|
191 | + $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000)); |
|
192 | 192 | } |
193 | 193 | break; |
194 | 194 | } |
@@ -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 = lcfirst(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 | } |