@@ -5,25 +5,25 @@ discard block |
||
5 | 5 | * @version 1.0 |
6 | 6 | * Autogenerated autoloader [2019-01-03 15:23:58] |
7 | 7 | */ |
8 | -if(!defined("BASE_DIR")) |
|
9 | -define("BASE_DIR", dirname( dirname(__DIR__) ) ); |
|
8 | +if (!defined("BASE_DIR")) |
|
9 | +define("BASE_DIR", dirname(dirname(__DIR__))); |
|
10 | 10 | |
11 | 11 | require_once __DIR__ . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'config.php'; |
12 | 12 | |
13 | -if(!function_exists("NOSQL_Autoloader")) { |
|
13 | +if (!function_exists("NOSQL_Autoloader")) { |
|
14 | 14 | // autoloader |
15 | - function NOSQL_Autoloader( $class ) { |
|
15 | + function NOSQL_Autoloader($class) { |
|
16 | 16 | // it only autoload class into the Rain scope |
17 | 17 | if (false !== preg_match('/^\\\?NOSQL/', $class)) { |
18 | 18 | // Change order src |
19 | 19 | $class = preg_replace('/^\\\?NOSQL/', 'NOSQL', $class); |
20 | 20 | // transform the namespace in path |
21 | - $path = str_replace("\\", DIRECTORY_SEPARATOR, $class ); |
|
21 | + $path = str_replace("\\", DIRECTORY_SEPARATOR, $class); |
|
22 | 22 | // filepath |
23 | 23 | $abs_path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $path . ".php"; |
24 | 24 | |
25 | 25 | // require the file |
26 | - if(file_exists($abs_path)) { |
|
26 | + if (file_exists($abs_path)) { |
|
27 | 27 | require_once $abs_path; |
28 | 28 | } |
29 | 29 | } |
@@ -31,5 +31,5 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | // register the autoloader |
34 | - spl_autoload_register( "NOSQL_Autoloader" ); |
|
34 | + spl_autoload_register("NOSQL_Autoloader"); |
|
35 | 35 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $code = 200; |
58 | 58 | try { |
59 | 59 | $this->srv->setCollections($module, $this->getRequest()->getRawData()); |
60 | - } catch(\Exception $exception) { |
|
60 | + } catch (\Exception $exception) { |
|
61 | 61 | $success = false; |
62 | 62 | $code = 400; |
63 | 63 | Logger::log($exception->getMessage(), LOG_WARNING); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $code = 200; |
76 | 76 | try { |
77 | 77 | $success = $this->srv->syncCollections($module); |
78 | - } catch(\Exception $exception) { |
|
78 | + } catch (\Exception $exception) { |
|
79 | 79 | $success = false; |
80 | 80 | $code = 400; |
81 | 81 | Logger::log($exception->getMessage(), LOG_WARNING); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public static function parseForm(CollectionDto $collectionDto) { |
34 | 34 | $form = new Form(false); |
35 | 35 | $form->addField(self::generateId()); |
36 | - foreach($collectionDto->properties as $property) { |
|
36 | + foreach ($collectionDto->properties as $property) { |
|
37 | 37 | $values = null; |
38 | 38 | $data = []; |
39 | 39 | $url = null; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | case NOSQLBase::NOSQL_TYPE_ENUM: |
59 | 59 | $type = Field::COMBO_TYPE; |
60 | 60 | $enumValues = explode('|', $property->enum); |
61 | - foreach($enumValues as $value) { |
|
61 | + foreach ($enumValues as $value) { |
|
62 | 62 | $data[] = [ |
63 | 63 | $property->name => $value, |
64 | 64 | 'Label' => t($value), |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $property |
80 | 80 | */ |
81 | 81 | public function addChanges($property) { |
82 | - if(!in_array($property, $this->changes)) { |
|
82 | + if (!in_array($property, $this->changes)) { |
|
83 | 83 | $this->changes[] = $property; |
84 | 84 | } |
85 | 85 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @throws \NOSQL\Exceptions\NOSQLValidationException |
112 | 112 | */ |
113 | 113 | public static function invokeHook(NOSQLActiveRecord $model, NOSQLModelDto $dto, $hook, Database $con = null) { |
114 | - if(method_exists($model, $hook)) { |
|
114 | + if (method_exists($model, $hook)) { |
|
115 | 115 | $con = self::initConnection($model, $con); |
116 | 116 | $model->feed($dto->toArray()); |
117 | 117 | $model->$hook($con); |
@@ -56,7 +56,7 @@ |
||
56 | 56 | public function getApi() |
57 | 57 | { |
58 | 58 | $class = explode('\\', get_called_class()); |
59 | - return $class[count($class)-1]; |
|
59 | + return $class[count($class) - 1]; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -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, |
@@ -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 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function getDtoCopy($cleanPk = false) { |
46 | 46 | $copy = clone $this->dto; |
47 | - if($cleanPk) { |
|
47 | + if ($cleanPk) { |
|
48 | 48 | $this->dto->resetPk(); |
49 | 49 | } |
50 | 50 | return $copy; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function save(Database $con = null) { |
62 | 62 | $saved = false; |
63 | - if(null === $con) { |
|
63 | + if (null === $con) { |
|
64 | 64 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
65 | 65 | } |
66 | 66 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $isInsert = $isUpdate = false; |
69 | 69 | $this->prepareData(); |
70 | 70 | $this->dto->setLastUpdate(); |
71 | - if($this->isNew()) { |
|
71 | + if ($this->isNew()) { |
|
72 | 72 | $this->preInsert($con); |
73 | 73 | $isInsert = true; |
74 | 74 | } elseif ($this->isModified()) { |
@@ -76,19 +76,19 @@ discard block |
||
76 | 76 | $isUpdate = true; |
77 | 77 | } |
78 | 78 | $result = $collection->insertOne($this->toArray()); |
79 | - if($result->getInsertedCount() > 0) { |
|
79 | + if ($result->getInsertedCount() > 0) { |
|
80 | 80 | $id = $result->getInsertedId(); |
81 | 81 | $this->dto->setPk($id->jsonSerialize()['$oid']); |
82 | - if($isInsert) { |
|
82 | + if ($isInsert) { |
|
83 | 83 | $this->postInsert($con); |
84 | - } elseif($isUpdate) { |
|
84 | + } elseif ($isUpdate) { |
|
85 | 85 | $this->postUpdate($con); |
86 | 86 | } |
87 | 87 | $saved = true; |
88 | 88 | $this->countAction(); |
89 | 89 | } |
90 | - } catch(\Exception $exception) { |
|
91 | - if($exception instanceof NOSQLValidationException) { |
|
90 | + } catch (\Exception $exception) { |
|
91 | + if ($exception instanceof NOSQLValidationException) { |
|
92 | 92 | throw $exception; |
93 | 93 | } else { |
94 | 94 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function update(Database $con = null) { |
105 | 105 | $updated = false; |
106 | - if(null === $con) { |
|
106 | + if (null === $con) { |
|
107 | 107 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
108 | 108 | } |
109 | 109 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | $this->postUpdate($con); |
118 | 118 | $updated = true; |
119 | 119 | $this->countAction(); |
120 | - } catch(\Exception $exception) { |
|
121 | - if($exception instanceof NOSQLValidationException) { |
|
120 | + } catch (\Exception $exception) { |
|
121 | + if ($exception instanceof NOSQLValidationException) { |
|
122 | 122 | throw $exception; |
123 | 123 | } else { |
124 | 124 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function bulkInsert(array $data, Database $con = null) { |
136 | 136 | $inserts = 0; |
137 | - if(null === $con) { |
|
137 | + if (null === $con) { |
|
138 | 138 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
139 | 139 | } |
140 | 140 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $ids = $result->getInsertedIds(); |
145 | 145 | $inserts = $this->parseInsertedDtos($con, $ids, $dtos); |
146 | 146 | $this->setActionCount($inserts); |
147 | - } catch(\Exception $exception) { |
|
147 | + } catch (\Exception $exception) { |
|
148 | 148 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
149 | 149 | } |
150 | 150 | return $inserts; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return int |
159 | 159 | */ |
160 | 160 | public function bulkUpsert(array $data, $id, Database $con = null) { |
161 | - if(null === $con) { |
|
161 | + if (null === $con) { |
|
162 | 162 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
163 | 163 | } |
164 | 164 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | try { |
169 | 169 | // Check index collation |
170 | 170 | $indexes = $collection->listIndexes(); |
171 | - foreach($indexes as $index) { |
|
171 | + foreach ($indexes as $index) { |
|
172 | 172 | $indexInfo = $index->__debugInfo(); |
173 | 173 | $keys = array_keys($index["key"]); |
174 | 174 | if ((count($keys) === 1) && ($keys[0] === $id) && (array_key_exists("collation", $indexInfo))) { |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - foreach($data as $item) { |
|
181 | + foreach ($data as $item) { |
|
182 | 182 | $filter[$id] = ['$eq' => $item[$id]]; |
183 | 183 | $update = []; |
184 | 184 | $update['$set'] = $item; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function delete(Database $con = null) { |
206 | 206 | $deleted = false; |
207 | - if(null === $con) { |
|
207 | + if (null === $con) { |
|
208 | 208 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
209 | 209 | } |
210 | 210 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $deleted = true; |
216 | 216 | $this->dto = null; |
217 | 217 | $this->countAction(); |
218 | - } catch(\Exception $exception) { |
|
218 | + } catch (\Exception $exception) { |
|
219 | 219 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
220 | 220 | } |
221 | 221 | return $deleted; |
@@ -229,14 +229,14 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function bulkDelete(array $filters, Database $con = null) { |
231 | 231 | $deletedCount = 0; |
232 | - if(null === $con) { |
|
232 | + if (null === $con) { |
|
233 | 233 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
234 | 234 | } |
235 | 235 | $collection = $con->selectCollection($this->getSchema()->name); |
236 | 236 | try { |
237 | 237 | $result = $collection->deleteMany($filters); |
238 | 238 | $deletedCount = $result->getDeletedCount(); |
239 | - } catch(\Exception $exception) { |
|
239 | + } catch (\Exception $exception) { |
|
240 | 240 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
241 | 241 | } |
242 | 242 | return $deletedCount; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $dtos = []; |
254 | 254 | /** @var NOSQLModelDto $dto */ |
255 | 255 | foreach ($data as &$insertData) { |
256 | - if(is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
256 | + if (is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
257 | 257 | $dto = clone $insertData; |
258 | 258 | } else { |
259 | 259 | $dto = $this->getDtoCopy(true); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | foreach ($ids as $index => $insertedId) { |
284 | 284 | $id = is_string($insertedId) ? ['$oid' => $insertedId] : $insertedId->jsonSerialize(); |
285 | 285 | $dto = $dtos[$index]; |
286 | - if($dto instanceof NOSQLModelDto) { |
|
286 | + if ($dto instanceof NOSQLModelDto) { |
|
287 | 287 | $dto->setPk($id['$oid']); |
288 | 288 | } else { |
289 | 289 |
@@ -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); |