Created
July 30, 2015 14:11
-
-
Save shadowhand/e690fc1c2de38b3fcb2f to your computer and use it in GitHub Desktop.
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 | |
namespace JAAulde\IP\V4; | |
class IpFactory | |
{ | |
/** | |
* @var array | |
*/ | |
private $specs = [ | |
'Address' => 'JAAulde\IP\V4\Address', | |
'Block' => 'JAAulde\IP\V4\Block', | |
'Range' => 'JAAulde\IP\V4\Range', | |
'SubnetMask' => 'JAAulde\IP\V4\SubnetMask', | |
]; | |
/** | |
* @param array $overload Specs to be overloaded with custom classes. | |
*/ | |
public function __construct(array $overload = []) | |
{ | |
if ($overload) { | |
$this->specs = array_replace($this->specs, $overload); | |
} | |
} | |
/** | |
* Create a new instance of a class. | |
* @param string $spec | |
* @param array $args | |
* @return object | |
*/ | |
public function make($spec, array $args = []) | |
{ | |
$class = new \ReflectionClass($this->specs[$spec]) | |
return $class->newInstanceArgs($args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment