php
if (Glob::match('/project/views/index.html.twig', '/project/**.twig')) {
path matches
}
public static match ( string $path, string $glob, integer $flags ) : boolean | ||
$path | string | The path to match. |
$glob | string | The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. |
$flags | integer | A bitwise combination of the flag constants in this class. |
return | boolean | Returns `true` if the path is matched by the glob. |
/** * {@inheritdoc} */ public function generateUrl($repositoryPath, $currentUrl = null) { $matchedBinding = null; $bindings = $this->discovery->findBindings(self::BINDING_TYPE); foreach ($bindings as $binding) { /** @var ResourceBinding $binding */ if (Glob::match($repositoryPath, $binding->getQuery())) { $matchedBinding = $binding; break; } } if (null === $matchedBinding) { throw new CannotGenerateUrlException(sprintf('Cannot generate URL for "%s". The path is not public.', $repositoryPath)); } // We can't prevent a resource to be mapped to more than one public path // For now, we'll just take the first one and make the user responsible // for preventing duplicates $url = $this->generateUrlForBinding($matchedBinding, $repositoryPath); if ($currentUrl) { try { $url = Url::makeRelative($url, $currentUrl); } catch (InvalidArgumentException $e) { throw new CannotGenerateUrlException(sprintf('Cannot generate URL for "%s" to current url "%s".', $repositoryPath, $currentUrl), $e->getCode(), $e); } } return $url; }
static function matchesGlobs($basePath, $path, $globArr) { foreach ($globArr as $glob) { if ($glob[0] == '/') { if (Glob::match($path, $glob)) { return true; } } else { if (Glob::match($path, $basePath . "/" . $glob)) { return true; } } } return false; }
public function try_file_filter() { if (!check_ajax_referer('my-wp-backup-fileFilter', 'nonce')) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } if (!isset($_POST['filters'])) { // input var okay wp_die(); } $filters = array_map('sanitize_text_field', preg_split("/\r\n|\n|\r/", $_POST['filters'])); //input var okay; $excluded = array(); /** * @param \SplFileInfo $file * @return bool True if you need to recurse or if the item is acceptable */ $filter = function ($file) use($filters, &$excluded) { $filePath = $file->getPathname(); $relativePath = substr($filePath, strlen(MyWPBackup::$info['root_dir'])); if ($file->isDir()) { $relativePath .= '/'; } foreach ($filters as $exclude) { if (Glob::match($filePath, Path::makeAbsolute($exclude, MyWPBackup::$info['root_dir']))) { array_push($excluded, $relativePath); return false; } } return true; }; $files = new \RecursiveIteratorIterator(new RecursiveCallbackFilterIterator(new \RecursiveDirectoryIterator(MyWPBackup::$info['root_dir'], \RecursiveDirectoryIterator::SKIP_DOTS), $filter)); iterator_to_array($files); wp_send_json($excluded); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage *.css */ public function testMatchFailsIfNotAbsolute() { Glob::match('/foo/bar.css', '*.css'); }
/** * Execute this builder. * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { if (Glob::match($request->getUri()->getPath(), $this->uriPattern)) { $runner = new Runner(array_merge($this->queue, [$this->endPoint])); $response = $runner($request, $response->withStatus(200)); if ($response->getStatusCode() === 200) { return $response; } } return $next($request, $response); }
/** * Returns whether a resource path matches a query. * * @param string $resourcePath The resource path. * @param string $query The resource query of a binding. * * @return bool Returns `true` if the resource path matches the query. */ protected function resourcePathMatchesQuery($resourcePath, $query) { if (false !== strpos($query, '*')) { return Glob::match($resourcePath, $query); } return $query === $resourcePath || Path::isBasePath($query, $resourcePath); }
/** * Exclude the given path? * TODO: extract (to trait?). * * @param $path * @param $globArray * * @return bool */ protected function exclude($path, $globArray = []) { $path = str_replace(["\n", "\r", "\t"], '', $path); if (!is_array($globArray)) { return false; } foreach ($globArray as $pattern) { if (Glob::match('/' . $path, Path::makeAbsolute($pattern, '/'))) { return true; } } return false; }