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

Breadcrumb

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

function ClassDiscovery::safeClassExists

We need a "safe" version of PHP's "class_exists" because Magento has a bug (or they call it a "feature"). Magento is throwing an exception if you do class_exists() on a class that ends with "Factory" and if that file does not exits.

This function catches all potential exceptions and makes sure to always return a boolean.

Parameters

string $class:

Return value

bool

7 calls to ClassDiscovery::safeClassExists()
ClassDiscovery::evaluateCondition in vendor/php-http/discovery/src/ClassDiscovery.php
Evaluates conditions to boolean.
ClassDiscovery::findOneByType in vendor/php-http/discovery/src/ClassDiscovery.php
Finds a class.
CommonClassesStrategy::getPsr18Candidates in vendor/php-http/discovery/src/Strategy/CommonClassesStrategy.php
Plugin::getMissingRequires in vendor/php-http/discovery/src/Composer/Plugin.php
Plugin::postUpdate in vendor/php-http/discovery/src/Composer/Plugin.php

... See full list

File

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

Class

ClassDiscovery
Registry that based find results on class existence.

Namespace

Http\Discovery

Code

public static function safeClassExists($class) {
    try {
        return class_exists($class) || interface_exists($class);
    } catch (\Exception $e) {
        return false;
    }
}

API Navigation

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