| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Support;
- /**
- * 包名风格域名 = 原生 APP 客户端(与注册域名 / 登录域名共用口径)
- *
- * 例:com.example.app
- */
- final class AppDomain
- {
- /** MySQL REGEXP 主体(不含定界符),用于 raw SQL */
- public const SQL_REGEXP = "^(com|org|net|io|cn)\\\\.[a-zA-Z0-9_]+(\\\\.[a-zA-Z0-9_]+)+$";
- /** PHP preg 模式 */
- public const PHP_PATTERN = '/^(com|org|net|io|cn)\.[a-z0-9_]+(\.[a-z0-9_]+)+$/i';
- public static function matches(string $host): bool
- {
- $host = strtolower(trim($host));
- if ($host === '') {
- return false;
- }
- return (bool)preg_match(self::PHP_PATTERN, $host);
- }
- /**
- * SQL 布尔表达式:列是否为包名域名
- *
- * @param string $column 已带表别名的列,如 u.register_domain
- */
- public static function sqlIsApp(string $column): string
- {
- return "({$column} REGEXP '" . self::SQL_REGEXP . "')";
- }
- }
|