@@ -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 | } |
@@ -5,8 +5,9 @@ |
||
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 | 12 | require_once __DIR__ . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'config.php'; |
12 | 13 |
@@ -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); |
@@ -14,14 +14,14 @@ |
||
14 | 14 | const DOMAIN = 'NOSQL'; |
15 | 15 | |
16 | 16 | /** |
17 | - * @Autoload |
|
18 | - * @var \NOSQL\Services\NOSQLService |
|
19 | - */ |
|
17 | + * @Autoload |
|
18 | + * @var \NOSQL\Services\NOSQLService |
|
19 | + */ |
|
20 | 20 | protected $srv; |
21 | 21 | |
22 | 22 | /** |
23 | - * Constructor por defecto |
|
24 | - */ |
|
23 | + * Constructor por defecto |
|
24 | + */ |
|
25 | 25 | function __construct() { |
26 | 26 | $this->init(); |
27 | 27 | $this->setDomain('NOSQL') |
@@ -14,14 +14,14 @@ |
||
14 | 14 | class NOSQLController extends NOSQLBaseController { |
15 | 15 | |
16 | 16 | /** |
17 | - * Index |
|
18 | - * @GET |
|
19 | - * @label Admin nosql composer |
|
20 | - * @action true |
|
21 | - * @visible true |
|
22 | - * @route /admin/nosql |
|
23 | - * @return string HTML |
|
24 | - */ |
|
17 | + * Index |
|
18 | + * @GET |
|
19 | + * @label Admin nosql composer |
|
20 | + * @action true |
|
21 | + * @visible true |
|
22 | + * @route /admin/nosql |
|
23 | + * @return string HTML |
|
24 | + */ |
|
25 | 25 | public function index() { |
26 | 26 | return $this->render('index.html.twig'); |
27 | 27 | } |
@@ -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 | /** |
@@ -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 && empty($value)) { |
|
111 | - if($throwException) { |
|
110 | + if ($required && empty($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(); |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | public function toArray() |
124 | 124 | { |
125 | 125 | $array = parent::toArray(); |
126 | - if(null !== $this->getPk()) { |
|
126 | + if (null !== $this->getPk()) { |
|
127 | 127 | $array['_id'] = $this->getPk(); |
128 | 128 | } |
129 | - if(null !== $this->getName()) { |
|
129 | + if (null !== $this->getName()) { |
|
130 | 130 | $array[Api::API_LIST_NAME_FIELD] = $this->getName(); |
131 | 131 | } |
132 | 132 | $array['_last_update'] = $this->getLastUpdate(\DateTime::ATOM); |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | if (!is_numeric($value)) { |
151 | 151 | $errors[] = $property->getName(); |
152 | 152 | } else { |
153 | - if(NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) { |
|
154 | - $property->setValue($this, (integer)$value); |
|
153 | + if (NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) { |
|
154 | + $property->setValue($this, (integer) $value); |
|
155 | 155 | } else { |
156 | - $property->setValue($this, (float)$value); |
|
156 | + $property->setValue($this, (float) $value); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | break; |
@@ -175,16 +175,16 @@ discard block |
||
175 | 175 | if (!in_array($value, [true, false, 0, 1])) { |
176 | 176 | $errors[] = $property->getName(); |
177 | 177 | } |
178 | - $property->setValue($this, (bool)$value); |
|
178 | + $property->setValue($this, (bool) $value); |
|
179 | 179 | break; |
180 | 180 | case NOSQLBase::NOSQL_TYPE_DATE: |
181 | 181 | case NOSQLBase::NOSQL_TYPE_TIMESTAMP: |
182 | 182 | $dateTime = new \DateTime($value, new \DateTimeZone('UTC')); |
183 | - if(!$dateTime) { |
|
183 | + if (!$dateTime) { |
|
184 | 184 | $errors[] = $property->getName(); |
185 | 185 | } else { |
186 | 186 | $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
187 | - $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000)); |
|
187 | + $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000)); |
|
188 | 188 | } |
189 | 189 | break; |
190 | 190 | } |
@@ -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, |