[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Providers/ApiBasedImplementation/ -> AbstractApiProvider.php (source)

   1  <?php
   2  
   3  declare (strict_types=1);
   4  namespace WordPress\AiClient\Providers\ApiBasedImplementation;
   5  
   6  use WordPress\AiClient\Providers\AbstractProvider;
   7  /**
   8   * Base class for API-based providers.
   9   *
  10   * This abstract class provides URL construction utilities for providers that
  11   * communicate with REST APIs. It standardizes the pattern of combining a base
  12   * URL with endpoint paths.
  13   *
  14   * @since 0.2.0
  15   */
  16  abstract class AbstractApiProvider extends AbstractProvider
  17  {
  18      /**
  19       * Gets the base URL for the provider's API.
  20       *
  21       * The base URL should include the protocol and domain, and may include
  22       * the API version path (e.g., "https://api.example.com/v1").
  23       *
  24       * @since 0.2.0
  25       *
  26       * @return string The base URL for the provider's API.
  27       */
  28      abstract protected static function baseUrl(): string;
  29      /**
  30       * Constructs a full URL by combining the base URL with an optional path.
  31       *
  32       * This method ensures proper URL construction by:
  33       * - Using the provider's base URL
  34       * - Trimming leading slashes from the path to prevent double-slashes
  35       * - Joining the base URL and path with a single forward slash
  36       *
  37       * @since 0.2.0
  38       *
  39       * @param string $path Optional path to append to the base URL. Default empty string.
  40       * @return string The complete URL.
  41       */
  42      public static function url(string $path = ''): string
  43      {
  44          if ($path === '') {
  45              return static::baseUrl();
  46          }
  47          return static::baseUrl() . '/' . ltrim($path, '/');
  48      }
  49  }


Generated : Sun Jul 5 08:20:13 2026 Cross-referenced by PHPXref