Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created July 30, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowhand/e690fc1c2de38b3fcb2f to your computer and use it in GitHub Desktop.
Save shadowhand/e690fc1c2de38b3fcb2f to your computer and use it in GitHub Desktop.
<?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