Intercepts any method and injects instances of the missing arguments
when they are type hinted

@return object
188820
public function invoke(MethodInvocation $invocation)
    {
        /** @var ReflectionMethod $method */
        $method = $invocation->getMethod();
        $assisted = $method->getAnnotation(Assisted::class);
        /* @var \Ray\Di\Di\Assisted $assisted */
        $parameters = $method->getParameters();
        $arguments = $invocation->getArguments()->getArrayCopy();
        if ($assisted instanceof Assisted && $method instanceof ReflectionMethod) {
            $this->methodInvocationProvider->set($invocation);
            $arguments = $this->injectAssistedParameters($method, $assisted, $parameters, $arguments);
        }
        $invocation->getArguments()->exchangeArray($arguments);

        return $invocation->proceed();
    }
736897
public static function callProtectedMethod($object, $method, ...$args)
    {
        $refObject = new \ReflectionObject($object);
        $refProp   = $refObject->getMethod($method);
        $refProp->setAccessible(true);

        return $refProp->invokeArgs($object, $args);
    }
1290199
public function withPreCallInterceptors(array $interceptors) : self
    {
        Assert::allInstanceOfType($interceptors, CallInterceptor::class);

        $this->preSendInterceptors = $interceptors;

        foreach ($interceptors as $interceptor) {
            $this->registerRequiredReference($interceptor->getReferenceName());
        }

        return $this;
    }
1000309
public function toBe()
    {
        if ($this->reference()) {
            $this->_substitutes = func_get_args();
        } else {
            $this->_actsAsAReplacement = true;
            if (func_num_args() !== 1) {
                throw new Exception("Only one hard method substitution is allowed through `toBe()`.");
            }
            $this->_closures = func_get_args();
        }
    }
1082637
protected function proxy() {
        if (!$this->context) {
            $this->context = new SampleContext(
                $this->version,
                $this->solution['assistantSid'],
                $this->solution['taskSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
315899
public function injector($classname, $method = null)
    {
        $params = [];
        $reflection = new \ReflectionClass($classname);

        if (is_null($method)) {
            $method = "__invoke";
        }

        $parameters = $reflection->getMethod($method)->getParameters();

        foreach ($parameters as $parameter) {
            $class = $parameter->getClass();

            if (is_null($class)) {
                continue;
            }

            $constructor = $class->getName();

            if (! class_exists($constructor, true)) {
                continue;
            }

            if (!in_array(strtolower($constructor), $this->getInjectorExceptedType())) {
                if (method_exists($constructor, 'getInstance')) {
                    $params[] = $constructor::getInstance();
                } else {
                    $params[] = new $constructor();
                }
            }
        }

        return $params;
    }
511175
@Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        if (method.getName().equals("annotationType")) {
            return annotationType;
        } else if (method.getName().equals("toString")) { 
            return toString();
        } else if (method.getName().equals("equals")) {
           return annotationEquals(args[0]);
        } else if (method.getName().equals("hashCode")) { 
            return proxy.hashCode();
        } else {
            return attributeData.get(method.getName());
        }
       
    }
1253839
public function answer(): callable
    {
        return function ($self, $arguments) {
            foreach ($this->iterations as $iteration) {
                foreach ($iteration->requests as $request) {
                    $this->invoker->callWith(
                        $request->callback(),
                        $request->finalArguments($self, $arguments)
                    );
                }

                if ($iteration instanceof GeneratorYieldFromIteration) {
                    foreach ($iteration->values as $key => $value) {
                        if ($key instanceof InstanceHandle) {
                            $key = $key->get();
                        }

                        if ($value instanceof InstanceHandle) {
                            $value = $value->get();
                        }

                        yield $key => $value;
                    }
                } else {
                    if ($iteration->hasKey) {
                        yield $iteration->key => $iteration->value;
                    } elseif ($iteration->hasValue) {
                        yield $iteration->value;
                    } else {
                        yield;
                    }
                }
            }

            foreach ($this->requests as $request) {
                $this->invoker->callWith(
                    $request->callback(),
                    $request->finalArguments($self, $arguments)
                );
            }

            if ($this->exception) {
                throw $this->exception;
            }

            if ($this->returnsSelf) {
                return $self;
            }

            if (null !== $this->returnsArgument) {
                return $arguments->get($this->returnsArgument);
            }

            return $this->returnValue;
        };
    }
1253218
public function execute()
    {
        $registered = false;
        if (self::$interceptor_stack === null)
        {
            $registered = true;
            self::registerErrorHandler();
        }
            
        array_push(self::$interceptor_stack, $this);
        $response = null;
        try
        {
            $response = call_user_func_array($this->func, func_get_args());
        }
        finally
        {
            array_pop(self::$interceptor_stack);

            if ($registered)
                self::unregisterErrorHandler();
        }
        return $response;
    }
878193
@Override
	public Object intercept(Object object, Method method, Object[] args,
			MethodProxy methodProxy) throws Throwable {
		Method delegateMethod = delegateClass.getMethod(method.getName(),
				method.getParameterTypes());
		if ("registerBeanDefinition".equals(method.getName())) {
			if (beanDefinitionMap.containsKey(args[0])) {
				List<BeanDefinition> definitions = beanDefinitionMap
						.get(args[0]);
				definitions.add((BeanDefinition) args[1]);
			} else {
				List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>();
				beanDefinitions.add((BeanDefinition) args[1]);
				beanDefinitionMap.put((String) args[0], beanDefinitions);
			}
		}
		return delegateMethod.invoke(delegate, args);
	}
694709
public function build(): object
    {
        $object = $this->instanciator->build($this->class, $this->properties);
        $parameters = $this->instanciator->parameters($this->class);

        //avoid injecting the properties already used in the constructor
        $properties = $this
            ->properties
            ->filter(function(string $property) use ($parameters) {
                return !$parameters->contains($property);
            });
        $refl = new ReflectionObject(
            $object,
            $properties,
            $this->injectionStrategy
        );

        return $refl->build();
    }
465557
private function handleHTTP()
    {
    	try
    	{
			$method = new ReflectionMethod($this->classname, $_REQUEST["svc"]);
    	}
    	catch (Exception $ex)
    	{
    		echo '{ error: "Method does not exists" }';
    		exit;
    	}
		if (!$method->isPublic())
		{
    		echo '{ error: "Method is not public" }';
			exit;
		}

		$params = $method->getParameters();
		$paramValues = array();
		$missingParams = array();
		foreach ($params as $param)
		{
			$paramName = $param->getName();
			$paramValue = ( isset($_REQUEST[$paramName]) ? $_REQUEST[$paramName] : null);
			if (is_null($paramValue) && $param->isDefaultValueAvailable())
			{
				$paramValue = $param->getDefaultValue();
			}
			if (is_null($paramValue))
			{
				$missingParams[] = $paramName;
			}
			else
			{
				$paramValues[$paramName] = $paramValue;
			}
		}
		if (count($missingParams) > 0)
		{
			echo '{ error: "Missing params", parameters: [ "' . implode('","', $missingParams) . '"] }';
		}
		else
		{
			try
			{
				$result = $method->invokeArgs($this, $paramValues);
				if (is_array($result))
				{
					echo json_encode($result);
				}
				elseif (is_object($result))
				{
					echo '{ error: "Return type is not supported" } ';
				}
				else
				{
					echo $result;
				}
			}
			catch (Exception $ex)
			{
				echo '{ error: "' . $ex->getMessage() . '" }';
			}
		}
    }
569900
public function method()
    {
        // Return the emulated method from GET
        $emulated = filter_input(INPUT_GET, '_method', FILTER_SANITIZE_STRING);

        // Return the emulated method from POST
        if (!$emulated) {
            $emulated = filter_input(INPUT_POST, '_method', FILTER_SANITIZE_STRING);
        }

        // Set the emulated method
        if ($this->app->config('request.emulate') && $emulated) {
            return $emulated;
        }

        // Or the real method
        return $_SERVER['REQUEST_METHOD'];
    }
1345835
public function newInstance()
    {
        /** @noinspection PhpUnusedLocalVariableInspection */
        $name = "{$this->getMockNamespaceName()}\\{$this->getMockName()}";
        /** @noinspection PhpUnusedLocalVariableInspection */
        $code = $this->generateCode();
        /** @var $reflect \ReflectionClass */
        $reflect = eval("$code return new \\ReflectionClass('$name');");

        try {
            return $reflect->newInstanceArgs($this->constructorArgs);
        } catch (ReflectionException $e) {
            return $reflect->newInstance();
        }
    }
443545
public function cliAction()
    {
        $exitCode = $this->cliApplication->run(new RequestInput($this->getRequest()), $this->output);

        if (is_numeric($exitCode)) {
            $model = new ViewModel();
            $model->setErrorLevel($exitCode);

            return $model;
        }
    }
154904
protected function proxy() {
        if (!$this->context) {
            $this->context = new CompositionHookContext($this->version, $this->solution['sid']);
        }

        return $this->context;
    }
1193477
@Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        return methodProxy.invokeSuper(o, objects);
    }