tawk/url-utils

2.0.2 2024-09-09 08:05 UTC

This package is auto-updated.

Last update: 2024-09-09 08:06:55 UTC


README

概述

tawk.to URL 工具库。

模块

URL 模式匹配器

此模块处理提供的 URL 与提供的模式的匹配。

match(string $current_url, array $patterns)

匹配提供的 URL 和模式。如果匹配则返回 true,否则返回 false

示例
<?php
use Tawk\Modules\UrlPatternMatcher;

$current_url = 'http://www.example.com/path/to/somewhere';
$patterns = array('http://www.example.com/path/to/somewhere');

$match_result = UrlPatternMatcher::match($current_url, $patterns);

路径模式匹配器

此模块通过逐块匹配处理提供的 URL 路径与提供的模式。

match(array $current_path_chunks, array $path_patterns)

匹配提供的 URL 路径和模式。如果匹配则返回 true,否则返回 false

<?php
use Tawk\Helpers\PathHelper;
use Tawk\Models\PathPattern;
use Tawk\Modules\PathPatternMatcher;

$current_url = PathHelper::get_chunks('/path/to/somewhere');
$path_patterns = array(
	PathPattern::create_instance_from_path('/path/to/somewhere'),
);

$match_result = PathPatternMatcher::match($current_url, $path_patterns);

附加信息

模式匹配器的有效模式

  • *
  • */to/somewhere
  • /*/to/somewhere
  • /path/*/somewhere
  • /path/*/lead/*/somewhere
  • /path/*/*/somewhere
  • /path/to/*
  • /path/to/*/
  • */to/*/page
  • /*/to/*/page
  • /path/*/other/*
  • /path/*/other/*/
  • http://www.example.com/
  • http://www.example.com/*
  • http://www.example.com/*/to/somewhere
  • http://www.example.com/path/*/somewhere
  • http://www.example.com/path/*/lead/*/somewhere
  • http://www.example.com/path/*/*/somewhere
  • http://www.example.com/path/to/*
  • http://www.example.com/path/to/*/
  • http://www.example.com/*/to/*/page
  • http://www.example.com/path/*/other/*
  • http://www.example.com/path/*/other/*/

模式匹配器的无效模式

  • path/*/somewhere - "path" 被视为主机而非路径的开始。
  • */should/*/to/* - 目前不支持。模式中只支持在路径的 起始和中间中间和末尾 使用多个通配符。