| 1: | <?php
|
| 2: |
|
| 3: | namespace Mypos\IPC;
|
| 4: |
|
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Helper
|
| 9: | {
|
| 10: | private function __construct() { }
|
| 11: |
|
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | public static function isValidEmail($email)
|
| 20: | {
|
| 21: | return filter_var($email, FILTER_VALIDATE_EMAIL);
|
| 22: | }
|
| 23: |
|
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: |
|
| 31: | public static function isValidURL($url)
|
| 32: | {
|
| 33: | return filter_var($url, FILTER_VALIDATE_URL);
|
| 34: | }
|
| 35: |
|
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: |
|
| 43: | public static function isValidIP($ip)
|
| 44: | {
|
| 45: | return filter_var($ip, FILTER_VALIDATE_IP);
|
| 46: | }
|
| 47: |
|
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: |
|
| 55: | public static function isValidName($name)
|
| 56: | {
|
| 57: | return preg_match("/^[a-zA-Z ]*$/", $name);
|
| 58: | }
|
| 59: |
|
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: |
|
| 67: | public static function isValidAmount($amt)
|
| 68: | {
|
| 69: | return preg_match('/^(-)?[0-9]+(?:\.[0-9]{0,2})?$/', $amt);
|
| 70: | }
|
| 71: |
|
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: |
|
| 79: | public static function isValidCartQuantity($quantity)
|
| 80: | {
|
| 81: | return is_int($quantity) && $quantity > 0;
|
| 82: | }
|
| 83: |
|
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: |
|
| 91: | public static function isValidTrnRef($trnref)
|
| 92: | {
|
| 93: |
|
| 94: | return true;
|
| 95: | }
|
| 96: |
|
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: |
|
| 104: | public static function isValidOrderId($trnref)
|
| 105: | {
|
| 106: |
|
| 107: | return true;
|
| 108: | }
|
| 109: |
|
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: |
|
| 117: | public static function isValidOutputFormat($outputFormat)
|
| 118: | {
|
| 119: | return in_array($outputFormat, [
|
| 120: | Defines::COMMUNICATION_FORMAT_XML,
|
| 121: | Defines::COMMUNICATION_FORMAT_JSON,
|
| 122: | ]);
|
| 123: | }
|
| 124: |
|
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: |
|
| 132: | public static function isValidCardNumber($cardNo)
|
| 133: | {
|
| 134: | $cardNo = str_replace(" ", "", trim($cardNo));
|
| 135: | if ((!is_numeric($cardNo)) || (strlen($cardNo) > 19) || (strlen($cardNo) < 13)) {
|
| 136: | return false;
|
| 137: | }
|
| 138: | $sum = $dub = $add = $chk = 0;
|
| 139: | $even = 0;
|
| 140: | for ($i = strlen($cardNo) - 1; $i >= 0; $i--) {
|
| 141: | if ($even == 1) {
|
| 142: | $dub = 2 * $cardNo[$i];
|
| 143: | if ($dub > 9) {
|
| 144: | $add = $dub - 9;
|
| 145: | } else {
|
| 146: | $add = $dub;
|
| 147: | }
|
| 148: | $even = 0;
|
| 149: | } else {
|
| 150: | $add = $cardNo[$i];
|
| 151: | $even = 1;
|
| 152: | }
|
| 153: | $sum += $add;
|
| 154: | }
|
| 155: |
|
| 156: | return (($sum % 10) == 0);
|
| 157: | }
|
| 158: |
|
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: |
|
| 166: | public static function isValidCVC($cvc)
|
| 167: | {
|
| 168: | return (is_numeric($cvc) && strlen($cvc) == 3);
|
| 169: | }
|
| 170: |
|
| 171: | public static function versionCheck($current, $required)
|
| 172: | {
|
| 173: | return (int)str_replace('.', '', $current) >= (int)str_replace('.', '', $required);
|
| 174: | }
|
| 175: |
|
| 176: | |
| 177: | |
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: |
|
| 183: | public static function escape($text)
|
| 184: | {
|
| 185: | if ($text !== null){
|
| 186: | $text = htmlspecialchars_decode($text, ENT_QUOTES);
|
| 187: |
|
| 188: | return htmlspecialchars($text, ENT_QUOTES);
|
| 189: | }else{
|
| 190: | return $text;
|
| 191: | }
|
| 192: |
|
| 193: | }
|
| 194: |
|
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: |
|
| 202: | public static function unescape($text)
|
| 203: | {
|
| 204: | if ($text !== null){
|
| 205: | return htmlspecialchars_decode($text, ENT_QUOTES);
|
| 206: | }else{
|
| 207: | return $text;
|
| 208: | }
|
| 209: | }
|
| 210: |
|
| 211: | |
| 212: | |
| 213: | |
| 214: | |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: |
|
| 223: | public static function getArrayVal($array, $key, $default = '', $notEmpty = false)
|
| 224: | {
|
| 225: | if (!is_array($array)) {
|
| 226: | return $default;
|
| 227: | }
|
| 228: | if ($notEmpty) {
|
| 229: | if (array_key_exists($key, $array)) {
|
| 230: | $val = trim($array[$key]);
|
| 231: | if (!empty($val)) {
|
| 232: | return $val;
|
| 233: | }
|
| 234: | }
|
| 235: |
|
| 236: | return $default;
|
| 237: | } else {
|
| 238: | return array_key_exists($key, $array) ? $array[$key] : $default;
|
| 239: | }
|
| 240: | }
|
| 241: |
|
| 242: | |
| 243: | |
| 244: | |
| 245: | |
| 246: | |
| 247: | |
| 248: | |
| 249: | |
| 250: |
|
| 251: | public static function getValuesFromMultiDimensionalArray($array, $values = [])
|
| 252: | {
|
| 253: | if (!is_array($array)) {
|
| 254: | return $values;
|
| 255: | }
|
| 256: | foreach ($array as $k => $v) {
|
| 257: | if (is_array($v)) {
|
| 258: | $values = self::getValuesFromMultiDimensionalArray($v, $values);
|
| 259: | } else {
|
| 260: | $values[] = $v;
|
| 261: | }
|
| 262: | }
|
| 263: |
|
| 264: | return $values;
|
| 265: | }
|
| 266: | }
|
| 267: | |