}'; /** @var string */ private $regex; /** @var array */ private $tokenNames; /** @var string */ private $pattern; /** * @param array $tokenNames */ public function __construct(string $regex, string $pattern, array $tokenNames) { $this->regex = $regex; $this->tokenNames = $tokenNames; $this->pattern = $pattern; } public static function fromPattern(string $pattern): self { preg_match_all(self::TOKEN_REGEX, $pattern, $matches); [$tokens, $tokenNames] = $matches; $regex = $pattern; foreach (array_values($matches[0]) as $index => $token) { $greedy = $index + 1 !== count($tokenNames); $regex = strtr($regex, [$token => sprintf('(?%s%s+)', $token, $greedy ? '[^/]' : '.')]); } if (empty($tokenNames)) { throw new NoPlaceHoldersException(sprintf( 'File pattern "%s" does not contain any ', $pattern )); } return new self(sprintf('{%s$}', $regex), $pattern, $tokenNames); } public function fits(string $filePath): bool { return (bool)preg_match($this->regex, Path::canonicalize($filePath)); } /** * @return array */ public function tokens(string $filePath): array { $filePath = Path::canonicalize($filePath); if (!preg_match($this->regex, $filePath, $matches)) { throw new RuntimeException(sprintf( 'Error occurred performing regex on filepath "%s" with regex "%s"', $filePath, $this->regex )); } return array_intersect_key($matches, (array)array_combine($this->tokenNames, $this->tokenNames)); } /** * @param array $tokens */ public function replaceTokens(array $tokens): string { return $this->cleanRemainingTokens($this->replaceTokensWithValues($tokens)); } public function toString(): string { return $this->pattern; } /** * @param array $tokens */ private function replaceTokensWithValues(array $tokens): string { return strtr($this->pattern, (array)array_combine(array_map(function (string $key) { return '<' . $key . '>'; }, array_keys($tokens)), array_values($tokens))); } private function cleanRemainingTokens(string $filePath): string { return strtr($filePath, (array)array_combine(array_map(function (string $tokenName) { return '<' . $tokenName . '>'; }, $this->tokenNames), array_fill(0, count($this->tokenNames), ''))); } } __halt_compiler();----SIGNATURE:----b5pJj9r5ZFsEjpTc/F3Wo7VQWesY6evH9z2XoIYrThEoU1pDhgp3H5EvJG0+w/oJihzcq3d3zicoFzR/gvT7f7bPjE01SlX7frheECMZuLCK4UL/hondHwvaqSN1r1/IbZccIE/l/GnsLd/49s+3hMKIDtv8xUw3ncqALAOw5TbWmrgTYa2oryfjFExKxngZSN5Bp8c5uxd8inCvwWYk283/m13/j5iJJsLCeTwTQBZ/IaL6zZFZcxpAXLQ58AVa8VzQJav5QzFR46aDkrVY63TNubCRS18fDgxcj/SeyyBlJB/7ZxSY5eDwuGgczIv1Ey3JuetYdsxXwRgdzFkGn+8uKCKv+QDqzb2LGyCmh0w2jdFmku3KLj76E32vtHdHl+gB7BuMMF10vUFKIjSI/z7gi0fiyRe0Yv/OQoxsHS/ANKMmAMu1e5NV+K95/mE71x752D/1ijF1Lh2TABJbGCsdANfAZdq89/JLd7TRgwCxtEadTR0wkOspYBjSz8h/Bh3xPyKe9nmsEZLXhZ1Wqp3XHcTpykH4pSjLM/c12S9lBv2PMGxKyEX0nyvqPX0Y8giMNhdMW6o2gzJvDouUu2/+jCxhimBou/g7KBqtMGt6M34PevkHSFxJlcyuCc7bBbA0Km/GdpF26XLwsg7LpHa7LB8LxuX8KxYGaCUYruU=----ATTACHMENT:----NTUyMzkyMDcwNTY1MjI1MyA5MDc2MTYzMzA0Nzc5OTggMjc5NTA4ODYxNzgwMDIwNQ==