Skip to content

Instantly share code, notes, and snippets.

@finwe
Created June 3, 2019 13:38
Show Gist options
  • Save finwe/39c15fce99e61b10a1f9e64fb0f7f717 to your computer and use it in GitHub Desktop.
Save finwe/39c15fce99e61b10a1f9e64fb0f7f717 to your computer and use it in GitHub Desktop.
<?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