Created
August 8, 2018 12:01
-
-
Save roquie/8b1170f345e62a46480ab16d073642cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// file1 | |
// bind UserRepositoryInterface to EloquentUserRepository object | |
class EloquentUserRepository extends UserRepositoryInterface | |
{ | |
// ... | |
public function all() | |
{ | |
return $this->model->all(); | |
} | |
public function allForAgent() | |
{ | |
return $this->model->where('type', 'agent')->all(); | |
} | |
public function allForOtherRole() | |
{ | |
// ..... | |
} | |
} | |
// file2 | |
class UserService extends UserServiceInterface | |
{ | |
protected $auth; | |
protected $repo; | |
public function __construct(Authentificable $auth, UserRepositoryInterface $repo) | |
{ | |
$this->auth = $auth; | |
$this->repo = $repo; | |
} | |
public function getUsers() | |
{ | |
if ($this->auth->inRole('admin')) { | |
return $this->repo->all(); | |
} elseif ($this->auth->inRole('agent')) { | |
return $this->repo->allForAgent(); | |
} elseif (/* other checks */) { | |
return /* other methods */; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment