1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
<?php
namespace Apptus\ESales\Connector;
final class AttributeValidation {
const ILLEGAL_KEY_CHARACTERS = ", \r\n\t";
private static $products = null;
private static $ads = null;
private $reservedNames;
private final function __construct() {
$this->reservedNames = array_flip(func_get_args());
}
public static function forProducts() {
if (self::$products === null) {
self::$products = new AttributeValidation('relevance', 'sales', 'rank', 'locale', 'abandonment_timestamp', 'viewed_timestamp', 'proportion', 'rating', 'clicks');
}
return self::$products;
}
public static function forVariants() {
return self::forProducts();
}
public static function forAds() {
if (self::$ads === null) {
self::$ads = new AttributeValidation('rank', 'locale', 'products', 'start_time', 'end_time', 'related', 'included');
}
return self::$ads;
}
public function validAttributeName($name) {
return $this->validAttributeNameHelper($name, '/^[a-zA-Z_][a-zA-Z0-9_\-]*$/');
}
public function validSortAttributeName($name) {
return $this->validAttributeNameHelper($name, '/^[a-zA-Z_][a-zA-Z0-9_]*$/');
}
private function validAttributeNameHelper($name, $pattern) {
if ($name === null || !is_string($name)) {
return false;
}
if (isset($this->reservedNames[$name])) {
return false;
}
if (!preg_match($pattern, $name)) {
return false;
}
return true;
}
public function validItemKey($itemKey) {
return strpbrk($itemKey, self::ILLEGAL_KEY_CHARACTERS) === false;
}
}