You are here

public function UrlInvalidation::validateExpression in Purge 8.3

Validate the expression given to the invalidation during instantiation.

Throws

\Drupal\purge\Plugin\Purge\Invalidation\Exception\MissingExpressionException Thrown when plugin defined expression_required = TRUE and when it is instantiated without expression (NULL).

\Drupal\purge\Plugin\Purge\Invalidation\Exception\InvalidExpressionException Exception thrown when plugin got instantiated with an expression that is not deemed valid for the type of invalidation.

Overrides InvalidationBase::validateExpression

See also

\Drupal\purge\Annotation\PurgeInvalidation::$expression_required

\Drupal\purge\Annotation\PurgeInvalidation::$expression_can_be_empty

1 call to UrlInvalidation::validateExpression()
WildcardUrlInvalidation::validateExpression in src/Plugin/Purge/Invalidation/WildcardUrlInvalidation.php
Validate the expression given to the invalidation during instantiation.
1 method overrides UrlInvalidation::validateExpression()
WildcardUrlInvalidation::validateExpression in src/Plugin/Purge/Invalidation/WildcardUrlInvalidation.php
Validate the expression given to the invalidation during instantiation.

File

src/Plugin/Purge/Invalidation/UrlInvalidation.php, line 68

Class

UrlInvalidation
Describes URL based invalidation, e.g. "http://site.com/node/1".

Namespace

Drupal\purge\Plugin\Purge\Invalidation

Code

public function validateExpression($wildcard_check = TRUE) {
  parent::validateExpression();

  // Set $this->url by calling getUrl and do some more validation.
  $url = $this
    ->getUrl()
    ->toString();
  if (strpos($url, 'http') === FALSE && strpos($url, 'https') === FALSE) {
    throw new InvalidExpressionException('Scheme unsupported!');
  }
  if (!UrlHelper::isValid($url, TRUE)) {
    throw new InvalidExpressionException('The URL is invalid.');
  }
  if ($wildcard_check && strpos($url, '*') !== FALSE) {
    throw new InvalidExpressionException('URL invalidations should not contain asterisks!');
  }
  if (strpos($url, ' ') !== FALSE) {
    throw new InvalidExpressionException('URL invalidations cannot contain spaces, use %20 instead.');
  }

  // @see \Drupal\purge\Plugin\Purge\Invalidation\WildcardUrl
  return $url;
}