Created
June 3, 2019 13:38
-
-
Save finwe/39c15fce99e61b10a1f9e64fb0f7f717 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Thing | |
{ | |
public function whatever(); | |
} | |
class ThingFactory | |
{ | |
private $things; | |
/** | |
* @param \Thing[] $things name => instance link | |
*/ | |
public function __construct($things) | |
{ | |
$this->things = $things; | |
} | |
public function make(string $kind): Thing | |
{ | |
if (!isset($this->things[$kind])) { | |
throw new \InvalidArgumentException('...'); | |
} | |
return $this->things[$kind]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment