peakphp/framework

View on GitHub
src/Di/ClassInstantiator.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace Peak\Di;

use \ReflectionClass;

class ClassInstantiator
{
    /**
     * Instantiate a class
     *
     * @param string $class
     * @param array $args
     * @return object
     * @throws \ReflectionException
     */
    public function instantiate(string $class, array $args = [])
    {
        if (empty($args)) {
            return new $class();
        }
        return (new ReflectionClass($class))->newInstanceArgs($args);
    }
}