Beispiel #1
0
 /**
  * Create an instance of a class
  * @param string $className The class name to create
  * @param array $params (optional) An array of arguments to be passed to the constructor.
  * @return object Returns the instance of the class created.
  * @since 1.2.0
  */
 public function instantiate($className, $params = array())
 {
     $class = new \ReflectionClass($className);
     $constructor = $class->getConstructor();
     $result = null;
     if ($constructor) {
         $arguments = Container::buildDependencies($this, $constructor, $params);
         $result = $class->newInstanceArgs($arguments);
     } else {
         $result = $class->newInstance();
     }
     if ($result instanceof ConsumerInterface) {
         $result($this);
     }
     return $result;
 }