Page MenuHomePhabricator
Paste P45879

adapter interface and adapter classes
ActivePublic

Authored by jgleeson on Mar 15 2023, 10:30 PM.
Tags
None
Referenced Files
F36913662: adapter interface and adapter classes
Mar 15 2023, 10:30 PM
Subscribers
None
// Adapter Interface
interface UserAdapter {
public function getUser($userId);
}
// Adapter Class for External System 1
class ExternalSystem1Adapter implements UserAdapter {
private $gateway;
public function __construct(UserGateway $gateway) {
$this->gateway = $gateway;
}
public function getUser($userId) {
$userData = $this->gateway->getUserData($userId);
return [
'id' => $userData['id'],
'name' => $userData['name'],
'email' => $userData['email']
];
}
}
// Adapter Class for External System 2
class ExternalSystem2Adapter implements UserAdapter {
private $gateway;
public function __construct(UserGateway $gateway) {
$this->gateway = $gateway;
}
public function getUser($userId) {
$userData = $this->gateway->getUserData($userId);
return [
'id' => $userData['userId'],
'name' => $userData['userName'],
'email' => $userData['userEmail']
];
}
}