Last active
January 13, 2022 06:41
-
-
Save assertchris/90d75771397ae2dbf5fed26a9148e0b4 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 | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment