src/WordPress/Http/Router.php
private function invokeControllerAction($controllerClassNamed, $actionNamed, array $givenArgs = [])
	{
		if (is_wp_error($controllerClass = $this->getControllerClass($controllerClassNamed))) {
			return $controllerClass;
		}
		$reflection = new \ReflectionClass($controllerClass);
		$controller = new $controllerClass($this);
		if (!$reflection->hasMethod($actionNamed)) {
			return new \WP_Error('method_not_found', "Method Not Found: {$controllerClassNamed}@{$actionNamed}", ['status' => 404]);
		}
		$method = $reflection->getMethod($actionNamed);
	
		$args = [];
		if (!empty($givenArgs)) {
			$args[] = $givenArgs[0];
		}

		if (count($givenArgs) > 1) {
			$params = $method->getParameters();

			// loop over method params, ignoring the first
			for ($i=1; $i<count($params); $i++) {
				$param = $params[$i];

				// if the param has no type 
				if (!$param->hasType()) {

					if ($this->getPlugin()->bound($param->name)) {
						$args[] = $this->getPlugin()->make($param->name);
					}	

				} else {
					$class = $param->getClass();
					// map in plugin
					if ($class->isSubclassOf(\Illuminate\Container\Container::class)) {
						$args[] = $this->getPlugin();

					// otherwise, use the service container to build whatever
					} else {
						$args[] = $this->getPlugin()->make($class->name);
					}
				}
			}
		}

		return $method->invokeArgs($controller, $args);
	}
private function invokeControllerAction($controllerClassNamed, $actionNamed, array $givenArgs = [])
	{
		if (is_wp_error($controllerClass = $this->getControllerClass($controllerClassNamed))) {
			return $controllerClass;
		}
		$reflection = new \ReflectionClass($controllerClass);
		$controller = new $controllerClass($this);
		if (!$reflection->hasMethod($actionNamed)) {
			return new \WP_Error('method_not_found', "Method Not Found: {$controllerClassNamed}@{$actionNamed}", ['status' => 404]);
		}
		$method = $reflection->getMethod($actionNamed);
	
		$args = [];
		if (!empty($givenArgs)) {
			$args[] = $givenArgs[0];
		}

		if (count($givenArgs) > 1) {
			$params = $method->getParameters();

			// loop over method params, ignoring the first
			for ($i=1; $i<count($params); $i++) {
				$param = $params[$i];

				// if the param has no type 
				if (!$param->hasType()) {

					if ($this->getPlugin()->bound($param->name)) {
						$args[] = $this->getPlugin()->make($param->name);
					}	

				} else {
					$class = $param->getClass();
					// map in plugin
					if ($class->isSubclassOf(\Illuminate\Container\Container::class)) {
						$args[] = $this->getPlugin();

					// otherwise, use the service container to build whatever
					} else {
						$args[] = $this->getPlugin()->make($class->name);
					}
				}
			}
		}

		return $method->invokeArgs($controller, $args);
	}
private function invokeControllerAction ( $ controllerClassNamed , $ actionNamed , array $ givenArgs = [ ] ) { if ( is_wp_error ( $ controllerClass = $ this -> getControllerClass ( $ controllerClassNamed ) ) ) { return $ controllerClass ; } $ reflection = new \ ReflectionClass ( $ controllerClass ) ; $ controller = new $ controllerClass ( $ this ) ; if ( ! $ reflection -> hasMethod ( $ actionNamed ) ) { return new \ WP_Error ( 'method_not_found' , "Method Not Found: {$controllerClassNamed}@{$actionNamed}" , [ 'status' => 404 ] ) ; } $ method = $ reflection -> getMethod ( $ actionNamed ) ; $ args = [ ] ; if ( ! empty ( $ givenArgs ) ) { $ args [ ] = $ givenArgs [ 0 ] ; } if ( count ( $ givenArgs ) > 1 ) { $ params = $ method -> getParameters ( ) ; // loop over method params, ignoring the first for ( $ i = 1 ; $ i < count ( $ params ) ; $ i ++ ) { $ param = $ params [ $ i ] ; // if the param has no type  if ( ! $ param -> hasType ( ) ) { if ( $ this -> getPlugin ( ) -> bound ( $ param -> name ) ) { $ args [ ] = $ this -> getPlugin ( ) -> make ( $ param -> name ) ; } } else { $ class = $ param -> getClass ( ) ; // map in plugin if ( $ class -> isSubclassOf ( \ Illuminate \ Container \ Container :: class ) ) { $ args [ ] = $ this -> getPlugin ( ) ; // otherwise, use the service container to build whatever } else { $ args [ ] = $ this -> getPlugin ( ) -> make ( $ class -> name ) ; } } } } return $ method -> invokeArgs ( $ controller , $ args ) ; }
Invoke the given action on the given class, after resolving
an existing Class that matches the given class as named; map
arguments to controller action by dependency injection.
@param String The name of a controller to invoke; presumed to be taken from routes config
@param String The name of the action to invoke; must be a callable method on the controller
@param array Arguments to pass into the invocation of the method
@return mixed The result of the action invocation
@throws Exception For various reasons, generally internal to the Controller's invocation
Invoke the given action on the given class after resolving an existing Class that matches the given class as named ; map arguments to controller action by dependency injection .