public function __construct(array $paths, AntPathMatcher $antPathMatcher = null, DirectorySeparatorNormalizer $directorySeparatorNormalizer = null) { if (null === $antPathMatcher) { $antPathMatcher = new AntPathMatcher(); } $this->patterns = array_map(function ($path) use($antPathMatcher) { return $antPathMatcher->isPattern($path) ? $path : $path . '/**'; }, $paths); $this->antPathMatcher = $antPathMatcher; $this->directorySeparatorNormalizer = $directorySeparatorNormalizer ?: new DirectorySeparatorNormalizer(); }
/** * {@inheritdoc} */ public function refresh(SourceSet $sourceSet) { $sinceTimeLast = $this->sinceTime; $this->sinceTime = date('c'); // We regenerate the whole site if an excluded file changes. $excludedFilesHaveChanged = false; $files = $this->finderFactory->createFinder()->files()->ignoreVCS(true)->ignoreDotFiles(false)->date('>=' . $sinceTimeLast)->followLinks()->in($this->sourceDir); $sinceTimeLastSeconds = strtotime($sinceTimeLast); foreach ($files as $file) { if ($sinceTimeLastSeconds > $file->getMTime()) { // This is a hack because Finder is actually incapable // of resolution down to seconds. // // Sometimes this may result in the file looking like it // has been modified twice in a row when it has not. continue; } foreach ($this->ignores as $pattern) { if (!$this->matcher->isPattern($pattern)) { continue; } if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) { // Ignored files are completely ignored. continue 2; } } foreach ($this->excludes as $pattern) { if (!$this->matcher->isPattern($pattern)) { continue; } if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) { $excludedFilesHaveChanged = true; continue 2; } } $isRaw = false; foreach ($this->raws as $pattern) { if (!$this->matcher->isPattern($pattern)) { continue; } if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) { $isRaw = true; break; } } $source = new FileSource($this->analyzer, $this, $file, $isRaw, true); $sourceSet->mergeSource($source); } if ($excludedFilesHaveChanged) { // If any of the exluded files have changed we should // mark all of the sources as having changed. foreach ($sourceSet->allSources() as $source) { $source->setHasChanged(); } } }
/** * Parse the Request Intercept map * * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request * @return void * @throws Exception */ private function parseInterceptMap($request) { // Set up authN/authZ if an URL mapping was given. if (isset($this->config['interceptUrlMap']) && is_array($this->config['interceptUrlMap'])) { // We may need to modify the intercept map, so make a copy of it $interceptMap = $this->config['interceptUrlMap']; // Always allow HEAD requests unless the user specifically blocked them if (!array_key_exists('HEAD', $interceptMap)) { $interceptMap['HEAD'] = ['/**' => ['authN' => 'permitAll', 'authZ' => 'permitAll']]; } // If the request method is not in the intercept map, throw an exception if (!array_key_exists($request->getMethod(), $interceptMap)) { throw new \Exception("Request Type: " . $request->getMethod() . " does not exist in Auth Intercept Map"); } $antPathMatcher = new AntPathMatcher(); foreach ($interceptMap[$request->getMethod()] as $pattern => $auth_array) { // Support RegEx or Ant patterns if ($pattern[0] == '^') { $match = preg_match('/' . $pattern . '/', $request->getUri()->getPath()); } else { $match = $antPathMatcher->match($pattern, $request->getUri()->getPath()); } // Break out of the foreach loop if this URL matches the pattern. if ($match) { $this->authN_type = $auth_array['authN']; $this->authZ_roles = $auth_array['authZ']; break; } } } }
/** * Parse the Request Intercept map * * @param Environment $env Slim environment * @return void * @throws Exception */ private function _parseInterceptMap($env) { // Set up authN/authZ if an URL mapping was given. if (isset($env['auth.interceptUrlMap']) && is_array($env['auth.interceptUrlMap'])) { // We may need to modify the intercept map, so make a copy of it $interceptMap = $env['auth.interceptUrlMap']; // Always allow HEAD requests unless the user specifically blocked them if (!array_key_exists('HEAD', $interceptMap)) { $interceptMap['HEAD'] = ['/**' => ['authN' => 'permitAll', 'authZ' => 'permitAll']]; } // If the request method is not in the Intercept Map, throw an exception if (!array_key_exists($env['REQUEST_METHOD'], $interceptMap)) { throw new \Exception("Request Type: " . $env['REQUEST_METHOD'] . " does not exist in Auth Intercept Map"); } $antPathMatcher = new AntPathMatcher(); foreach ($interceptMap[$env['REQUEST_METHOD']] as $pattern => $auth_array) { // Break out of the foreach loop if this URL matches the pattern. if ($antPathMatcher->match($pattern, $env['PATH_INFO'])) { $this->authN_type = $auth_array['authN']; $this->authZ_roles = $auth_array['authZ']; break; } } } }