You are here

class SubdomainMethod in Persistent URL 8

Plugin annotation


@PurlMethod(
    id="subdomain",
    name="Subdomain"
)

Hierarchy

  • class \Drupal\purl\Plugin\Purl\Method\SubdomainMethod implements \Symfony\Component\DependencyInjection\ContainerAwareInterface, MethodInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait

Expanded class hierarchy of SubdomainMethod

File

src/Plugin/Purl/Method/SubdomainMethod.php, line 16

Namespace

Drupal\purl\Plugin\Purl\Method
View source
class SubdomainMethod implements MethodInterface, ContainerAwareInterface {
  use ContainerAwareTrait;
  public function contains(Request $request, $modifier) {
    $baseHost = $this
      ->getBaseHost();
    if (!$baseHost) {
      return false;
    }
    $host = $request
      ->getHost();
    if ($host === $this
      ->getBaseHost()) {
      return false;
    }
    return $this
      ->hostContainsModifier($modifier, $request
      ->getHost());
  }
  private function hostContainsModifier($modifier, $host) {
    return strpos($host, $modifier . '.') === 0;
  }
  private function getBaseHost() {

    // Retrieve this from request context.
    return 'apa.dev';
  }
  public function enterContext($modifier, $path, array &$options) {
    $baseHost = $this
      ->getBaseHost();
    if (!$baseHost) {
      return null;
    }
    $options['absolute'] = true;
    if ($this
      ->hostContainsModifier($modifier, $baseHost)) {
      return null;
    }
    $options['host'] = sprintf('%s.%s', $modifier, $baseHost);
    return $path;
  }
  public function exitContext($modifier, $path, array &$options) {
    $baseHost = $this
      ->getBaseHost();
    if (!$this
      ->hostContainsModifier($modifier, $baseHost)) {
      return null;
    }

    // Strip out modifier sub-domain.
    $host = substr($baseHost, 0, strlen($modifier) + 1);
    $options['absolute'] = true;
    $options['host'] = $host;
    return $path;
  }

}

Members