Created
April 8, 2022 10:42
-
-
Save localheinz/2d47fbcde3852febc0772d0e366e355e to your computer and use it in GitHub Desktop.
sleeper
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 | |
interface Sleeper | |
{ | |
public function sleep(int $seconds): void; | |
} | |
final class SystemSleeper implements Sleeper | |
{ | |
public function sleep(int $seconds): void | |
{ | |
sleep($seconds); | |
} | |
} | |
final class NullSleeper implements Sleeper | |
{ | |
public function sleep(int $seconds): void | |
{ | |
} | |
} | |
final class ServiceThatNeedsToSleep | |
{ | |
public function __construct(private Sleeper $sleeper) | |
{ | |
} | |
public function doSomething(): void | |
{ | |
// ... | |
$this->sleeper->sleep(3); | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment