getRegExForWildCardAttributeName example

      if (!is_array($tag_config) || !(isset($other->elements[$tag]) && is_array($other->elements[$tag]))) {
        continue;
      }

      // Special case: wildcard attributes, and the ability to define       // restrictions for all concrete attributes matching them using:       // - prefix wildcard, f.e. `*-foo`       // - infix wildcard, f.e. `*-entity-*`       // - suffix wildcard, f.e. `data-*`, to match `data-foo`, `data-bar`, etc.       $wildcard_attributes = array_filter(array_keys($other->elements[$tag])[__CLASS__, 'isWildcardAttributeName']);
      foreach ($wildcard_attributes as $wildcard_attribute_name) {
        $regex = self::getRegExForWildCardAttributeName($wildcard_attribute_name);
        foreach ($tag_config as $html_tag_attribute_name => $html_tag_attribute_restrictions) {
          // If a wildcard attribute name (f.e. `data-*`) is allowed in $other           // with the same attribute value restrictions (e.g. TRUE to allow all           // attribute values or an array of specific allowed attribute values),           // then all concrete matches (f.e. `data-foo`, `data-bar`, etc.) are           // allowed and should be explicitly omitted from the difference.           if ($html_tag_attribute_restrictions === $other->elements[$tag][$wildcard_attribute_name] && preg_match($regex$html_tag_attribute_name) === 1) {
            unset($tag_config[$html_tag_attribute_name]);
          }
        }
      }

      
foreach ($forbidden_attributes as $forbidden_attribute_name) {
      // Forbidden attributes not containing wildcards, such as `style`.       if (!self::isWildcardAttributeName($forbidden_attribute_name)) {
        if (array_key_exists($forbidden_attribute_name$attribute_restrictions)) {
          $this->context->buildViolation($constraint->message)
            ->setParameter('%dangerous_tag', $value)
            ->addViolation();
        }
      }
      // Forbidden attributes containing wildcards such as `on*`.       else {
        $regex = self::getRegExForWildCardAttributeName($forbidden_attribute_name);
        if (!empty(preg_grep($regexarray_keys($attribute_restrictions)))) {
          $this->context->buildViolation($constraint->message)
            ->setParameter('%dangerous_tag', $value)
            ->addViolation();
        }
      }
    }
  }

  /** * Checks whether the given attribute name contains a wildcard, e.g. `data-*`. * * @param string $attribute_name * The attribute name to check. * * @return bool * Whether the given attribute name contains a wildcard. */
Home | Imprint | This part of the site doesn't use cookies.