matchUrl example

return $result->length ? $result->item(0)->getAttribute('href') : FALSE;
  }

  /** * {@inheritdoc} */
  public function getProviderByUrl($url) {
    // Check the URL against every scheme of every endpoint of every provider     // until we find a match.     foreach ($this->providers->getAll() as $provider_info) {
      foreach ($provider_info->getEndpoints() as $endpoint) {
        if ($endpoint->matchUrl($url)) {
          return $provider_info;
        }
      }
    }

    $resource_url = $this->discoverResourceUrl($url);
    if ($resource_url) {
      return $this->resourceFetcher->fetchResource($resource_url)->getProvider();
    }

    throw new ResourceException('No matching provider found.', $url);
  }
class EndpointTest extends UnitTestCase {

  /** * @covers ::matchUrl */
  public function testMatchUrl(): void {
    $endpoint = new Endpoint(
      'https://www.youtube.com/oembed',
      $this->createMock('\Drupal\media\OEmbed\Provider'),
      ['https://*.youtube.com/playlist?list=*']
    );
    $this->assertTrue($endpoint->matchUrl('https://www.youtube.com/playlist?list=aBc-EzAs123'));
  }

  /** * @covers ::matchUrl */
  public function testCaseSensitiveMatch(): void {
    $endpoint = new Endpoint(
      'https://www.example.com/oembed',
      $this->createMock('\Drupal\media\OEmbed\Provider'),
      ['https://*.example.com/Video/*'],
    );
    
Home | Imprint | This part of the site doesn't use cookies.