You are here

public static function AmpSocialPost::getProvider in Accelerated Mobile Pages (AMP) 8.3

Find the provider from an url.

Parameters

$url: The url.

Return value

string The provider this url is valid for.

2 calls to AmpSocialPost::getProvider()
AmpSocialPost::preRenderSocialPost in src/Element/AmpSocialPost.php
Pre-render callback.
AmpSocialPostTest::testGetProvider in tests/src/Unit/AmpSocialPostTest.php
@covers ::getProvider @dataProvider providerData

File

src/Element/AmpSocialPost.php, line 169

Class

AmpSocialPost
Provides AMP social post elements.

Namespace

Drupal\amp\Element

Code

public static function getProvider($url) {
  $patterns = static::getPatterns();
  $providers = array_keys(static::getProviders());
  foreach ($providers as $provider) {
    foreach ($patterns[$provider] as $pattern) {
      if (preg_match($pattern, $url, $matches) && $matches['provider'] == $provider) {
        return $provider;
      }
    }
  }
  return FALSE;
}