@@ -6,25 +6,25 @@ |
||
| 6 | 6 | |
| 7 | 7 | class StoreRole extends FormRequest |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Determine if the user is authorized to make this request. |
|
| 11 | - * |
|
| 12 | - * @return bool |
|
| 13 | - */ |
|
| 14 | - public function authorize() |
|
| 15 | - { |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * Determine if the user is authorized to make this request. |
|
| 11 | + * |
|
| 12 | + * @return bool |
|
| 13 | + */ |
|
| 14 | + public function authorize() |
|
| 15 | + { |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Get the validation rules that apply to the request. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function rules() |
|
| 25 | - { |
|
| 26 | - return [ |
|
| 27 | - 'name' => 'required|string|max:100|unique:roles,name,' . $this->route('id') |
|
| 28 | - ]; |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * Get the validation rules that apply to the request. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function rules() |
|
| 25 | + { |
|
| 26 | + return [ |
|
| 27 | + 'name' => 'required|string|max:100|unique:roles,name,' . $this->route('id') |
|
| 28 | + ]; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | public function rules() |
| 25 | 25 | { |
| 26 | 26 | return [ |
| 27 | - 'name' => 'required|string|max:100|unique:roles,name,' . $this->route('id') |
|
| 27 | + 'name' => 'required|string|max:100|unique:roles,name,'.$this->route('id') |
|
| 28 | 28 | ]; |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RoleService extends BaseService |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Init new object. |
|
| 12 | - * |
|
| 13 | - * @param RoleRepository $repo |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function __construct(RoleRepository $repo) |
|
| 17 | - { |
|
| 18 | - parent::__construct($repo); |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * Init new object. |
|
| 12 | + * |
|
| 13 | + * @param RoleRepository $repo |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function __construct(RoleRepository $repo) |
|
| 17 | + { |
|
| 18 | + parent::__construct($repo); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Assign the given permission ids to the given role. |
|
| 23 | - * |
|
| 24 | - * @param integer $roleId |
|
| 25 | - * @param array $permissionIds |
|
| 26 | - * @return object |
|
| 27 | - */ |
|
| 28 | - public function assignPermissions($roleId, $permissionIds) |
|
| 29 | - { |
|
| 30 | - $role = false; |
|
| 31 | - \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 32 | - $role = $this->repo->find($roleId); |
|
| 33 | - $this->repo->detachPermissions($role); |
|
| 34 | - $this->repo->attachPermissions($role, $permissionIds); |
|
| 35 | - }); |
|
| 21 | + /** |
|
| 22 | + * Assign the given permission ids to the given role. |
|
| 23 | + * |
|
| 24 | + * @param integer $roleId |
|
| 25 | + * @param array $permissionIds |
|
| 26 | + * @return object |
|
| 27 | + */ |
|
| 28 | + public function assignPermissions($roleId, $permissionIds) |
|
| 29 | + { |
|
| 30 | + $role = false; |
|
| 31 | + \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 32 | + $role = $this->repo->find($roleId); |
|
| 33 | + $this->repo->detachPermissions($role); |
|
| 34 | + $this->repo->attachPermissions($role, $permissionIds); |
|
| 35 | + }); |
|
| 36 | 36 | |
| 37 | - return $role; |
|
| 38 | - } |
|
| 37 | + return $role; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | public function assignPermissions($roleId, $permissionIds) |
| 29 | 29 | { |
| 30 | 30 | $role = false; |
| 31 | - \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 31 | + \DB::transaction(function() use ($roleId, $permissionIds, &$role) { |
|
| 32 | 32 | $role = $this->repo->find($roleId); |
| 33 | 33 | $this->repo->detachPermissions($role); |
| 34 | 34 | $this->repo->attachPermissions($role, $permissionIds); |
@@ -7,39 +7,39 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RoleRepository extends BaseRepository |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Init new object. |
|
| 12 | - * |
|
| 13 | - * @param Role $model |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function __construct(Role $model) |
|
| 17 | - { |
|
| 18 | - parent::__construct($model); |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * Init new object. |
|
| 12 | + * |
|
| 13 | + * @param Role $model |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function __construct(Role $model) |
|
| 17 | + { |
|
| 18 | + parent::__construct($model); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Detach all permissions from the given role. |
|
| 23 | - * |
|
| 24 | - * @param mixed $role |
|
| 25 | - * @return object |
|
| 26 | - */ |
|
| 27 | - public function detachPermissions($role) |
|
| 28 | - { |
|
| 29 | - $role = ! filter_var($role, FILTER_VALIDATE_INT) ? $role : $this->find($role); |
|
| 30 | - $role->permissions()->detach(); |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Detach all permissions from the given role. |
|
| 23 | + * |
|
| 24 | + * @param mixed $role |
|
| 25 | + * @return object |
|
| 26 | + */ |
|
| 27 | + public function detachPermissions($role) |
|
| 28 | + { |
|
| 29 | + $role = ! filter_var($role, FILTER_VALIDATE_INT) ? $role : $this->find($role); |
|
| 30 | + $role->permissions()->detach(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Attach permission ids to the given role. |
|
| 35 | - * |
|
| 36 | - * @param mixed $role |
|
| 37 | - * @param array $permissionIds |
|
| 38 | - * @return object |
|
| 39 | - */ |
|
| 40 | - public function attachPermissions($role, $permissionIds) |
|
| 41 | - { |
|
| 42 | - $role = ! filter_var($role, FILTER_VALIDATE_INT) ? $role : $this->find($role); |
|
| 43 | - $role->permissions()->attach($permissionIds); |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Attach permission ids to the given role. |
|
| 35 | + * |
|
| 36 | + * @param mixed $role |
|
| 37 | + * @param array $permissionIds |
|
| 38 | + * @return object |
|
| 39 | + */ |
|
| 40 | + public function attachPermissions($role, $permissionIds) |
|
| 41 | + { |
|
| 42 | + $role = ! filter_var($role, FILTER_VALIDATE_INT) ? $role : $this->find($role); |
|
| 43 | + $role->permissions()->attach($permissionIds); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -7,63 +7,63 @@ |
||
| 7 | 7 | |
| 8 | 8 | class OauthClientService extends BaseService |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Init new object. |
|
| 12 | - * |
|
| 13 | - * @param OauthClientRepository $repo |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function __construct(OauthClientRepository $repo) |
|
| 17 | - { |
|
| 18 | - parent::__construct($repo); |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * Init new object. |
|
| 12 | + * |
|
| 13 | + * @param OauthClientRepository $repo |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function __construct(OauthClientRepository $repo) |
|
| 17 | + { |
|
| 18 | + parent::__construct($repo); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Revoke the given client. |
|
| 23 | - * |
|
| 24 | - * @param integer $clientId |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function revoke($clientId) |
|
| 28 | - { |
|
| 29 | - \DB::transaction(function () use ($clientId) { |
|
| 30 | - $client = $this->repo->find($clientId); |
|
| 31 | - $this->repo->revokeClientTokens($client); |
|
| 32 | - $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
| 33 | - }); |
|
| 34 | - } |
|
| 21 | + /** |
|
| 22 | + * Revoke the given client. |
|
| 23 | + * |
|
| 24 | + * @param integer $clientId |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function revoke($clientId) |
|
| 28 | + { |
|
| 29 | + \DB::transaction(function () use ($clientId) { |
|
| 30 | + $client = $this->repo->find($clientId); |
|
| 31 | + $this->repo->revokeClientTokens($client); |
|
| 32 | + $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
| 33 | + }); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * UnRevoke the given client. |
|
| 38 | - * |
|
| 39 | - * @param integer $clientId |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function unRevoke($clientId) |
|
| 43 | - { |
|
| 44 | - $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * UnRevoke the given client. |
|
| 38 | + * |
|
| 39 | + * @param integer $clientId |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function unRevoke($clientId) |
|
| 43 | + { |
|
| 44 | + $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Ensure access token hasn't expired or revoked. |
|
| 49 | - * |
|
| 50 | - * @param string $accessToken |
|
| 51 | - * @return boolean |
|
| 52 | - */ |
|
| 53 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
| 54 | - { |
|
| 55 | - return $this->oauthClientRepository->accessTokenExpiredOrRevoked($accessToken); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * Ensure access token hasn't expired or revoked. |
|
| 49 | + * |
|
| 50 | + * @param string $accessToken |
|
| 51 | + * @return boolean |
|
| 52 | + */ |
|
| 53 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
| 54 | + { |
|
| 55 | + return $this->oauthClientRepository->accessTokenExpiredOrRevoked($accessToken); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Revoke the given access token and all |
|
| 60 | - * associated refresh tokens. |
|
| 61 | - * |
|
| 62 | - * @param oject $accessToken |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public function revokeAccessToken($accessToken) |
|
| 66 | - { |
|
| 67 | - return $this->oauthClientRepository->revokeAccessToken($accessToken); |
|
| 68 | - } |
|
| 58 | + /** |
|
| 59 | + * Revoke the given access token and all |
|
| 60 | + * associated refresh tokens. |
|
| 61 | + * |
|
| 62 | + * @param oject $accessToken |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public function revokeAccessToken($accessToken) |
|
| 66 | + { |
|
| 67 | + return $this->oauthClientRepository->revokeAccessToken($accessToken); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function revoke($clientId) |
| 28 | 28 | { |
| 29 | - \DB::transaction(function () use ($clientId) { |
|
| 29 | + \DB::transaction(function() use ($clientId) { |
|
| 30 | 30 | $client = $this->repo->find($clientId); |
| 31 | 31 | $this->repo->revokeClientTokens($client); |
| 32 | 32 | $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
@@ -7,64 +7,64 @@ |
||
| 7 | 7 | |
| 8 | 8 | class OauthClientRepository extends BaseRepository |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Init new object. |
|
| 12 | - * |
|
| 13 | - * @param OauthClient $model |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function __construct(OauthClient $model) |
|
| 17 | - { |
|
| 18 | - parent::__construct($model); |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * Init new object. |
|
| 12 | + * |
|
| 13 | + * @param OauthClient $model |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function __construct(OauthClient $model) |
|
| 17 | + { |
|
| 18 | + parent::__construct($model); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Revoke the given client tokens. |
|
| 23 | - * |
|
| 24 | - * @param mixed $client |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function revokeClientTokens($client) |
|
| 28 | - { |
|
| 29 | - $client = ! filter_var($client, FILTER_VALIDATE_INT) ? $client : $this->find($client); |
|
| 30 | - $client->tokens()->update(['revoked' => true]); |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Revoke the given client tokens. |
|
| 23 | + * |
|
| 24 | + * @param mixed $client |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function revokeClientTokens($client) |
|
| 28 | + { |
|
| 29 | + $client = ! filter_var($client, FILTER_VALIDATE_INT) ? $client : $this->find($client); |
|
| 30 | + $client->tokens()->update(['revoked' => true]); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Ensure access token hasn't expired or revoked. |
|
| 35 | - * |
|
| 36 | - * @param string $accessToken |
|
| 37 | - * @return boolean |
|
| 38 | - */ |
|
| 39 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
| 40 | - { |
|
| 41 | - $accessTokenId = json_decode($accessToken, true)['id']; |
|
| 42 | - $accessToken = \DB::table('oauth_access_tokens') |
|
| 43 | - ->where('id', $accessTokenId) |
|
| 44 | - ->first(); |
|
| 33 | + /** |
|
| 34 | + * Ensure access token hasn't expired or revoked. |
|
| 35 | + * |
|
| 36 | + * @param string $accessToken |
|
| 37 | + * @return boolean |
|
| 38 | + */ |
|
| 39 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
| 40 | + { |
|
| 41 | + $accessTokenId = json_decode($accessToken, true)['id']; |
|
| 42 | + $accessToken = \DB::table('oauth_access_tokens') |
|
| 43 | + ->where('id', $accessTokenId) |
|
| 44 | + ->first(); |
|
| 45 | 45 | |
| 46 | - if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
| 47 | - return true; |
|
| 48 | - } |
|
| 46 | + if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
| 47 | + return true; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return false; |
|
| 51 | - } |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Revoke the given access token and all |
|
| 55 | - * associated refresh tokens. |
|
| 56 | - * |
|
| 57 | - * @param oject $accessToken |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function revokeAccessToken($accessToken) |
|
| 61 | - { |
|
| 62 | - \DB::table('oauth_refresh_tokens') |
|
| 63 | - ->where('access_token_id', $accessToken->id) |
|
| 64 | - ->update([ |
|
| 65 | - 'revoked' => true |
|
| 66 | - ]); |
|
| 53 | + /** |
|
| 54 | + * Revoke the given access token and all |
|
| 55 | + * associated refresh tokens. |
|
| 56 | + * |
|
| 57 | + * @param oject $accessToken |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function revokeAccessToken($accessToken) |
|
| 61 | + { |
|
| 62 | + \DB::table('oauth_refresh_tokens') |
|
| 63 | + ->where('access_token_id', $accessToken->id) |
|
| 64 | + ->update([ |
|
| 65 | + 'revoked' => true |
|
| 66 | + ]); |
|
| 67 | 67 | |
| 68 | - $accessToken->revoke(); |
|
| 69 | - } |
|
| 68 | + $accessToken->revoke(); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Core implements BaseFactoryInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Construct the repository class name based on |
|
| 11 | - * the method name called, search in the |
|
| 12 | - * given namespaces for the class and |
|
| 13 | - * return an instance. |
|
| 14 | - * |
|
| 15 | - * @param string $name the called method name |
|
| 16 | - * @param array $arguments the method arguments |
|
| 17 | - * @return object |
|
| 18 | - */ |
|
| 19 | - public function __call($name, $arguments) |
|
| 20 | - { |
|
| 21 | - foreach (\Module::all() as $module) { |
|
| 22 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 23 | - $model = ucfirst(\Str::singular($name)); |
|
| 24 | - if(count($arguments) == 1 && $arguments[0]) { |
|
| 25 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
| 26 | - } else { |
|
| 27 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
| 28 | - } |
|
| 9 | + /** |
|
| 10 | + * Construct the repository class name based on |
|
| 11 | + * the method name called, search in the |
|
| 12 | + * given namespaces for the class and |
|
| 13 | + * return an instance. |
|
| 14 | + * |
|
| 15 | + * @param string $name the called method name |
|
| 16 | + * @param array $arguments the method arguments |
|
| 17 | + * @return object |
|
| 18 | + */ |
|
| 19 | + public function __call($name, $arguments) |
|
| 20 | + { |
|
| 21 | + foreach (\Module::all() as $module) { |
|
| 22 | + $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 23 | + $model = ucfirst(\Str::singular($name)); |
|
| 24 | + if(count($arguments) == 1 && $arguments[0]) { |
|
| 25 | + $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
| 26 | + } else { |
|
| 27 | + $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - if (class_exists($class)) { |
|
| 31 | - return \App::make($class); |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - } |
|
| 30 | + if (class_exists($class)) { |
|
| 31 | + return \App::make($class); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -19,12 +19,12 @@ |
||
| 19 | 19 | public function __call($name, $arguments) |
| 20 | 20 | { |
| 21 | 21 | foreach (\Module::all() as $module) { |
| 22 | - $nameSpace = 'App\\Modules\\' . $module['basename'] ; |
|
| 22 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
| 23 | 23 | $model = ucfirst(\Str::singular($name)); |
| 24 | - if(count($arguments) == 1 && $arguments[0]) { |
|
| 25 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
| 24 | + if (count($arguments) == 1 && $arguments[0]) { |
|
| 25 | + $class = $nameSpace.'\\Services\\'.$model.'Service'; |
|
| 26 | 26 | } else { |
| 27 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
| 27 | + $class = $nameSpace.'\\Repositories\\'.$model.'Repository'; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | if (class_exists($class)) { |
@@ -4,46 +4,46 @@ |
||
| 4 | 4 | |
| 5 | 5 | trait Translatable |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Create a new model instance that is existing. |
|
| 9 | - * |
|
| 10 | - * @param array $attributes |
|
| 11 | - * @param string|null $connection |
|
| 12 | - * @return static |
|
| 13 | - */ |
|
| 14 | - public function newFromBuilder($attributes = [], $connection = null) |
|
| 15 | - { |
|
| 16 | - $model = parent::newFromBuilder($attributes, $connection); |
|
| 17 | - |
|
| 18 | - foreach ($model->attributes as $key => $value) { |
|
| 19 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
| 20 | - $model->$key = $this->getTranslatedAttribute($value); |
|
| 21 | - } |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - return $model; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | - * |
|
| 30 | - * @param $values |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - protected function getTranslatedAttribute($values) |
|
| 34 | - { |
|
| 35 | - $values = json_decode($values); |
|
| 36 | - $primaryLocale = \Session::get('locale'); |
|
| 37 | - $fallbackLocale = 'en'; |
|
| 38 | - |
|
| 39 | - if ($primaryLocale == 'all') { |
|
| 40 | - return $values; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 44 | - return $values ? (isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values) : ''; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 48 | - } |
|
| 7 | + /** |
|
| 8 | + * Create a new model instance that is existing. |
|
| 9 | + * |
|
| 10 | + * @param array $attributes |
|
| 11 | + * @param string|null $connection |
|
| 12 | + * @return static |
|
| 13 | + */ |
|
| 14 | + public function newFromBuilder($attributes = [], $connection = null) |
|
| 15 | + { |
|
| 16 | + $model = parent::newFromBuilder($attributes, $connection); |
|
| 17 | + |
|
| 18 | + foreach ($model->attributes as $key => $value) { |
|
| 19 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
| 20 | + $model->$key = $this->getTranslatedAttribute($value); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + return $model; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | + * |
|
| 30 | + * @param $values |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + protected function getTranslatedAttribute($values) |
|
| 34 | + { |
|
| 35 | + $values = json_decode($values); |
|
| 36 | + $primaryLocale = \Session::get('locale'); |
|
| 37 | + $fallbackLocale = 'en'; |
|
| 38 | + |
|
| 39 | + if ($primaryLocale == 'all') { |
|
| 40 | + return $values; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 44 | + return $values ? (isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values) : ''; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | return $values; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 43 | + if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
| 44 | 44 | return $values ? (isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values) : ''; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -6,223 +6,223 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class BaseService implements BaseServiceInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var object |
|
| 11 | - */ |
|
| 12 | - public $repo; |
|
| 9 | + /** |
|
| 10 | + * @var object |
|
| 11 | + */ |
|
| 12 | + public $repo; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Init new object. |
|
| 16 | - * |
|
| 17 | - * @param mixed $repo |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - public function __construct($repo) |
|
| 21 | - { |
|
| 22 | - $this->repo = $repo; |
|
| 23 | - } |
|
| 14 | + /** |
|
| 15 | + * Init new object. |
|
| 16 | + * |
|
| 17 | + * @param mixed $repo |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + public function __construct($repo) |
|
| 21 | + { |
|
| 22 | + $this->repo = $repo; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Fetch records with relations based on the given params. |
|
| 27 | - * |
|
| 28 | - * @param array $relations |
|
| 29 | - * @param array $conditions |
|
| 30 | - * @param integer $perPage |
|
| 31 | - * @param string $sortBy |
|
| 32 | - * @param boolean $desc |
|
| 33 | - * @param boolean $trashed |
|
| 34 | - * @return collection |
|
| 35 | - */ |
|
| 36 | - public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false) |
|
| 37 | - { |
|
| 38 | - $translatable = $this->repo->model->translatable ?? []; |
|
| 39 | - $filters = $this->constructFilters($conditions); |
|
| 40 | - $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy; |
|
| 25 | + /** |
|
| 26 | + * Fetch records with relations based on the given params. |
|
| 27 | + * |
|
| 28 | + * @param array $relations |
|
| 29 | + * @param array $conditions |
|
| 30 | + * @param integer $perPage |
|
| 31 | + * @param string $sortBy |
|
| 32 | + * @param boolean $desc |
|
| 33 | + * @param boolean $trashed |
|
| 34 | + * @return collection |
|
| 35 | + */ |
|
| 36 | + public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false) |
|
| 37 | + { |
|
| 38 | + $translatable = $this->repo->model->translatable ?? []; |
|
| 39 | + $filters = $this->constructFilters($conditions); |
|
| 40 | + $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy; |
|
| 41 | 41 | |
| 42 | - if ($trashed) { |
|
| 43 | - return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true); |
|
| 44 | - } |
|
| 42 | + if ($trashed) { |
|
| 43 | + return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if (count($filters)) { |
|
| 47 | - return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
| 48 | - } |
|
| 46 | + if (count($filters)) { |
|
| 47 | + return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
| 51 | - } |
|
| 50 | + return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Fetch all records with relations from the storage. |
|
| 55 | - * |
|
| 56 | - * @param array $relations |
|
| 57 | - * @param string $sortBy |
|
| 58 | - * @param boolean $desc |
|
| 59 | - * @param array $columns |
|
| 60 | - * @return collection |
|
| 61 | - */ |
|
| 62 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 63 | - { |
|
| 64 | - return $this->repo->all($relations, $sortBy, $desc, $columns); |
|
| 65 | - } |
|
| 53 | + /** |
|
| 54 | + * Fetch all records with relations from the storage. |
|
| 55 | + * |
|
| 56 | + * @param array $relations |
|
| 57 | + * @param string $sortBy |
|
| 58 | + * @param boolean $desc |
|
| 59 | + * @param array $columns |
|
| 60 | + * @return collection |
|
| 61 | + */ |
|
| 62 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 63 | + { |
|
| 64 | + return $this->repo->all($relations, $sortBy, $desc, $columns); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Fetch all records with relations from storage in pages. |
|
| 69 | - * |
|
| 70 | - * @param integer $perPage |
|
| 71 | - * @param array $relations |
|
| 72 | - * @param string $sortBy |
|
| 73 | - * @param boolean $desc |
|
| 74 | - * @param array $columns |
|
| 75 | - * @return collection |
|
| 76 | - */ |
|
| 77 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 78 | - { |
|
| 79 | - return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns); |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * Fetch all records with relations from storage in pages. |
|
| 69 | + * |
|
| 70 | + * @param integer $perPage |
|
| 71 | + * @param array $relations |
|
| 72 | + * @param string $sortBy |
|
| 73 | + * @param boolean $desc |
|
| 74 | + * @param array $columns |
|
| 75 | + * @return collection |
|
| 76 | + */ |
|
| 77 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 78 | + { |
|
| 79 | + return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Fetch all records with relations based on |
|
| 84 | - * the given condition from storage in pages. |
|
| 85 | - * |
|
| 86 | - * @param array $conditions array of conditions |
|
| 87 | - * @param integer $perPage |
|
| 88 | - * @param array $relations |
|
| 89 | - * @param string $sortBy |
|
| 90 | - * @param boolean $desc |
|
| 91 | - * @param array $columns |
|
| 92 | - * @return collection |
|
| 93 | - */ |
|
| 94 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 95 | - { |
|
| 96 | - return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 97 | - } |
|
| 82 | + /** |
|
| 83 | + * Fetch all records with relations based on |
|
| 84 | + * the given condition from storage in pages. |
|
| 85 | + * |
|
| 86 | + * @param array $conditions array of conditions |
|
| 87 | + * @param integer $perPage |
|
| 88 | + * @param array $relations |
|
| 89 | + * @param string $sortBy |
|
| 90 | + * @param boolean $desc |
|
| 91 | + * @param array $columns |
|
| 92 | + * @return collection |
|
| 93 | + */ |
|
| 94 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 95 | + { |
|
| 96 | + return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Save the given model to the storage. |
|
| 101 | - * |
|
| 102 | - * @param array $data |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function save(array $data) |
|
| 106 | - { |
|
| 107 | - return $this->repo->save($data); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * Save the given model to the storage. |
|
| 101 | + * |
|
| 102 | + * @param array $data |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function save(array $data) |
|
| 106 | + { |
|
| 107 | + return $this->repo->save($data); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Delete record from the storage based on the given |
|
| 112 | - * condition. |
|
| 113 | - * |
|
| 114 | - * @param var $value condition value |
|
| 115 | - * @param string $attribute condition column name |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - public function delete($value, $attribute = 'id') |
|
| 119 | - { |
|
| 120 | - return $this->repo->delete($value, $attribute); |
|
| 121 | - } |
|
| 110 | + /** |
|
| 111 | + * Delete record from the storage based on the given |
|
| 112 | + * condition. |
|
| 113 | + * |
|
| 114 | + * @param var $value condition value |
|
| 115 | + * @param string $attribute condition column name |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + public function delete($value, $attribute = 'id') |
|
| 119 | + { |
|
| 120 | + return $this->repo->delete($value, $attribute); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Fetch records from the storage based on the given |
|
| 125 | - * id. |
|
| 126 | - * |
|
| 127 | - * @param integer $id |
|
| 128 | - * @param array $relations |
|
| 129 | - * @param array $columns |
|
| 130 | - * @return object |
|
| 131 | - */ |
|
| 132 | - public function find($id, $relations = [], $columns = ['*']) |
|
| 133 | - { |
|
| 134 | - return $this->repo->find($id, $relations, $columns); |
|
| 135 | - } |
|
| 123 | + /** |
|
| 124 | + * Fetch records from the storage based on the given |
|
| 125 | + * id. |
|
| 126 | + * |
|
| 127 | + * @param integer $id |
|
| 128 | + * @param array $relations |
|
| 129 | + * @param array $columns |
|
| 130 | + * @return object |
|
| 131 | + */ |
|
| 132 | + public function find($id, $relations = [], $columns = ['*']) |
|
| 133 | + { |
|
| 134 | + return $this->repo->find($id, $relations, $columns); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Fetch records from the storage based on the given |
|
| 139 | - * condition. |
|
| 140 | - * |
|
| 141 | - * @param array $conditions array of conditions |
|
| 142 | - * @param array $relations |
|
| 143 | - * @param string $sortBy |
|
| 144 | - * @param boolean $desc |
|
| 145 | - * @param array $columns |
|
| 146 | - * @return collection |
|
| 147 | - */ |
|
| 148 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 149 | - { |
|
| 150 | - return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns); |
|
| 151 | - } |
|
| 137 | + /** |
|
| 138 | + * Fetch records from the storage based on the given |
|
| 139 | + * condition. |
|
| 140 | + * |
|
| 141 | + * @param array $conditions array of conditions |
|
| 142 | + * @param array $relations |
|
| 143 | + * @param string $sortBy |
|
| 144 | + * @param boolean $desc |
|
| 145 | + * @param array $columns |
|
| 146 | + * @return collection |
|
| 147 | + */ |
|
| 148 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 149 | + { |
|
| 150 | + return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Fetch the first record from the storage based on the given |
|
| 155 | - * condition. |
|
| 156 | - * |
|
| 157 | - * @param array $conditions array of conditions |
|
| 158 | - * @param array $relations |
|
| 159 | - * @param array $columns |
|
| 160 | - * @return object |
|
| 161 | - */ |
|
| 162 | - public function first($conditions, $relations = [], $columns = ['*']) |
|
| 163 | - { |
|
| 164 | - return $this->repo->first($conditions, $relations, $columns); |
|
| 165 | - } |
|
| 153 | + /** |
|
| 154 | + * Fetch the first record from the storage based on the given |
|
| 155 | + * condition. |
|
| 156 | + * |
|
| 157 | + * @param array $conditions array of conditions |
|
| 158 | + * @param array $relations |
|
| 159 | + * @param array $columns |
|
| 160 | + * @return object |
|
| 161 | + */ |
|
| 162 | + public function first($conditions, $relations = [], $columns = ['*']) |
|
| 163 | + { |
|
| 164 | + return $this->repo->first($conditions, $relations, $columns); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Return the deleted models in pages based on the given conditions. |
|
| 169 | - * |
|
| 170 | - * @param array $conditions array of conditions |
|
| 171 | - * @param integer $perPage |
|
| 172 | - * @param string $sortBy |
|
| 173 | - * @param boolean $desc |
|
| 174 | - * @param array $columns |
|
| 175 | - * @return collection |
|
| 176 | - */ |
|
| 177 | - public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 178 | - { |
|
| 179 | - return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns); |
|
| 180 | - } |
|
| 167 | + /** |
|
| 168 | + * Return the deleted models in pages based on the given conditions. |
|
| 169 | + * |
|
| 170 | + * @param array $conditions array of conditions |
|
| 171 | + * @param integer $perPage |
|
| 172 | + * @param string $sortBy |
|
| 173 | + * @param boolean $desc |
|
| 174 | + * @param array $columns |
|
| 175 | + * @return collection |
|
| 176 | + */ |
|
| 177 | + public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 178 | + { |
|
| 179 | + return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Restore the deleted model. |
|
| 184 | - * |
|
| 185 | - * @param integer $id |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - public function restore($id) |
|
| 189 | - { |
|
| 190 | - return $this->repo->restore($id); |
|
| 191 | - } |
|
| 182 | + /** |
|
| 183 | + * Restore the deleted model. |
|
| 184 | + * |
|
| 185 | + * @param integer $id |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + public function restore($id) |
|
| 189 | + { |
|
| 190 | + return $this->repo->restore($id); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Prepare filters for repo. |
|
| 195 | - * |
|
| 196 | - * @param array $conditions |
|
| 197 | - * @return array |
|
| 198 | - */ |
|
| 199 | - public function constructFilters($conditions) |
|
| 200 | - { |
|
| 201 | - $filters = []; |
|
| 202 | - $translatable = $this->repo->model->translatable ?? []; |
|
| 203 | - foreach ($conditions as $key => $value) { |
|
| 204 | - if ((in_array($key, $this->repo->model->fillable ?? []) || method_exists($this->repo->model, $key) || in_array($key, ['or', 'and'])) && $key !== 'trashed') { |
|
| 205 | - $key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key; |
|
| 206 | - if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) { |
|
| 207 | - $filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
| 208 | - } elseif (! is_array($value) && strpos($key, '_id')) { |
|
| 209 | - $filters[$key] = [ |
|
| 210 | - 'op' => 'in', |
|
| 211 | - 'val' => explode(',', $value) |
|
| 212 | - ]; |
|
| 213 | - } elseif (is_array($value)) { |
|
| 214 | - $filters[$key] = $value; |
|
| 215 | - } elseif($value) { |
|
| 216 | - $key = 'LOWER(' . $key . ')'; |
|
| 217 | - $value = strtolower($value); |
|
| 218 | - $filters[$key] = [ |
|
| 219 | - 'op' => 'like', |
|
| 220 | - 'val' => '%' . $value . '%' |
|
| 221 | - ]; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 193 | + /** |
|
| 194 | + * Prepare filters for repo. |
|
| 195 | + * |
|
| 196 | + * @param array $conditions |
|
| 197 | + * @return array |
|
| 198 | + */ |
|
| 199 | + public function constructFilters($conditions) |
|
| 200 | + { |
|
| 201 | + $filters = []; |
|
| 202 | + $translatable = $this->repo->model->translatable ?? []; |
|
| 203 | + foreach ($conditions as $key => $value) { |
|
| 204 | + if ((in_array($key, $this->repo->model->fillable ?? []) || method_exists($this->repo->model, $key) || in_array($key, ['or', 'and'])) && $key !== 'trashed') { |
|
| 205 | + $key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key; |
|
| 206 | + if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) { |
|
| 207 | + $filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
| 208 | + } elseif (! is_array($value) && strpos($key, '_id')) { |
|
| 209 | + $filters[$key] = [ |
|
| 210 | + 'op' => 'in', |
|
| 211 | + 'val' => explode(',', $value) |
|
| 212 | + ]; |
|
| 213 | + } elseif (is_array($value)) { |
|
| 214 | + $filters[$key] = $value; |
|
| 215 | + } elseif($value) { |
|
| 216 | + $key = 'LOWER(' . $key . ')'; |
|
| 217 | + $value = strtolower($value); |
|
| 218 | + $filters[$key] = [ |
|
| 219 | + 'op' => 'like', |
|
| 220 | + 'val' => '%' . $value . '%' |
|
| 221 | + ]; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - return $filters; |
|
| 227 | - } |
|
| 226 | + return $filters; |
|
| 227 | + } |
|
| 228 | 228 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $translatable = $this->repo->model->translatable ?? []; |
| 39 | 39 | $filters = $this->constructFilters($conditions); |
| 40 | - $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy; |
|
| 40 | + $sortBy = in_array($sortBy, $translatable) ? $sortBy.'->'.\Session::get('locale') : $sortBy; |
|
| 41 | 41 | |
| 42 | 42 | if ($trashed) { |
| 43 | 43 | return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true); |
@@ -202,22 +202,22 @@ discard block |
||
| 202 | 202 | $translatable = $this->repo->model->translatable ?? []; |
| 203 | 203 | foreach ($conditions as $key => $value) { |
| 204 | 204 | if ((in_array($key, $this->repo->model->fillable ?? []) || method_exists($this->repo->model, $key) || in_array($key, ['or', 'and'])) && $key !== 'trashed') { |
| 205 | - $key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key; |
|
| 205 | + $key = in_array($key, $translatable) ? $key.'->'.(\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key; |
|
| 206 | 206 | if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) { |
| 207 | 207 | $filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN); |
| 208 | - } elseif (! is_array($value) && strpos($key, '_id')) { |
|
| 208 | + } elseif ( ! is_array($value) && strpos($key, '_id')) { |
|
| 209 | 209 | $filters[$key] = [ |
| 210 | 210 | 'op' => 'in', |
| 211 | 211 | 'val' => explode(',', $value) |
| 212 | 212 | ]; |
| 213 | 213 | } elseif (is_array($value)) { |
| 214 | 214 | $filters[$key] = $value; |
| 215 | - } elseif($value) { |
|
| 216 | - $key = 'LOWER(' . $key . ')'; |
|
| 215 | + } elseif ($value) { |
|
| 216 | + $key = 'LOWER('.$key.')'; |
|
| 217 | 217 | $value = strtolower($value); |
| 218 | 218 | $filters[$key] = [ |
| 219 | 219 | 'op' => 'like', |
| 220 | - 'val' => '%' . $value . '%' |
|
| 220 | + 'val' => '%'.$value.'%' |
|
| 221 | 221 | ]; |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -7,84 +7,84 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CachingDecorator |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var String |
|
| 12 | - */ |
|
| 13 | - public $service; |
|
| 10 | + /** |
|
| 11 | + * @var String |
|
| 12 | + */ |
|
| 13 | + public $service; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var Cache |
|
| 17 | - */ |
|
| 18 | - protected $cache; |
|
| 15 | + /** |
|
| 16 | + * @var Cache |
|
| 17 | + */ |
|
| 18 | + protected $cache; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var mixed |
|
| 22 | - */ |
|
| 23 | - public $cacheConfig; |
|
| 20 | + /** |
|
| 21 | + * @var mixed |
|
| 22 | + */ |
|
| 23 | + public $cacheConfig; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - public $cacheTag; |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + public $cacheTag; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Init new object. |
|
| 32 | - * |
|
| 33 | - * @param Object $service |
|
| 34 | - * @param Cache $cache |
|
| 35 | - * |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public function __construct($service, Cache $cache) |
|
| 39 | - { |
|
| 40 | - $this->service = $service; |
|
| 41 | - $this->cache = $cache; |
|
| 42 | - $serviceClass = explode('\\', get_class($this->service)); |
|
| 43 | - $serviceName = end($serviceClass); |
|
| 44 | - $this->cacheTag = lcfirst(substr($serviceName, 0, strpos($serviceName, 'Service'))); |
|
| 45 | - } |
|
| 30 | + /** |
|
| 31 | + * Init new object. |
|
| 32 | + * |
|
| 33 | + * @param Object $service |
|
| 34 | + * @param Cache $cache |
|
| 35 | + * |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public function __construct($service, Cache $cache) |
|
| 39 | + { |
|
| 40 | + $this->service = $service; |
|
| 41 | + $this->cache = $cache; |
|
| 42 | + $serviceClass = explode('\\', get_class($this->service)); |
|
| 43 | + $serviceName = end($serviceClass); |
|
| 44 | + $this->cacheTag = lcfirst(substr($serviceName, 0, strpos($serviceName, 'Service'))); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Handle the cache mechanism for the called method |
|
| 49 | - * based the configurations. |
|
| 50 | - * |
|
| 51 | - * @param string $name the called method name |
|
| 52 | - * @param array $arguments the method arguments |
|
| 53 | - * @return object |
|
| 54 | - */ |
|
| 55 | - public function __call($name, $arguments) |
|
| 56 | - { |
|
| 57 | - $this->setCacheConfig($name); |
|
| 47 | + /** |
|
| 48 | + * Handle the cache mechanism for the called method |
|
| 49 | + * based the configurations. |
|
| 50 | + * |
|
| 51 | + * @param string $name the called method name |
|
| 52 | + * @param array $arguments the method arguments |
|
| 53 | + * @return object |
|
| 54 | + */ |
|
| 55 | + public function __call($name, $arguments) |
|
| 56 | + { |
|
| 57 | + $this->setCacheConfig($name); |
|
| 58 | 58 | |
| 59 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
| 60 | - $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
| 61 | - $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
| 62 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
| 63 | - return call_user_func_array([$this->service, $name], $arguments); |
|
| 64 | - }); |
|
| 65 | - } elseif ($this->cacheConfig) { |
|
| 66 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
| 67 | - return call_user_func_array([$this->service, $name], $arguments); |
|
| 68 | - } |
|
| 59 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
| 60 | + $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
| 61 | + $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
| 62 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
| 63 | + return call_user_func_array([$this->service, $name], $arguments); |
|
| 64 | + }); |
|
| 65 | + } elseif ($this->cacheConfig) { |
|
| 66 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
| 67 | + return call_user_func_array([$this->service, $name], $arguments); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - return call_user_func_array([$this->service, $name], $arguments); |
|
| 71 | - } |
|
| 70 | + return call_user_func_array([$this->service, $name], $arguments); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Set cache config based on the called method. |
|
| 75 | - * |
|
| 76 | - * @param string $name |
|
| 77 | - * @return void |
|
| 78 | - */ |
|
| 79 | - private function setCacheConfig($name) |
|
| 80 | - { |
|
| 81 | - $cacheConfig = Arr::get(config('core.cache_config'), $this->cacheTag, false); |
|
| 82 | - $this->cacheConfig = false; |
|
| 73 | + /** |
|
| 74 | + * Set cache config based on the called method. |
|
| 75 | + * |
|
| 76 | + * @param string $name |
|
| 77 | + * @return void |
|
| 78 | + */ |
|
| 79 | + private function setCacheConfig($name) |
|
| 80 | + { |
|
| 81 | + $cacheConfig = Arr::get(config('core.cache_config'), $this->cacheTag, false); |
|
| 82 | + $this->cacheConfig = false; |
|
| 83 | 83 | |
| 84 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
| 85 | - $this->cacheConfig = 'cache'; |
|
| 86 | - } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
| 87 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
| 88 | - } |
|
| 89 | - } |
|
| 84 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
| 85 | + $this->cacheConfig = 'cache'; |
|
| 86 | + } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
| 87 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | } |