[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/third-party/Http/Discovery/Exception/ -> NoCandidateFoundException.php (source)

   1  <?php
   2  
   3  namespace WordPress\AiClientDependencies\Http\Discovery\Exception;
   4  
   5  use WordPress\AiClientDependencies\Http\Discovery\Exception;
   6  /**
   7   * When we have used a strategy but no candidates provided by that strategy could be used.
   8   *
   9   * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  10   */
  11  final class NoCandidateFoundException extends \Exception implements Exception
  12  {
  13      /**
  14       * @param string $strategy
  15       */
  16      public function __construct($strategy, array $candidates)
  17      {
  18          $classes = array_map(function ($a) {
  19              return $a['class'];
  20          }, $candidates);
  21          $message = sprintf('No valid candidate found using strategy "%s". We tested the following candidates: %s.', $strategy, implode(', ', array_map([$this, 'stringify'], $classes)));
  22          parent::__construct($message);
  23      }
  24      private function stringify($mixed)
  25      {
  26          if (is_string($mixed)) {
  27              return $mixed;
  28          }
  29          if (is_array($mixed) && 2 === count($mixed)) {
  30              return sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]);
  31          }
  32          return is_object($mixed) ? get_class($mixed) : gettype($mixed);
  33      }
  34  }


Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref