@@ -2,96 +2,96 @@ |
||
2 | 2 | |
3 | 3 | class CachingDecorator |
4 | 4 | { |
5 | - /** |
|
6 | - * The repo implementation. |
|
7 | - * |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - public $repo; |
|
5 | + /** |
|
6 | + * The repo implementation. |
|
7 | + * |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + public $repo; |
|
11 | 11 | |
12 | - /** |
|
13 | - * The cache implementation. |
|
14 | - * |
|
15 | - * @var object |
|
16 | - */ |
|
17 | - protected $cache; |
|
12 | + /** |
|
13 | + * The cache implementation. |
|
14 | + * |
|
15 | + * @var object |
|
16 | + */ |
|
17 | + protected $cache; |
|
18 | 18 | |
19 | - /** |
|
20 | - * The model implementation. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $model; |
|
19 | + /** |
|
20 | + * The model implementation. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $model; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The cacheConfig implementation. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - public $cacheConfig; |
|
26 | + /** |
|
27 | + * The cacheConfig implementation. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + public $cacheConfig; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Create new CachingDecorator instance. |
|
35 | - */ |
|
36 | - public function __construct($repo, $cache) |
|
37 | - { |
|
38 | - $this->repo = $repo; |
|
39 | - $this->cache = $cache; |
|
40 | - $this->model = get_class($this->repo->model); |
|
41 | - } |
|
33 | + /** |
|
34 | + * Create new CachingDecorator instance. |
|
35 | + */ |
|
36 | + public function __construct($repo, $cache) |
|
37 | + { |
|
38 | + $this->repo = $repo; |
|
39 | + $this->cache = $cache; |
|
40 | + $this->model = get_class($this->repo->model); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Handle the cache mechanism for the called method |
|
45 | - * based the configurations. |
|
46 | - * |
|
47 | - * @param string $name the called method name |
|
48 | - * @param array $arguments the method arguments |
|
49 | - * @return object |
|
50 | - */ |
|
51 | - public function __call($name, $arguments) |
|
52 | - { |
|
53 | - $this->setCacheConfig($name); |
|
43 | + /** |
|
44 | + * Handle the cache mechanism for the called method |
|
45 | + * based the configurations. |
|
46 | + * |
|
47 | + * @param string $name the called method name |
|
48 | + * @param array $arguments the method arguments |
|
49 | + * @return object |
|
50 | + */ |
|
51 | + public function __call($name, $arguments) |
|
52 | + { |
|
53 | + $this->setCacheConfig($name); |
|
54 | 54 | |
55 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') |
|
56 | - { |
|
57 | - $page = \Request::get('page') ?? '1'; |
|
58 | - $cacheKey = $name . $page . serialize($arguments); |
|
59 | - return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
60 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
61 | - }); |
|
62 | - } |
|
63 | - else if ($this->cacheConfig) |
|
64 | - { |
|
65 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
66 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
67 | - } |
|
55 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') |
|
56 | + { |
|
57 | + $page = \Request::get('page') ?? '1'; |
|
58 | + $cacheKey = $name . $page . serialize($arguments); |
|
59 | + return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
60 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
61 | + }); |
|
62 | + } |
|
63 | + else if ($this->cacheConfig) |
|
64 | + { |
|
65 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
66 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
67 | + } |
|
68 | 68 | |
69 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
70 | - } |
|
69 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Set cache config based on the called method. |
|
74 | - * |
|
75 | - * @param string $name |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - private function setCacheConfig($name) |
|
79 | - { |
|
80 | - $strArr = explode('\\', get_class($this->repo)); |
|
81 | - $repoName = end($strArr); |
|
82 | - $configKey = str_plural(strtolower(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
72 | + /** |
|
73 | + * Set cache config based on the called method. |
|
74 | + * |
|
75 | + * @param string $name |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + private function setCacheConfig($name) |
|
79 | + { |
|
80 | + $strArr = explode('\\', get_class($this->repo)); |
|
81 | + $repoName = end($strArr); |
|
82 | + $configKey = str_plural(strtolower(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
83 | 83 | |
84 | - $config = \CoreConfig::getConfig(); |
|
85 | - $cacheConfig = array_key_exists($configKey, $config['cacheConfig']) ? $config['cacheConfig'][$configKey] : false; |
|
86 | - $this->cacheConfig = false; |
|
84 | + $config = \CoreConfig::getConfig(); |
|
85 | + $cacheConfig = array_key_exists($configKey, $config['cacheConfig']) ? $config['cacheConfig'][$configKey] : false; |
|
86 | + $this->cacheConfig = false; |
|
87 | 87 | |
88 | - if (in_array($name, $cacheConfig['cache'])) |
|
89 | - { |
|
90 | - $this->cacheConfig = 'cache'; |
|
91 | - } |
|
92 | - else if (in_array($name, $cacheConfig['clear'])) |
|
93 | - { |
|
94 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
95 | - } |
|
96 | - } |
|
88 | + if (in_array($name, $cacheConfig['cache'])) |
|
89 | + { |
|
90 | + $this->cacheConfig = 'cache'; |
|
91 | + } |
|
92 | + else if (in_array($name, $cacheConfig['clear'])) |
|
93 | + { |
|
94 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
95 | + } |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -8,7 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | public function index() |
10 | 10 | { |
11 | - $path = str_replace($_SERVER['DOCUMENT_ROOT'], '',str_replace('\\', '/', __FILE__)); |
|
11 | + $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', __FILE__)); |
|
12 | 12 | $baseUrl = str_replace('Http/Controllers/ApiDocumentController.php', '', $path); |
13 | 13 | $jsonDoc = json_decode(file_get_contents(app_path('Modules/V1/Core/Resources/api.json')), true); |
14 | 14 | $modules = $jsonDoc['modules']; |