Skip to content

Instantly share code, notes, and snippets.

@nicolasdanelon
Last active April 25, 2022 15:50
Show Gist options
  • Save nicolasdanelon/ddb314169ee41eecba66db04d8a84e2c to your computer and use it in GitHub Desktop.
Save nicolasdanelon/ddb314169ee41eecba66db04d8a84e2c to your computer and use it in GitHub Desktop.
user.php
// 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