You are here

public function CartLinksValidator::isValidSyntax in Ubercart 8.4

Tests a string containing a Cart Link to see if it is syntactically valid.

Parameters

string $link: String containing a Cart Link.

bool $debug: Boolean flag to enable/disable debug output. Defaults to FALSE.

Return value

bool TRUE if valid, FALSE if not.

Overrides CartLinksValidatorInterface::isValidSyntax

File

uc_cart_links/src/CartLinksValidator.php, line 32

Class

CartLinksValidator
Utility functions for dealing with Cart Links.

Namespace

Drupal\uc_cart_links

Code

public function isValidSyntax($link, $debug = FALSE) {
  $result = preg_match('~/cart/add/(e-)?(p[1-9][0-9]*(_q[1-9][0-9]*)*(_a[1-9][0-9]*o[a-zA-Z0-9%]+)*(_s)?)+(-m[0-9]+|-i[a-zA-Z0-9]+)*(\\?destination=/[a-zA-Z0-9/%]+)?~', $link, $matches);
  if ($debug) {
    $this->messenger
      ->addMessage('Cart Link = ' . $link);
    $this->messenger
      ->addMessage('Regular expression matches = <pre>' . print_r($matches) . '</pre>');
  }
  return (bool) $result;
}