Skip to content

Instantly share code, notes, and snippets.

@assertchris
Last active January 13, 2022 06:41
Show Gist options
  • Save assertchris/90d75771397ae2dbf5fed26a9148e0b4 to your computer and use it in GitHub Desktop.
Save assertchris/90d75771397ae2dbf5fed26a9148e0b4 to your computer and use it in GitHub Desktop.
<?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