@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | include_once __DIR__ . '/vendor/autoload.php'; |
3 | -if (!is_file(__DIR__. '/clusterpoint.php')) { |
|
4 | - copy(__DIR__. '/clusterpoint-example.php', __DIR__. '/clusterpoint.php'); |
|
3 | +if (!is_file(__DIR__ . '/clusterpoint.php')) { |
|
4 | + copy(__DIR__ . '/clusterpoint-example.php', __DIR__ . '/clusterpoint.php'); |
|
5 | 5 | } |
6 | -if (is_file(__DIR__. '/.env')) { |
|
6 | +if (is_file(__DIR__ . '/.env')) { |
|
7 | 7 | $dotenv = new Dotenv\Dotenv(__DIR__); |
8 | 8 | $dotenv->load(); |
9 | 9 | } |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use Aws\DynamoDb\Marshaler; |
7 | 7 | use Fathomminds\Rest\Exceptions\RestException; |
8 | 8 | use Fathomminds\Rest\Contracts\IResource; |
9 | -use Fathomminds\Rest\Helpers\Uuid; |
|
10 | 9 | use Aws\DynamoDb\Exception\DynamoDbException; |
11 | 10 | |
12 | 11 | class Resource implements IResource |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | throw new RestException($ex->getMessage(), ['exception' => $ex]); |
133 | 133 | } catch (\Exception $ex) { |
134 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
134 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $res = $this->client->deleteItem($query); |
154 | 154 | return $resourceId; |
155 | 155 | } catch (\Exception $ex) { |
156 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
156 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 |
@@ -83,6 +83,9 @@ |
||
83 | 83 | $this->resource = new \StdClass(); |
84 | 84 | } |
85 | 85 | |
86 | + /** |
|
87 | + * @param boolean $value |
|
88 | + */ |
|
86 | 89 | protected function setUpdateMode($value) |
87 | 90 | { |
88 | 91 | $this->updateMode = $value; |
@@ -3,7 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use Fathomminds\Rest\Helpers\ReflectionHelper; |
5 | 5 | use Fathomminds\Rest\Contracts\IRestObject; |
6 | -use Fathomminds\Rest\Database\Clusterpoint\Database; |
|
7 | 6 | |
8 | 7 | abstract class RestObject implements IRestObject |
9 | 8 | { |
@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | if ((int)$res->hits() > 0) { |
27 | 27 | $results = json_decode($res->rawResponse())->results; |
28 | 28 | $message = $results[0]->{$this->primaryKey} === $this->getPrimaryKeyValue() ? |
29 | - 'Primary key collision' : |
|
30 | - 'Unique constraint violation'; |
|
29 | + 'Primary key collision' : 'Unique constraint violation'; |
|
31 | 30 | throw new RestException( |
32 | 31 | $message, |
33 | 32 | ['resourceName' => $this->resourceName, 'confilct' => $results[0]] |
@@ -38,7 +37,7 @@ discard block |
||
38 | 37 | private function getUniqueFieldQuery($query, $uniqueFields) |
39 | 38 | { |
40 | 39 | // @codeCoverageIgnoreStart |
41 | - $query->where(function ($query) use ($uniqueFields) { |
|
40 | + $query->where(function($query) use ($uniqueFields) { |
|
42 | 41 | foreach ($uniqueFields as $fieldName) { |
43 | 42 | if (property_exists($this->resource, $fieldName)) { |
44 | 43 | $query->orWhere($fieldName, '==', $this->resource->{$fieldName}); |
@@ -52,11 +52,10 @@ discard block |
||
52 | 52 | $this->failOnError($res); |
53 | 53 | $object = $this->toObject($res); |
54 | 54 | $newResource->{$this->primaryKey} = empty($object->{$this->primaryKey}) ? |
55 | - null : |
|
56 | - $object->{$this->primaryKey}; |
|
55 | + null : $object->{$this->primaryKey}; |
|
57 | 56 | return $newResource; |
58 | 57 | } catch (\Exception $ex) { |
59 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
58 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]); |
|
60 | 59 | } |
61 | 60 | } |
62 | 61 | |
@@ -67,7 +66,7 @@ discard block |
||
67 | 66 | $this->failOnError($res); |
68 | 67 | return $this->toObject($res); |
69 | 68 | } catch (\Exception $ex) { |
70 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
69 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]); |
|
71 | 70 | } |
72 | 71 | } |
73 | 72 | |
@@ -78,7 +77,7 @@ discard block |
||
78 | 77 | $this->failOnError($res); |
79 | 78 | return $this->toObject($res); |
80 | 79 | } catch (\Exception $ex) { |
81 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
80 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]); |
|
82 | 81 | } |
83 | 82 | } |
84 | 83 | |
@@ -88,8 +87,7 @@ discard block |
||
88 | 87 | return; |
89 | 88 | } |
90 | 89 | $message = $res->error()[0]->message === 'Requested document does not exist' ? |
91 | - 'Resource does not exist' : |
|
92 | - 'Database operation failed'; |
|
90 | + 'Resource does not exist' : 'Database operation failed'; |
|
93 | 91 | throw new RestException( |
94 | 92 | $message, |
95 | 93 | [ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $uniqueAndSetAndIndexed = array_intersect($uniqueAndSet, $indexes); //Is unique and value is set and is indexed |
34 | 34 | sort($uniqueAndSet); |
35 | 35 | sort($uniqueAndSetAndIndexed); |
36 | - return $uniqueAndSet===$uniqueAndSetAndIndexed; |
|
36 | + return $uniqueAndSet === $uniqueAndSetAndIndexed; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | protected function scanUniqueFields($fields) |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $filter = $this->generateScanFilter($fields); |
60 | 60 | if (property_exists($this->resource, $this->primaryKey)) { |
61 | 61 | $marshaler = new Marshaler; |
62 | - $filter['FilterExpression'] = '('.$filter['FilterExpression'].') AND #pk<>:pk'; |
|
62 | + $filter['FilterExpression'] = '(' . $filter['FilterExpression'] . ') AND #pk<>:pk'; |
|
63 | 63 | $filter['ExpressionAttributeNames']['#pk'] = $this->primaryKey; |
64 | 64 | $filter['ExpressionAttributeValues'][':pk'] = $marshaler->marshalValue( |
65 | 65 | $this->resource->{$this->primaryKey} |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | ]; |
84 | 84 | foreach ($fields as $field) { |
85 | 85 | if (property_exists($this->resource, $field)) { |
86 | - $ret['FilterExpression'] .= '#'.$field.'=:'.$field.' OR '; |
|
87 | - $ret['ExpressionAttributeNames']['#'.$field] = $field; |
|
88 | - $ret['ExpressionAttributeValues'][':'.$field] = $marshaler->marshalValue( |
|
86 | + $ret['FilterExpression'] .= '#' . $field . '=:' . $field . ' OR '; |
|
87 | + $ret['ExpressionAttributeNames']['#' . $field] = $field; |
|
88 | + $ret['ExpressionAttributeValues'][':' . $field] = $marshaler->marshalValue( |
|
89 | 89 | $this->resource->{$field} |
90 | 90 | ); |
91 | 91 | } |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | $marshaler = new Marshaler; |
125 | 125 | $query = [ |
126 | 126 | 'TableName' => $this->database->getDatabaseName() . '-' . $this->resourceName, |
127 | - 'KeyConditionExpression' => '#'.$field.'=:'.$field, |
|
127 | + 'KeyConditionExpression' => '#' . $field . '=:' . $field, |
|
128 | 128 | 'IndexName' => $this->indexNames[$field], |
129 | - 'ExpressionAttributeNames' => ['#'.$field => $field], |
|
130 | - 'ExpressionAttributeValues' => [':'.$field => $marshaler->marshalValue( |
|
129 | + 'ExpressionAttributeNames' => ['#' . $field => $field], |
|
130 | + 'ExpressionAttributeValues' => [':' . $field => $marshaler->marshalValue( |
|
131 | 131 | $this->resource->{$field} |
132 | 132 | )], |
133 | 133 | ]; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $promises = []; |
148 | 148 | foreach ($queries as $query) { |
149 | 149 | $promise = new Promise( |
150 | - function () use (&$promise, $client, $query) { |
|
150 | + function() use (&$promise, $client, $query) { |
|
151 | 151 | $q = new Query($client, $query); |
152 | 152 | while ($res = $q->next()) { |
153 | 153 | if ($res['Count'] !== 0) { |
@@ -41,7 +41,7 @@ |
||
41 | 41 | |
42 | 42 | public function __construct() |
43 | 43 | { |
44 | - $this->setDefault('_id', function () { |
|
44 | + $this->setDefault('_id', function() { |
|
45 | 45 | return (new Uuid)->generate(); |
46 | 46 | }); |
47 | 47 | } |