WordPress\AiClientDependencies\Http\Discovery

ClassDiscovery::instantiateClassprotected staticWP 1.0

Get an instance of the $class.

Method of the class: ClassDiscovery{}

No Hooks.

Returns

Object.

Usage

$result = ClassDiscovery::instantiateClass( $class );
$class(string|\Closure) (required)
a FQCN of a class or a closure that instantiate the class.

ClassDiscovery::instantiateClass() code WP 7.0

protected static function instantiateClass($class)
{
    try {
        if (is_string($class)) {
            return new $class();
        }
        if (is_callable($class)) {
            return $class();
        }
    } catch (\Exception $e) {
        throw new ClassInstantiationFailedException('Unexpected exception when instantiating class.', 0, $e);
    }
    throw new ClassInstantiationFailedException('Could not instantiate class because parameter is neither a callable nor a string');
}