public newInstance ( string $className, string | null $sessionId = null, array $args = [] ) : object | ||
$className | string | The fully qualified class name to return the instance for |
$sessionId | string | null | The session-ID, necessary to inject stateful session beans (SFBs) |
$args | array | Arguments to pass to the constructor of the instance |
return | object | The instance itself |
public function newInstance($className, $sessionId = null, array $args = array())
{
// load/create and return a new instance
$reflectionClass = $this->getReflectionClass($className);
// check if we've a constructor
if ($reflectionClass->hasMethod('__construct')) {
$instance = $reflectionClass->newInstanceArgs($args);
} else {
$instance = $reflectionClass->newInstance();
}
// inject the dependencies
$this->injectDependencies($instance, $sessionId);
// return the instance here
return $instance;
}