src/web/Controller.php
public function bindActionParams($action, $params)
    {
        if ($action instanceof InlineAction) {
            $method = new \ReflectionMethod($this, $action->actionMethod);
        } else {
            $method = new \ReflectionMethod($action, 'run');
        }

        $args = [];
        $missing = [];
        $actionParams = [];
        foreach ($method->getParameters() as $param) {
            $name = $param->getName();
            if (($class = $param->getClass()) !== null) {
                $className = $class->getName();
            }
            // We only enter the class injection code path if:
            // - A class is hinted in the method signature
            // - And the param name of hinted class does not exist in existing $params, or the value in existing $params is not an instance of the hinted class
            // The latter two checks allow us to manually inject classes via $params while ignoring wrongly injected values (no instances of hinted class).
            if ($class !== null && (!array_key_exists($name, $params) || !$params[$name] instanceof $className)) {
                if (Yii::$app->has($name) && ($obj = Yii::$app->get($name)) instanceof $className) {
                    $args[] = $actionParams[$name] = $obj;
                } else {
                    $args[] = $actionParams[$name] = Yii::$container->get($className);
                }
            } elseif (array_key_exists($name, $params)) {
                if ($param->isArray()) {
                    $args[] = $actionParams[$name] = (array) $params[$name];
                } elseif (!is_array($params[$name])) {
                    $args[] = $actionParams[$name] = $params[$name];
                } else {
                    throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', [
                        'param' => $name,
                    ]));
                }
                unset($params[$name]);
            } elseif ($param->isDefaultValueAvailable()) {
                $args[] = $actionParams[$name] = $param->getDefaultValue();
            } else {
                $missing[] = $name;
            }
        }

        if (!empty($missing)) {
            throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', [
                'params' => implode(', ', $missing),
            ]));
        }

        $this->actionParams = $actionParams;

        return $args;
    }
public function bindActionParams($action, $params)
    {
        if ($action instanceof InlineAction) {
            $method = new \ReflectionMethod($this, $action->actionMethod);
        } else {
            $method = new \ReflectionMethod($action, 'run');
        }

        $args = [];
        $missing = [];
        $actionParams = [];
        foreach ($method->getParameters() as $param) {
            $name = $param->getName();
            if (($class = $param->getClass()) !== null) {
                $className = $class->getName();
            }
            // We only enter the class injection code path if:
            // - A class is hinted in the method signature
            // - And the param name of hinted class does not exist in existing $params, or the value in existing $params is not an instance of the hinted class
            // The latter two checks allow us to manually inject classes via $params while ignoring wrongly injected values (no instances of hinted class).
            if ($class !== null && (!array_key_exists($name, $params) || !$params[$name] instanceof $className)) {
                if (Yii::$app->has($name) && ($obj = Yii::$app->get($name)) instanceof $className) {
                    $args[] = $actionParams[$name] = $obj;
                } else {
                    $args[] = $actionParams[$name] = Yii::$container->get($className);
                }
            } elseif (array_key_exists($name, $params)) {
                if ($param->isArray()) {
                    $args[] = $actionParams[$name] = (array) $params[$name];
                } elseif (!is_array($params[$name])) {
                    $args[] = $actionParams[$name] = $params[$name];
                } else {
                    throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', [
                        'param' => $name,
                    ]));
                }
                unset($params[$name]);
            } elseif ($param->isDefaultValueAvailable()) {
                $args[] = $actionParams[$name] = $param->getDefaultValue();
            } else {
                $missing[] = $name;
            }
        }

        if (!empty($missing)) {
            throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', [
                'params' => implode(', ', $missing),
            ]));
        }

        $this->actionParams = $actionParams;

        return $args;
    }
Binds the parameters to the action.
This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters.
This method will check the parameter names that the action requires and return
the provided parameters according to the requirement. If there is any missing parameter,
an exception will be thrown.
@param \yii\base\Action $action the action to be bound with parameters
@param array $params the parameters to be bound to the action
@return array the valid parameters that the action can run with.
@throws BadRequestHttpException if there are missing or invalid parameters.