@@ -8,15 +8,15 @@ |
||
8 | 8 | |
9 | 9 | class PermissionService extends BaseService |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param PermissionRepository $repo |
|
15 | - * @param Session $session |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function __construct(PermissionRepository $repo, Session $session) |
|
19 | - { |
|
20 | - parent::__construct($repo, $session); |
|
21 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param PermissionRepository $repo |
|
15 | + * @param Session $session |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function __construct(PermissionRepository $repo, Session $session) |
|
19 | + { |
|
20 | + parent::__construct($repo, $session); |
|
21 | + } |
|
22 | 22 | } |
@@ -8,64 +8,64 @@ |
||
8 | 8 | |
9 | 9 | class OauthClientService extends BaseService |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param OauthClientRepository $repo |
|
15 | - * @param Session $session |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function __construct(OauthClientRepository $repo, Session $session) |
|
19 | - { |
|
20 | - parent::__construct($repo, $session); |
|
21 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param OauthClientRepository $repo |
|
15 | + * @param Session $session |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function __construct(OauthClientRepository $repo, Session $session) |
|
19 | + { |
|
20 | + parent::__construct($repo, $session); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Revoke the given client. |
|
25 | - * |
|
26 | - * @param integer $clientId |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function revoke($clientId) |
|
30 | - { |
|
31 | - \DB::transaction(function () use ($clientId) { |
|
32 | - $client = $this->repo->find($clientId); |
|
33 | - $this->repo->revokeClientTokens($client); |
|
34 | - $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
35 | - }); |
|
36 | - } |
|
23 | + /** |
|
24 | + * Revoke the given client. |
|
25 | + * |
|
26 | + * @param integer $clientId |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function revoke($clientId) |
|
30 | + { |
|
31 | + \DB::transaction(function () use ($clientId) { |
|
32 | + $client = $this->repo->find($clientId); |
|
33 | + $this->repo->revokeClientTokens($client); |
|
34 | + $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
35 | + }); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * UnRevoke the given client. |
|
40 | - * |
|
41 | - * @param integer $clientId |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function unRevoke($clientId) |
|
45 | - { |
|
46 | - $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
47 | - } |
|
38 | + /** |
|
39 | + * UnRevoke the given client. |
|
40 | + * |
|
41 | + * @param integer $clientId |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function unRevoke($clientId) |
|
45 | + { |
|
46 | + $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Ensure access token hasn't expired or revoked. |
|
51 | - * |
|
52 | - * @param string $accessToken |
|
53 | - * @return boolean |
|
54 | - */ |
|
55 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
56 | - { |
|
57 | - return $this->repo->accessTokenExpiredOrRevoked($accessToken); |
|
58 | - } |
|
49 | + /** |
|
50 | + * Ensure access token hasn't expired or revoked. |
|
51 | + * |
|
52 | + * @param string $accessToken |
|
53 | + * @return boolean |
|
54 | + */ |
|
55 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
56 | + { |
|
57 | + return $this->repo->accessTokenExpiredOrRevoked($accessToken); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Revoke the given access token and all |
|
62 | - * associated refresh tokens. |
|
63 | - * |
|
64 | - * @param oject $accessToken |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function revokeAccessToken($accessToken) |
|
68 | - { |
|
69 | - return $this->repo->revokeAccessToken($accessToken); |
|
70 | - } |
|
60 | + /** |
|
61 | + * Revoke the given access token and all |
|
62 | + * associated refresh tokens. |
|
63 | + * |
|
64 | + * @param oject $accessToken |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function revokeAccessToken($accessToken) |
|
68 | + { |
|
69 | + return $this->repo->revokeAccessToken($accessToken); |
|
70 | + } |
|
71 | 71 | } |
@@ -8,39 +8,39 @@ |
||
8 | 8 | |
9 | 9 | class PushNotificationDeviceService extends BaseService |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param PushNotificationDeviceRepository $repo |
|
15 | - * @param Session $session |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function __construct(PushNotificationDeviceRepository $repo, Session $session) |
|
19 | - { |
|
20 | - parent::__construct($repo, $session); |
|
21 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param PushNotificationDeviceRepository $repo |
|
15 | + * @param Session $session |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function __construct(PushNotificationDeviceRepository $repo, Session $session) |
|
19 | + { |
|
20 | + parent::__construct($repo, $session); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the given device to the logged in user. |
|
25 | - * |
|
26 | - * @param array $data |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function registerDevice($data) |
|
30 | - { |
|
31 | - $data['access_token'] = \Auth::user()->token(); |
|
32 | - $data['user_id'] = \Auth::id(); |
|
33 | - $device = $this->repo->first([ |
|
34 | - 'and' => [ |
|
35 | - 'device_token' => $data['device_token'], |
|
36 | - 'user_id' => $data['user_id'] |
|
37 | - ] |
|
38 | - ]); |
|
23 | + /** |
|
24 | + * Register the given device to the logged in user. |
|
25 | + * |
|
26 | + * @param array $data |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function registerDevice($data) |
|
30 | + { |
|
31 | + $data['access_token'] = \Auth::user()->token(); |
|
32 | + $data['user_id'] = \Auth::id(); |
|
33 | + $device = $this->repo->first([ |
|
34 | + 'and' => [ |
|
35 | + 'device_token' => $data['device_token'], |
|
36 | + 'user_id' => $data['user_id'] |
|
37 | + ] |
|
38 | + ]); |
|
39 | 39 | |
40 | - if ($device) { |
|
41 | - $data['id'] = $device->id; |
|
42 | - } |
|
40 | + if ($device) { |
|
41 | + $data['id'] = $device->id; |
|
42 | + } |
|
43 | 43 | |
44 | - return $this->repo->save($data); |
|
45 | - } |
|
44 | + return $this->repo->save($data); |
|
45 | + } |
|
46 | 46 | } |
@@ -9,49 +9,49 @@ |
||
9 | 9 | |
10 | 10 | class ReportService extends BaseService |
11 | 11 | { |
12 | - /** |
|
13 | - * @var UserService |
|
14 | - */ |
|
15 | - protected $userService; |
|
12 | + /** |
|
13 | + * @var UserService |
|
14 | + */ |
|
15 | + protected $userService; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Init new object. |
|
19 | - * |
|
20 | - * @param ReportRepository $repo |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function __construct(ReportRepository $repo, UserService $userService, Session $session) |
|
24 | - { |
|
25 | - $this->userService = $userService; |
|
26 | - parent::__construct($repo, $session); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Init new object. |
|
19 | + * |
|
20 | + * @param ReportRepository $repo |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function __construct(ReportRepository $repo, UserService $userService, Session $session) |
|
24 | + { |
|
25 | + $this->userService = $userService; |
|
26 | + parent::__construct($repo, $session); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Render the given report db view based on the given |
|
31 | - * condition. |
|
32 | - * |
|
33 | - * @param string $reportName |
|
34 | - * @param array $conditions |
|
35 | - * @param integer $perPage |
|
36 | - * @param boolean $skipPermission |
|
37 | - * @return object |
|
38 | - */ |
|
39 | - public function getReport($reportName, $conditions = [], $perPage = 0, $skipPermission = false) |
|
40 | - { |
|
41 | - /** |
|
42 | - * Fetch the report from db. |
|
43 | - */ |
|
44 | - $report = $this->repo->first(['report_name' => $reportName]); |
|
29 | + /** |
|
30 | + * Render the given report db view based on the given |
|
31 | + * condition. |
|
32 | + * |
|
33 | + * @param string $reportName |
|
34 | + * @param array $conditions |
|
35 | + * @param integer $perPage |
|
36 | + * @param boolean $skipPermission |
|
37 | + * @return object |
|
38 | + */ |
|
39 | + public function getReport($reportName, $conditions = [], $perPage = 0, $skipPermission = false) |
|
40 | + { |
|
41 | + /** |
|
42 | + * Fetch the report from db. |
|
43 | + */ |
|
44 | + $report = $this->repo->first(['report_name' => $reportName]); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Check report existance and permission. |
|
48 | - */ |
|
49 | - if (! $report) { |
|
50 | - \Errors::notFound('report'); |
|
51 | - } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
52 | - \Errors::noPermissions(); |
|
53 | - } |
|
46 | + /** |
|
47 | + * Check report existance and permission. |
|
48 | + */ |
|
49 | + if (! $report) { |
|
50 | + \Errors::notFound('report'); |
|
51 | + } elseif (! $skipPermission && ! $this->userService->can($report->view_name, 'report')) { |
|
52 | + \Errors::noPermissions(); |
|
53 | + } |
|
54 | 54 | |
55 | - return $this->repo->renderReport($report, $conditions, $perPage); |
|
56 | - } |
|
55 | + return $this->repo->renderReport($report, $conditions, $perPage); |
|
56 | + } |
|
57 | 57 | } |
@@ -9,30 +9,30 @@ |
||
9 | 9 | |
10 | 10 | class Errors implements BaseFactoryInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Construct the config class name based on |
|
14 | - * the method name called, search in the |
|
15 | - * given namespaces for the class and |
|
16 | - * return an instance. |
|
17 | - * |
|
18 | - * @param string $name the called method name |
|
19 | - * @param array $arguments the method arguments |
|
20 | - * @return object |
|
21 | - */ |
|
22 | - public function __call(string $name, array $arguments): object |
|
23 | - { |
|
24 | - foreach (Module::all() as $module) { |
|
25 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
26 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
12 | + /** |
|
13 | + * Construct the config class name based on |
|
14 | + * the method name called, search in the |
|
15 | + * given namespaces for the class and |
|
16 | + * return an instance. |
|
17 | + * |
|
18 | + * @param string $name the called method name |
|
19 | + * @param array $arguments the method arguments |
|
20 | + * @return object |
|
21 | + */ |
|
22 | + public function __call(string $name, array $arguments): object |
|
23 | + { |
|
24 | + foreach (Module::all() as $module) { |
|
25 | + $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
26 | + $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
27 | 27 | |
28 | - if (class_exists($class)) { |
|
29 | - $class = App::make($class); |
|
30 | - if (method_exists($class, $name)) { |
|
31 | - return call_user_func_array([$class, $name], $arguments); |
|
32 | - } |
|
33 | - } |
|
34 | - } |
|
28 | + if (class_exists($class)) { |
|
29 | + $class = App::make($class); |
|
30 | + if (method_exists($class, $name)) { |
|
31 | + return call_user_func_array([$class, $name], $arguments); |
|
32 | + } |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | - return new stdClass; |
|
37 | - } |
|
36 | + return new stdClass; |
|
37 | + } |
|
38 | 38 | } |
@@ -22,8 +22,8 @@ |
||
22 | 22 | public function __call(string $name, array $arguments): object |
23 | 23 | { |
24 | 24 | foreach (Module::all() as $module) { |
25 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
26 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
25 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
26 | + $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors'; |
|
27 | 27 | |
28 | 28 | if (class_exists($class)) { |
29 | 29 | $class = App::make($class); |
@@ -8,30 +8,30 @@ |
||
8 | 8 | |
9 | 9 | class SettingService extends BaseService |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param SettingRepository $repo |
|
15 | - * @param Session $session |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function __construct(SettingRepository $repo, Session $session) |
|
19 | - { |
|
20 | - parent::__construct($repo, $session); |
|
21 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param SettingRepository $repo |
|
15 | + * @param Session $session |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function __construct(SettingRepository $repo, Session $session) |
|
19 | + { |
|
20 | + parent::__construct($repo, $session); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Save list of settings. |
|
25 | - * |
|
26 | - * @param array $data |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function saveMany(array $data) |
|
30 | - { |
|
31 | - \DB::transaction(function () use ($data) { |
|
32 | - foreach ($data as $value) { |
|
33 | - $this->repo->save($value); |
|
34 | - } |
|
35 | - }); |
|
36 | - } |
|
23 | + /** |
|
24 | + * Save list of settings. |
|
25 | + * |
|
26 | + * @param array $data |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function saveMany(array $data) |
|
30 | + { |
|
31 | + \DB::transaction(function () use ($data) { |
|
32 | + foreach ($data as $value) { |
|
33 | + $this->repo->save($value); |
|
34 | + } |
|
35 | + }); |
|
36 | + } |
|
37 | 37 | } |
@@ -10,32 +10,32 @@ |
||
10 | 10 | |
11 | 11 | class Core implements BaseFactoryInterface |
12 | 12 | { |
13 | - /** |
|
14 | - * Construct the repository class name based on |
|
15 | - * the method name called, search in the |
|
16 | - * given namespaces for the class and |
|
17 | - * return an instance. |
|
18 | - * |
|
19 | - * @param string $name the called method name |
|
20 | - * @param array $arguments the method arguments |
|
21 | - * @return object |
|
22 | - */ |
|
23 | - public function __call(string $name, array $arguments): object |
|
24 | - { |
|
25 | - foreach (Module::all() as $module) { |
|
26 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
27 | - $model = ucfirst(Str::singular($name)); |
|
28 | - if (count($arguments) == 1 && $arguments[0]) { |
|
29 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
30 | - } else { |
|
31 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
32 | - } |
|
13 | + /** |
|
14 | + * Construct the repository class name based on |
|
15 | + * the method name called, search in the |
|
16 | + * given namespaces for the class and |
|
17 | + * return an instance. |
|
18 | + * |
|
19 | + * @param string $name the called method name |
|
20 | + * @param array $arguments the method arguments |
|
21 | + * @return object |
|
22 | + */ |
|
23 | + public function __call(string $name, array $arguments): object |
|
24 | + { |
|
25 | + foreach (Module::all() as $module) { |
|
26 | + $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
27 | + $model = ucfirst(Str::singular($name)); |
|
28 | + if (count($arguments) == 1 && $arguments[0]) { |
|
29 | + $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
30 | + } else { |
|
31 | + $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
32 | + } |
|
33 | 33 | |
34 | - if (class_exists($class)) { |
|
35 | - return App::make($class); |
|
36 | - } |
|
37 | - } |
|
34 | + if (class_exists($class)) { |
|
35 | + return App::make($class); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - return new stdClass; |
|
40 | - } |
|
39 | + return new stdClass; |
|
40 | + } |
|
41 | 41 | } |
@@ -23,12 +23,12 @@ |
||
23 | 23 | public function __call(string $name, array $arguments): object |
24 | 24 | { |
25 | 25 | foreach (Module::all() as $module) { |
26 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
26 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
27 | 27 | $model = ucfirst(Str::singular($name)); |
28 | 28 | if (count($arguments) == 1 && $arguments[0]) { |
29 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
29 | + $class = $nameSpace.'\\Services\\'.$model.'Service'; |
|
30 | 30 | } else { |
31 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
31 | + $class = $nameSpace.'\\Repositories\\'.$model.'Repository'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | if (class_exists($class)) { |
@@ -11,96 +11,96 @@ |
||
11 | 11 | |
12 | 12 | class CachingDecorator |
13 | 13 | { |
14 | - /** |
|
15 | - * @var BaseServiceInterface |
|
16 | - */ |
|
17 | - protected $service; |
|
14 | + /** |
|
15 | + * @var BaseServiceInterface |
|
16 | + */ |
|
17 | + protected $service; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var Repository |
|
21 | - */ |
|
22 | - protected $cache; |
|
19 | + /** |
|
20 | + * @var Repository |
|
21 | + */ |
|
22 | + protected $cache; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var mixed |
|
26 | - */ |
|
27 | - protected $cacheConfig; |
|
24 | + /** |
|
25 | + * @var mixed |
|
26 | + */ |
|
27 | + protected $cacheConfig; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $cacheTag; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $cacheTag; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var Request |
|
36 | - */ |
|
37 | - protected $request; |
|
34 | + /** |
|
35 | + * @var Request |
|
36 | + */ |
|
37 | + protected $request; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var Session |
|
41 | - */ |
|
42 | - protected $session; |
|
39 | + /** |
|
40 | + * @var Session |
|
41 | + */ |
|
42 | + protected $session; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Init new object. |
|
46 | - * |
|
47 | - * @param BaseServiceInterface $service |
|
48 | - * @param Cache $cache |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function __construct(BaseServiceInterface $service, Repository $cache, Request $request, Session $session) |
|
53 | - { |
|
54 | - $this->service = $service; |
|
55 | - $this->cache = $cache; |
|
56 | - $this->request = $request; |
|
57 | - $this->session = $session; |
|
58 | - $serviceClass = explode('\\', get_class($this->service)); |
|
59 | - $serviceName = end($serviceClass); |
|
60 | - $this->cacheTag = lcfirst(substr($serviceName, 0, strpos($serviceName, 'Service'))); |
|
61 | - } |
|
44 | + /** |
|
45 | + * Init new object. |
|
46 | + * |
|
47 | + * @param BaseServiceInterface $service |
|
48 | + * @param Cache $cache |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function __construct(BaseServiceInterface $service, Repository $cache, Request $request, Session $session) |
|
53 | + { |
|
54 | + $this->service = $service; |
|
55 | + $this->cache = $cache; |
|
56 | + $this->request = $request; |
|
57 | + $this->session = $session; |
|
58 | + $serviceClass = explode('\\', get_class($this->service)); |
|
59 | + $serviceName = end($serviceClass); |
|
60 | + $this->cacheTag = lcfirst(substr($serviceName, 0, strpos($serviceName, 'Service'))); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Handle the cache mechanism for the called method |
|
65 | - * based the configurations. |
|
66 | - * |
|
67 | - * @param string $name the called method name |
|
68 | - * @param array $arguments the method arguments |
|
69 | - * @return object |
|
70 | - */ |
|
71 | - public function __call($name, $arguments) |
|
72 | - { |
|
73 | - $this->setCacheConfig($name); |
|
63 | + /** |
|
64 | + * Handle the cache mechanism for the called method |
|
65 | + * based the configurations. |
|
66 | + * |
|
67 | + * @param string $name the called method name |
|
68 | + * @param array $arguments the method arguments |
|
69 | + * @return object |
|
70 | + */ |
|
71 | + public function __call($name, $arguments) |
|
72 | + { |
|
73 | + $this->setCacheConfig($name); |
|
74 | 74 | |
75 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
76 | - $page = $this->request->get('page') !== null ? $this->request->get('page') : '1'; |
|
77 | - $cacheKey = $name.$page.$this->session->get('locale').serialize($arguments); |
|
78 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
79 | - return call_user_func_array([$this->service, $name], $arguments); |
|
80 | - }); |
|
81 | - } elseif ($this->cacheConfig) { |
|
82 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
83 | - return call_user_func_array([$this->service, $name], $arguments); |
|
84 | - } |
|
75 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
76 | + $page = $this->request->get('page') !== null ? $this->request->get('page') : '1'; |
|
77 | + $cacheKey = $name.$page.$this->session->get('locale').serialize($arguments); |
|
78 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
79 | + return call_user_func_array([$this->service, $name], $arguments); |
|
80 | + }); |
|
81 | + } elseif ($this->cacheConfig) { |
|
82 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
83 | + return call_user_func_array([$this->service, $name], $arguments); |
|
84 | + } |
|
85 | 85 | |
86 | - return call_user_func_array([$this->service, $name], $arguments); |
|
87 | - } |
|
86 | + return call_user_func_array([$this->service, $name], $arguments); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Set cache config based on the called method. |
|
91 | - * |
|
92 | - * @param string $name |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - private function setCacheConfig($name) |
|
96 | - { |
|
97 | - $cacheConfig = Arr::get(config('core.cache_config'), $this->cacheTag, false); |
|
98 | - $this->cacheConfig = false; |
|
89 | + /** |
|
90 | + * Set cache config based on the called method. |
|
91 | + * |
|
92 | + * @param string $name |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + private function setCacheConfig($name) |
|
96 | + { |
|
97 | + $cacheConfig = Arr::get(config('core.cache_config'), $this->cacheTag, false); |
|
98 | + $this->cacheConfig = false; |
|
99 | 99 | |
100 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
101 | - $this->cacheConfig = 'cache'; |
|
102 | - } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
103 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
104 | - } |
|
105 | - } |
|
100 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
101 | + $this->cacheConfig = 'cache'; |
|
102 | + } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
103 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
@@ -75,7 +75,7 @@ |
||
75 | 75 | if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
76 | 76 | $page = $this->request->get('page') !== null ? $this->request->get('page') : '1'; |
77 | 77 | $cacheKey = $name.$page.$this->session->get('locale').serialize($arguments); |
78 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
78 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
79 | 79 | return call_user_func_array([$this->service, $name], $arguments); |
80 | 80 | }); |
81 | 81 | } elseif ($this->cacheConfig) { |
@@ -13,109 +13,109 @@ |
||
13 | 13 | |
14 | 14 | class BaseApiController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * Array of eager loaded relations. |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $relations; |
|
16 | + /** |
|
17 | + * Array of eager loaded relations. |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $relations; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var object |
|
25 | - */ |
|
26 | - protected $service; |
|
23 | + /** |
|
24 | + * @var object |
|
25 | + */ |
|
26 | + protected $service; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Path of the model resource. |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $modelResource; |
|
28 | + /** |
|
29 | + * Path of the model resource. |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $modelResource; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Path of the sotre form request. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $storeFormRequest; |
|
35 | + /** |
|
36 | + * Path of the sotre form request. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $storeFormRequest; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Init new object. |
|
44 | - * |
|
45 | - * @param BaseServiceInterface $service |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function __construct(BaseServiceInterface $service) |
|
49 | - { |
|
50 | - $this->service = new CachingDecorator($service, App::make(Repository::class), App::make(Request::class), App::make(Session::class)); |
|
51 | - } |
|
42 | + /** |
|
43 | + * Init new object. |
|
44 | + * |
|
45 | + * @param BaseServiceInterface $service |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function __construct(BaseServiceInterface $service) |
|
49 | + { |
|
50 | + $this->service = new CachingDecorator($service, App::make(Repository::class), App::make(Request::class), App::make(Session::class)); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Fetch all records with relations from storage. |
|
55 | - * |
|
56 | - * @param Request $request |
|
57 | - * @return \Illuminate\Http\Response |
|
58 | - */ |
|
59 | - public function index(Request $request) |
|
60 | - { |
|
61 | - return $this->modelResource::collection($this->service->list($request->relations, $request->query(), $request->query('perPage', 15), $request->query('sortBy', 'created_at'), $request->query('desc', false), $request->query('trashed', false))); |
|
62 | - } |
|
53 | + /** |
|
54 | + * Fetch all records with relations from storage. |
|
55 | + * |
|
56 | + * @param Request $request |
|
57 | + * @return \Illuminate\Http\Response |
|
58 | + */ |
|
59 | + public function index(Request $request) |
|
60 | + { |
|
61 | + return $this->modelResource::collection($this->service->list($request->relations, $request->query(), $request->query('perPage', 15), $request->query('sortBy', 'created_at'), $request->query('desc', false), $request->query('trashed', false))); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Fetch the single object with relations from storage. |
|
66 | - * |
|
67 | - * @param Request $request |
|
68 | - * @param integer $id Id of the requested model. |
|
69 | - * @return \Illuminate\Http\Response |
|
70 | - */ |
|
71 | - public function show(Request $request, $id) |
|
72 | - { |
|
73 | - return new $this->modelResource($this->service->find($id, $request->relations)); |
|
74 | - } |
|
64 | + /** |
|
65 | + * Fetch the single object with relations from storage. |
|
66 | + * |
|
67 | + * @param Request $request |
|
68 | + * @param integer $id Id of the requested model. |
|
69 | + * @return \Illuminate\Http\Response |
|
70 | + */ |
|
71 | + public function show(Request $request, $id) |
|
72 | + { |
|
73 | + return new $this->modelResource($this->service->find($id, $request->relations)); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Insert the given model to storage. |
|
78 | - * |
|
79 | - * @return \Illuminate\Http\Response |
|
80 | - */ |
|
81 | - public function store() |
|
82 | - { |
|
83 | - $data = App::make($this->storeFormRequest)->validated(); |
|
84 | - return new $this->modelResource($this->service->save($data)); |
|
85 | - } |
|
76 | + /** |
|
77 | + * Insert the given model to storage. |
|
78 | + * |
|
79 | + * @return \Illuminate\Http\Response |
|
80 | + */ |
|
81 | + public function store() |
|
82 | + { |
|
83 | + $data = App::make($this->storeFormRequest)->validated(); |
|
84 | + return new $this->modelResource($this->service->save($data)); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Update the given model to storage. |
|
89 | - * |
|
90 | - * @param integer $id |
|
91 | - * @return \Illuminate\Http\Response |
|
92 | - */ |
|
93 | - public function update($id) |
|
94 | - { |
|
95 | - $data = App::make($this->storeFormRequest)->validated(); |
|
96 | - $data['id'] = $id; |
|
97 | - return new $this->modelResource($this->service->save($data)); |
|
98 | - } |
|
87 | + /** |
|
88 | + * Update the given model to storage. |
|
89 | + * |
|
90 | + * @param integer $id |
|
91 | + * @return \Illuminate\Http\Response |
|
92 | + */ |
|
93 | + public function update($id) |
|
94 | + { |
|
95 | + $data = App::make($this->storeFormRequest)->validated(); |
|
96 | + $data['id'] = $id; |
|
97 | + return new $this->modelResource($this->service->save($data)); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Delete by the given id from storage. |
|
102 | - * |
|
103 | - * @param integer $id Id of the deleted model. |
|
104 | - * @return \Illuminate\Http\Response |
|
105 | - */ |
|
106 | - public function destroy($id) |
|
107 | - { |
|
108 | - return new GeneralResource($this->service->delete($id)); |
|
109 | - } |
|
100 | + /** |
|
101 | + * Delete by the given id from storage. |
|
102 | + * |
|
103 | + * @param integer $id Id of the deleted model. |
|
104 | + * @return \Illuminate\Http\Response |
|
105 | + */ |
|
106 | + public function destroy($id) |
|
107 | + { |
|
108 | + return new GeneralResource($this->service->delete($id)); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Restore the deleted model. |
|
113 | - * |
|
114 | - * @param integer $id Id of the restored model. |
|
115 | - * @return \Illuminate\Http\Response |
|
116 | - */ |
|
117 | - public function restore($id) |
|
118 | - { |
|
119 | - return new GeneralResource($this->service->restore($id)); |
|
120 | - } |
|
111 | + /** |
|
112 | + * Restore the deleted model. |
|
113 | + * |
|
114 | + * @param integer $id Id of the restored model. |
|
115 | + * @return \Illuminate\Http\Response |
|
116 | + */ |
|
117 | + public function restore($id) |
|
118 | + { |
|
119 | + return new GeneralResource($this->service->restore($id)); |
|
120 | + } |
|
121 | 121 | } |