@@ -9,7 +9,7 @@ |
||
9 | 9 | |
10 | 10 | public function boot() |
11 | 11 | { |
12 | - $configPath = __DIR__ . '/../../config/laravel-model-caching.php'; |
|
12 | + $configPath = __DIR__.'/../../config/laravel-model-caching.php'; |
|
13 | 13 | $this->mergeConfigFrom($configPath, 'laravel-model-caching'); |
14 | 14 | $this->commands(Flush::class); |
15 | 15 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public function avg($column) |
14 | 14 | { |
15 | - if (! $this->isCachable()) { |
|
15 | + if (!$this->isCachable()) { |
|
16 | 16 | return parent::avg($column); |
17 | 17 | } |
18 | 18 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | public function count($columns = ["*"]) |
25 | 25 | { |
26 | - if (! $this->isCachable()) { |
|
26 | + if (!$this->isCachable()) { |
|
27 | 27 | return parent::count($columns); |
28 | 28 | } |
29 | 29 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function find($id, $columns = ["*"]) |
47 | 47 | { |
48 | - if (! $this->isCachable()) { |
|
48 | + if (!$this->isCachable()) { |
|
49 | 49 | return parent::find($id, $columns); |
50 | 50 | } |
51 | 51 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | public function first($columns = ["*"]) |
58 | 58 | { |
59 | - if (! $this->isCachable()) { |
|
59 | + if (!$this->isCachable()) { |
|
60 | 60 | return parent::first($columns); |
61 | 61 | } |
62 | 62 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | public function get($columns = ["*"]) |
69 | 69 | { |
70 | - if (! $this->isCachable()) { |
|
70 | + if (!$this->isCachable()) { |
|
71 | 71 | return parent::get($columns); |
72 | 72 | } |
73 | 73 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | public function max($column) |
80 | 80 | { |
81 | - if (! $this->isCachable()) { |
|
81 | + if (!$this->isCachable()) { |
|
82 | 82 | return parent::max($column); |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | public function min($column) |
91 | 91 | { |
92 | - if (! $this->isCachable()) { |
|
92 | + if (!$this->isCachable()) { |
|
93 | 93 | return parent::min($column); |
94 | 94 | } |
95 | 95 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $pageName = "page", |
105 | 105 | $page = null |
106 | 106 | ) { |
107 | - if (! $this->isCachable()) { |
|
107 | + if (!$this->isCachable()) { |
|
108 | 108 | return parent::paginate($perPage, $columns, $pageName, $page); |
109 | 109 | } |
110 | 110 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | public function pluck($column, $key = null) |
118 | 118 | { |
119 | - if (! $this->isCachable()) { |
|
119 | + if (!$this->isCachable()) { |
|
120 | 120 | return parent::pluck($column, $key); |
121 | 121 | } |
122 | 122 | |
123 | - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); |
|
123 | + $keyDifferentiator = "-pluck_{$column}".($key ? "_{$key}" : ""); |
|
124 | 124 | $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); |
125 | 125 | |
126 | 126 | return $this->cachedValue(func_get_args(), $cacheKey); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | public function sum($column) |
130 | 130 | { |
131 | - if (! $this->isCachable()) { |
|
131 | + if (!$this->isCachable()) { |
|
132 | 132 | return parent::sum($column); |
133 | 133 | } |
134 | 134 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | public function value($column) |
141 | 141 | { |
142 | - if (! $this->isCachable()) { |
|
142 | + if (!$this->isCachable()) { |
|
143 | 143 | return parent::value($column); |
144 | 144 | } |
145 | 145 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | return $this->cache($cacheTags) |
209 | 209 | ->rememberForever( |
210 | 210 | $hashedCacheKey, |
211 | - function () use ($arguments, $cacheKey, $method) { |
|
211 | + function() use ($arguments, $cacheKey, $method) { |
|
212 | 212 | return [ |
213 | 213 | "key" => $cacheKey, |
214 | 214 | "value" => parent::{$method}(...$arguments), |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | { |
13 | 13 | $option = $this->option('model'); |
14 | 14 | |
15 | - if (! $option) { |
|
15 | + if (!$option) { |
|
16 | 16 | return $this->flushEntireCache(); |
17 | 17 | } |
18 | 18 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $usesCachableTrait = $this->getAllTraitsUsedByClass($option) |
37 | 37 | ->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable"); |
38 | 38 | |
39 | - if (! $usesCachableTrait) { |
|
39 | + if (!$usesCachableTrait) { |
|
40 | 40 | $this->error("'{$option}' is not an instance of CachedModel."); |
41 | 41 | $this->line("Only CachedModel instances can be flushed."); |
42 | 42 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
49 | 49 | |
50 | 50 | $this->cache() |
51 | - ->rememberForever($cacheKey, function () { |
|
51 | + ->rememberForever($cacheKey, function() { |
|
52 | 52 | return now(); |
53 | 53 | }); |
54 | 54 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | return "genealabs:laravel-model-caching:" |
60 | 60 | . (config('laravel-model-caching.cache-prefix') |
61 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
61 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
62 | 62 | : ""); |
63 | 63 | } |
64 | 64 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | [$cacheCooldown, $invalidatedAt, $savedAt] = $this |
91 | 91 | ->getCacheCooldownDetails($instance, $cachePrefix, $modelClassName); |
92 | 92 | |
93 | - if (! $cacheCooldown || $cacheCooldown === 0) { |
|
93 | + if (!$cacheCooldown || $cacheCooldown === 0) { |
|
94 | 94 | return [null, null, null]; |
95 | 95 | } |
96 | 96 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | { |
124 | 124 | [$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance); |
125 | 125 | |
126 | - if (! $cacheCooldown |
|
126 | + if (!$cacheCooldown |
|
127 | 127 | || now()->diffInSeconds($invalidatedAt) < $cacheCooldown |
128 | 128 | ) { |
129 | 129 | return; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | { |
149 | 149 | [$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance); |
150 | 150 | |
151 | - if (! $cacheCooldown) { |
|
151 | + if (!$cacheCooldown) { |
|
152 | 152 | $instance->flushCache(); |
153 | 153 | |
154 | 154 | return; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | public function isCachable() : bool |
165 | 165 | { |
166 | 166 | return $this->isCachable |
167 | - && ! config('laravel-model-caching.disabled'); |
|
167 | + && !config('laravel-model-caching.disabled'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | protected function setCacheCooldownSavedAtTimestamp(Model $instance) |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
175 | 175 | |
176 | 176 | $instance->cache() |
177 | - ->rememberForever($cacheKey, function () { |
|
177 | + ->rememberForever($cacheKey, function() { |
|
178 | 178 | return now(); |
179 | 179 | }); |
180 | 180 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | protected function getLimitClause() : string |
51 | 51 | { |
52 | - if (! $this->query->limit) { |
|
52 | + if (!$this->query->limit) { |
|
53 | 53 | return ""; |
54 | 54 | } |
55 | 55 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | protected function getOffsetClause() : string |
65 | 65 | { |
66 | - if (! $this->query->offset) { |
|
66 | + if (!$this->query->offset) { |
|
67 | 67 | return ""; |
68 | 68 | } |
69 | 69 | |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | $orders = collect($this->query->orders); |
76 | 76 | |
77 | 77 | return $orders |
78 | - ->reduce(function ($carry, $order) { |
|
78 | + ->reduce(function($carry, $order) { |
|
79 | 79 | if (($order["type"] ?? "") === "Raw") { |
80 | - return $carry . "_orderByRaw_" . str_slug($order["sql"]); |
|
80 | + return $carry."_orderByRaw_".str_slug($order["sql"]); |
|
81 | 81 | } |
82 | 82 | |
83 | - return $carry . "_orderBy_" . $order["column"] . "_" . $order["direction"]; |
|
83 | + return $carry."_orderBy_".$order["column"]."_".$order["direction"]; |
|
84 | 84 | }) |
85 | 85 | ?: ""; |
86 | 86 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | return ""; |
92 | 92 | } |
93 | 93 | |
94 | - return "_" . implode("_", $columns); |
|
94 | + return "_".implode("_", $columns); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | protected function getTypeClause($where) : string |
98 | 98 | { |
99 | - $type =in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
99 | + $type = in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
100 | 100 | ? strtolower($where["type"]) |
101 | 101 | : strtolower($where["operator"]); |
102 | 102 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $values = $this->getValuesFromWhere($where); |
113 | 113 | $values = $this->getValuesFromBindings($values); |
114 | 114 | |
115 | - return "_" . $values; |
|
115 | + return "_".$values; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | protected function getValuesFromWhere(array $where) : string |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | protected function getValuesFromBindings(string $values) : string |
126 | 126 | { |
127 | - if (! $values && $this->query->bindings["where"] ?? false) { |
|
127 | + if (!$values && $this->query->bindings["where"] ?? false) { |
|
128 | 128 | $values = implode("_", $this->query->bindings["where"]); |
129 | 129 | } |
130 | 130 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | protected function getWhereClauses(array $wheres = []) : string |
135 | 135 | { |
136 | 136 | return $this->getWheres($wheres) |
137 | - ->reduce(function ($carry, $where) { |
|
137 | + ->reduce(function($carry, $where) { |
|
138 | 138 | $value = $this->getNestedClauses($where); |
139 | 139 | $value .= $this->getColumnClauses($where); |
140 | 140 | $value .= $this->getRawClauses($where); |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | |
148 | 148 | protected function getNestedClauses(array $where) : string |
149 | 149 | { |
150 | - if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
150 | + if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
151 | 151 | return ""; |
152 | 152 | } |
153 | 153 | |
154 | - return "_" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres); |
|
154 | + return "_".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | protected function getColumnClauses(array $where) : string |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | return ""; |
170 | 170 | } |
171 | 171 | |
172 | - return "_{$where["boolean"]}_" . str_slug($where["sql"]); |
|
172 | + return "_{$where["boolean"]}_".str_slug($where["sql"]); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | protected function getOtherClauses(array $where, string $carry = null) : string |
@@ -203,6 +203,6 @@ discard block |
||
203 | 203 | return ""; |
204 | 204 | } |
205 | 205 | |
206 | - return "-" . implode("-", $eagerLoads->keys()->toArray()); |
|
206 | + return "-".implode("-", $eagerLoads->keys()->toArray()); |
|
207 | 207 | } |
208 | 208 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | $tags = collect($this->eagerLoad) |
30 | 30 | ->keys() |
31 | - ->map(function ($relationName) { |
|
31 | + ->map(function($relationName) { |
|
32 | 32 | $relation = $this->getRelation($relationName); |
33 | 33 | |
34 | 34 | return $this->getCachePrefix() |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | protected function getRelation(string $relationName) : Relation |
54 | 54 | { |
55 | 55 | return collect(explode('.', $relationName)) |
56 | - ->reduce(function ($carry, $name) { |
|
56 | + ->reduce(function($carry, $name) { |
|
57 | 57 | $carry = $carry ?: $this->model; |
58 | 58 | $carry = $this->getRelatedModel($carry); |
59 | 59 | |
@@ -63,6 +63,6 @@ discard block |
||
63 | 63 | |
64 | 64 | protected function getTagName() : string |
65 | 65 | { |
66 | - return $this->getCachePrefix() . str_slug(get_class($this->model)); |
|
66 | + return $this->getCachePrefix().str_slug(get_class($this->model)); |
|
67 | 67 | } |
68 | 68 | } |
@@ -5,9 +5,9 @@ |
||
5 | 5 | protected function getCachePrefix() : string |
6 | 6 | { |
7 | 7 | return "genealabs:laravel-model-caching:" |
8 | - . $this->getDatabaseConnectionName() . ":" |
|
8 | + . $this->getDatabaseConnectionName().":" |
|
9 | 9 | . (config("laravel-model-caching.cache-prefix") |
10 | - ? config("laravel-model-caching.cache-prefix", "") . ":" |
|
10 | + ? config("laravel-model-caching.cache-prefix", "").":" |
|
11 | 11 | : ""); |
12 | 12 | } |
13 | 13 |
@@ -18,33 +18,33 @@ discard block |
||
18 | 18 | $key = $instance->makeCacheKey(); |
19 | 19 | |
20 | 20 | return $instance->cache($tags) |
21 | - ->rememberForever($key, function () use ($columns) { |
|
21 | + ->rememberForever($key, function() use ($columns) { |
|
22 | 22 | return parent::all($columns); |
23 | 23 | }); |
24 | 24 | } |
25 | 25 | |
26 | 26 | public static function bootCachable() |
27 | 27 | { |
28 | - static::saved(function ($instance) { |
|
28 | + static::saved(function($instance) { |
|
29 | 29 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
30 | 30 | }); |
31 | 31 | |
32 | - static::pivotAttached(function ($instance) { |
|
32 | + static::pivotAttached(function($instance) { |
|
33 | 33 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
34 | 34 | }); |
35 | 35 | |
36 | - static::pivotDetached(function ($instance) { |
|
36 | + static::pivotDetached(function($instance) { |
|
37 | 37 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
38 | 38 | }); |
39 | 39 | |
40 | - static::pivotUpdated(function ($instance) { |
|
40 | + static::pivotUpdated(function($instance) { |
|
41 | 41 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
42 | 42 | }); |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function newEloquentBuilder($query) |
46 | 46 | { |
47 | - if (! $this->isCachable()) { |
|
47 | + if (!$this->isCachable()) { |
|
48 | 48 | $this->isCachable = true; |
49 | 49 | |
50 | 50 | return new EloquentBuilder($query); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function scopeDisableCache(EloquentBuilder $query) : QueryOrModelCaller |
57 | 57 | { |
58 | - $disabledInConfig = config('laravel-model-caching.disabled'); |
|
58 | + $disabledInConfig = config('laravel-model-caching.disabled'); |
|
59 | 59 | |
60 | 60 | if ($this->isCachable()) { |
61 | 61 | config()->set('laravel-model-caching.disabled', true); |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds"; |
75 | 75 | |
76 | 76 | $this->cache() |
77 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
77 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
78 | 78 | return $seconds; |
79 | 79 | }); |
80 | 80 | |
81 | 81 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"; |
82 | 82 | $this->cache() |
83 | - ->rememberForever($cacheKey, function () { |
|
83 | + ->rememberForever($cacheKey, function() { |
|
84 | 84 | return now(); |
85 | 85 | }); |
86 | 86 |
@@ -42,10 +42,11 @@ |
||
42 | 42 | */ |
43 | 43 | public function __call($name, $arguments) |
44 | 44 | { |
45 | - if ($name == 'all') |
|
46 | - $result = call_user_func_array([$this->model, 'all'], $arguments); |
|
47 | - else |
|
48 | - $result = call_user_func_array([$this->query, $name], $arguments); |
|
45 | + if ($name == 'all') { |
|
46 | + $result = call_user_func_array([$this->model, 'all'], $arguments); |
|
47 | + } else { |
|
48 | + $result = call_user_func_array([$this->query, $name], $arguments); |
|
49 | + } |
|
49 | 50 | |
50 | 51 | config()->set('laravel-model-caching.disabled', $this->disableInConfig); |
51 | 52 |