protected function instantiateClass($class, array $args)
    {
        try {
            $reflectionMethod = new ReflectionMethod($class, '__construct');

            $ordered_arguments = Helper::parseParams(
                $reflectionMethod->getParameters(),
                $args
            );

            $reflectionClass = new ReflectionClass($class);

            return $reflectionClass->newInstanceArgs(
                (array)$ordered_arguments
            );
        } catch (Exception $exception) {
            throw new InvalidArgumentException(
                sprintf(
                    _('Failed to instantiate class "%1$s". Reason: %2$s'),
                    $class,
                    $exception->getMessage()
                )
            );
        }
    }
protected function instantiateClass($class, array $args)
    {
        try {
            $reflectionMethod = new ReflectionMethod($class, '__construct');

            $ordered_arguments = Helper::parseParams(
                $reflectionMethod->getParameters(),
                $args
            );

            $reflectionClass = new ReflectionClass($class);

            return $reflectionClass->newInstanceArgs(
                (array)$ordered_arguments
            );
        } catch (Exception $exception) {
            throw new InvalidArgumentException(
                sprintf(
                    _('Failed to instantiate class "%1$s". Reason: %2$s'),
                    $class,
                    $exception->getMessage()
                )
            );
        }
    }
protected function instantiateClass ( $ class , array $ args ) { try { $ reflectionMethod = new ReflectionMethod ( $ class , '__construct' ) ; $ ordered_arguments = Helper :: parseParams ( $ reflectionMethod -> getParameters ( ) , $ args ) ; $ reflectionClass = new ReflectionClass ( $ class ) ; return $ reflectionClass -> newInstanceArgs ( ( array ) $ ordered_arguments ) ; } catch ( Exception $ exception ) { throw new InvalidArgumentException ( sprintf ( _ ( 'Failed to instantiate class "%1$s". Reason: %2$s' ) , $ class , $ exception -> getMessage ( ) ) ) ; } }
Check the accepted arguments for a given class constructor and pass
associative array values in the right order.

@since 0.2.0

@param  string $class The class that needs to be instantiated.
@param  array  $args  Associative array that contains the arguments.

@return object        Instantiated object.
@throws InvalidArgumentException If a valid method is missing.
Check the accepted arguments for a given class constructor and pass associative array values in the right order .