You are here

PathInvalidation.php in Purge 8.3

File

src/Plugin/Purge/Invalidation/PathInvalidation.php
View source
<?php

namespace Drupal\purge\Plugin\Purge\Invalidation;

use Drupal\purge\Plugin\Purge\Invalidation\Exception\InvalidExpressionException;

/**
 * Describes path based invalidation, e.g. "news/article-1".
 *
 * @PurgeInvalidation(
 *   id = "path",
 *   label = @Translation("Path"),
 *   description = @Translation("Invalidates by path."),
 *   examples = {"news/article-1"},
 *   expression_required = TRUE,
 *   expression_can_be_empty = TRUE,
 *   expression_must_be_string = TRUE
 * )
 */
class PathInvalidation extends InvalidationBase implements InvalidationInterface {

  /**
   * {@inheritdoc}
   */
  public function validateExpression($wildcard_check = TRUE) {
    parent::validateExpression();
    if ($wildcard_check && strpos($this->expression, '*') !== FALSE) {
      throw new InvalidExpressionException('Path invalidations should not contain asterisks.');
    }
    if ($wildcard_check && $this->expression === '*') {
      throw new InvalidExpressionException('Path invalidations cannot be "*".');
    }
    if (strpos($this->expression, ' ') !== FALSE) {
      throw new InvalidExpressionException('Path invalidations cannot contain spaces, use %20 instead.');
    }
    if (strpos($this->expression, '/') === 0) {
      throw new InvalidExpressionException('Path invalidations cannot start with slashes.');
    }
  }

}

Classes

Namesort descending Description
PathInvalidation Describes path based invalidation, e.g. "news/article-1".