Skip to content

Commit

Permalink
Implemented singleton functionality in ObjectFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-nijens committed Jan 6, 2015
1 parent ba1cd31 commit e7a2bf2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@
**/
class ObjectFactory
{
/**
* The ObjectFactory instance
*
* @access private
* @var ObjectFactory
**/
private static $instance;

/**
* getInstance
*
* Returns the ObjectFactory instance
*
* @access public
* @return ObjectFactory
**/
public static function getInstance()
{
$class = new ReflectionClass(get_called_class() );
if ($class->isInstance(static::$instance) === false) {
static::$instance = $class->newInstanceArgs(func_get_args() );
}

return static::$instance;
}

/**
* newInstance
*
Expand Down

0 comments on commit e7a2bf2

Please sign in to comment.