Last active
September 10, 2018 12:26
-
-
Save Majkl578/31ef8549b7e79d5878ac806acb3f3277 to your computer and use it in GitHub Desktop.
typed factory
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 | |
declare(strict_Types=1); | |
namespace Example; | |
(function () : void { | |
$requestFactory = new class implements ServerRequestFactory { | |
public function __invoke() : ServerRequest | |
{ | |
return SpecificServerRequest(123, 456); | |
} | |
}; | |
(new RequestHandlerRunner($requestFactory))->run(); | |
})(); |
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 | |
declare(strict_Types=1); | |
namespace Example; | |
final class RequestHandlerRunner | |
{ | |
/** ServerRequestFactory */ | |
private $requestFactory; | |
public function __construct(ServerRequestFactory $requestFactory) | |
{ | |
$this->requestFactory = $requestFactory; | |
} | |
public function run() : void | |
{ | |
$request = ($this->requestFactory)(); | |
// doi stuff with ServerRequest | |
} | |
} |
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 | |
declare(strict_Types=1); | |
namespace Example; | |
interface ServerRequestFactory | |
{ | |
public function __invoke() : ServerRequest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment