src/DI/DefaultFactory.php
protected function determineArgumentsFor(
        ReflectionMethod $method, 
        string $class, 
        string $method_name, 
        array $args, 
        string $selector, 
        Injector $injector
    )
    {
        $params = $method->getParameters();
        $method_args = [];

        // Determine values for each parameter
        $used_optional = false;
        foreach ($params as $param)
        {
            $name = $param->getName();

            if (array_key_exists($name, $args))
            {
                $method_args[] = $args[$name];
                continue;
            }

            $pclass = $param->getClass();
            if (null !== $pclass)
            {
                $instance = $injector->getInstance($pclass->getName(), $selector);
                $method_args[] = $instance;
                continue;
            }

            if ($param->isDefaultValueAvailable())
            {
                $default = $param->getDefaultValue();
                $method_args[] = $default;
                continue;
            }

            if ($param->isOptional())
            {
                // This and all remaining parameters have a default value
                break;
            }

            throw new DIException("Unable to determine value for parameter $name for $method_name of '$class'");
        }

        // There should be a argument for every parameter
        return $method_args;
    }
protected function determineArgumentsFor(
        ReflectionMethod $method, 
        string $class, 
        string $method_name, 
        array $args, 
        string $selector, 
        Injector $injector
    )
    {
        $params = $method->getParameters();
        $method_args = [];

        // Determine values for each parameter
        $used_optional = false;
        foreach ($params as $param)
        {
            $name = $param->getName();

            if (array_key_exists($name, $args))
            {
                $method_args[] = $args[$name];
                continue;
            }

            $pclass = $param->getClass();
            if (null !== $pclass)
            {
                $instance = $injector->getInstance($pclass->getName(), $selector);
                $method_args[] = $instance;
                continue;
            }

            if ($param->isDefaultValueAvailable())
            {
                $default = $param->getDefaultValue();
                $method_args[] = $default;
                continue;
            }

            if ($param->isOptional())
            {
                // This and all remaining parameters have a default value
                break;
            }

            throw new DIException("Unable to determine value for parameter $name for $method_name of '$class'");
        }

        // There should be a argument for every parameter
        return $method_args;
    }
protected function determineArgumentsFor ( ReflectionMethod $ method , string $ class , string $ method_name , array $ args , string $ selector , Injector $ injector ) { $ params = $ method -> getParameters ( ) ; $ method_args = [ ] ; // Determine values for each parameter $ used_optional = false ; foreach ( $ params as $ param ) { $ name = $ param -> getName ( ) ; if ( array_key_exists ( $ name , $ args ) ) { $ method_args [ ] = $ args [ $ name ] ; continue ; } $ pclass = $ param -> getClass ( ) ; if ( null !== $ pclass ) { $ instance = $ injector -> getInstance ( $ pclass -> getName ( ) , $ selector ) ; $ method_args [ ] = $ instance ; continue ; } if ( $ param -> isDefaultValueAvailable ( ) ) { $ default = $ param -> getDefaultValue ( ) ; $ method_args [ ] = $ default ; continue ; } if ( $ param -> isOptional ( ) ) { // This and all remaining parameters have a default value break ; } throw new DIException ( "Unable to determine value for parameter $name for $method_name of '$class'" ) ; } // There should be a argument for every parameter return $ method_args ; }
Find arguments for a method
Find arguments for a method