composition.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
<?php | |
class RequestId | |
{ | |
} | |
class ClientId | |
{ | |
} | |
class AgencyId | |
{ | |
} | |
class AgencyUserId | |
{ | |
} | |
class ServiceId | |
{ | |
} | |
class Deps | |
{ | |
public function __construct( | |
public ?RequestId $requestId = null, | |
public ?ClientId $clientId = null, | |
public ?AgencyId $agencyId = null, | |
public ?AgencyUserId $agencyUserId = null, | |
public ?ServiceId $serviceId = null, | |
) { | |
} | |
public function unpack(): array | |
{ | |
return array_filter([ | |
'requestId' => $this->requestId ?? null, | |
'clientId' => $this->clientId ?? null, | |
'agencyId' => $this->agencyId ?? null, | |
'agencyUserId' => $this->agencyUserId ?? null, | |
'serviceId' => $this->serviceId ?? null, | |
]); | |
} | |
} | |
class Opened | |
{ | |
public function __construct( | |
public RequestId $requestId, | |
public ClientId $clientId, | |
public ServiceId $serviceId, | |
) { | |
} | |
} | |
function deps(...$things): array | |
{ | |
return (new Deps(...$things))->unpack(); | |
} | |
$opened = new Opened(...deps( | |
requestId: new RequestId(), | |
clientId: new ClientId(), | |
serviceId: new ServiceId(), | |
)); | |
print_r($opened); |