Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ClassDiscovery.php

function ClassDiscovery::instantiateClass

Get an instance of the $class.

Parameters

string|\Closure $class a FQCN of a class or a closure that instantiate the class:

Return value

object

Throws

ClassInstantiationFailedException

12 calls to ClassDiscovery::instantiateClass()
HttpAsyncClientDiscovery::find in vendor/php-http/discovery/src/HttpAsyncClientDiscovery.php
Finds an HTTP Async Client.
HttpClientDiscovery::find in vendor/php-http/discovery/src/HttpClientDiscovery.php
Finds an HTTP Client.
MessageFactoryDiscovery::find in vendor/php-http/discovery/src/MessageFactoryDiscovery.php
Finds a Message Factory.
Psr17FactoryDiscovery::findRequestFactory in vendor/php-http/discovery/src/Psr17FactoryDiscovery.php
Psr17FactoryDiscovery::findResponseFactory in vendor/php-http/discovery/src/Psr17FactoryDiscovery.php

... See full list

File

vendor/php-http/discovery/src/ClassDiscovery.php, line 219

Class

ClassDiscovery
Registry that based find results on class existence.

Namespace

Http\Discovery

Code

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');
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal