PHPSpec2\Subject\LazyObject::getInstance PHP Method

getInstance() public method

public getInstance ( )
    public function getInstance()
    {
        if ($this->instance) {
            return $this->instance;
        }
        if (null === $this->classname || !is_string($this->classname)) {
            throw new Exception(sprintf('Instantiator expects class name, "%s" got', gettype($this->classname)));
        }
        if (!class_exists($this->classname)) {
            throw new ClassNotFoundException($this->classname);
        }
        $reflection = new ReflectionClass($this->classname);
        return $this->instance = $reflection->newInstanceArgs($this->arguments);
    }

Usage Example

Example #1
0
 public function getInstance()
 {
     $instance = parent::getInstance();
     if (!method_exists($instance, $this->method) && !method_exists($instance, '__call')) {
         throw new MethodNotFoundException($instance, $this->method);
     }
     return call_user_func_array(array($instance, $this->method), $this->arguments);
 }