/**
  * {@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();
         }
     }
 }
Example #2
0
 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();
 }