Last active
April 25, 2022 15:50
-
-
Save nicolasdanelon/ddb314169ee41eecba66db04d8a84e2c to your computer and use it in GitHub Desktop.
user.php
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
// https://www.wikiwand.com/es/SOLID | |
// Service Repository Pattern | |
class User { | |
private string $name; | |
} | |
class UserRepository { | |
public function getUserName(int $id): string | |
{ | |
return User::findById($id)->name; | |
} | |
} | |
class UserSerice { | |
function __constructor() { | |
$this->repo = new UserRepository(); | |
} | |
public function getUserName(int $id): string | |
{ | |
// Bussiness Logic | |
return $this->repo->getUserName($id); | |
} | |
} | |
class BackendUserController { | |
public function index(UserSerice $service) { | |
// Backend logic | |
$nameOfTheUser = $service->getUserName(4); | |
} | |
} | |
class APIUserController { | |
public function index(UserSerice $service) { | |
// API logic | |
$nameOfTheUser = $service->getUserName(4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment