'', 'name' => '', 'last_name' => '', 'phone' => '', 'email' => '', 'country' => '972', 'stage_id' => '', 'custom' => []]; } public static function clean(array $input): array { $out = self::defaults(); $out['enabled'] = empty($input['enabled']) ? '' : 'yes'; foreach (['name', 'last_name', 'phone', 'email'] as $key) { $out[$key] = self::field_id($input[$key] ?? ''); } $country = is_scalar($input['country'] ?? '972') ? trim((string) ($input['country'] ?? '972')) : ''; $out['country'] = preg_match('/^[1-9][0-9]{0,2}$/D', $country) ? $country : ''; $stage = is_scalar($input['stage_id'] ?? '') ? (string) ($input['stage_id'] ?? '') : ''; $out['stage_id'] = ctype_digit($stage) && (int) $stage > 0 ? (int) $stage : ''; foreach (array_slice(is_array($input['custom'] ?? null) ? $input['custom'] : [], 0, 100) as $row) { if (!is_array($row)) { continue; } $key = is_scalar($row['key'] ?? '') ? trim((string) $row['key']) : ''; $field = self::field_id($row['field'] ?? ''); if ($key !== '' && $field !== '' && preg_match('/^[\p{L}\p{M}\p{N}_-]{1,100}$/uD', $key)) { $out['custom'][] = ['key' => $key, 'field' => $field, 'type' => ($row['type'] ?? '') === 'boolean' ? 'boolean' : 'text']; } } return $out; } private static function field_id($value): string { return is_scalar($value) ? preg_replace('/[^A-Za-z0-9_-]/', '', (string) $value) : ''; } }