mergeSource() public method

Merge a source
public mergeSource ( Sculpin\Core\Source\SourceInterface $source )
$source Sculpin\Core\Source\SourceInterface
Example #1
0
 public function testMergeSource()
 {
     $source000a = $this->makeTestSource('TestSource:000');
     $source000a->expects($this->any())->method('content')->will($this->returnValue('a'));
     $source000b = $this->makeTestSource('TestSource:000');
     $source000b->expects($this->any())->method('content')->will($this->returnValue('b'));
     $sourceSet = new SourceSet();
     $this->assertFalse($sourceSet->containsSource($source000a));
     $sourceSet->mergeSource($source000a);
     $this->assertTrue($sourceSet->containsSource($source000a));
     $internalSources = $sourceSet->allSources();
     $this->assertEquals('a', $internalSources['TestSource:000']->content());
     $sourceSet->mergeSource($source000b);
     $internalSources = $sourceSet->allSources();
     $this->assertEquals('b', $internalSources['TestSource:000']->content());
 }
 /**
  * Generate
  *
  * @param  SourceInterface           $source    Source
  * @param  SourceSet                 $sourceSet Source set
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 public function generate(SourceInterface $source, SourceSet $sourceSet)
 {
     $data = $source->data();
     $generators = array();
     $isGenerator = $source->isGenerator();
     if ($generatorNames = $data->get('generator')) {
         if (!$isGenerator) {
             $source->setIsGenerator();
         }
         $generatorNames = (array) $generatorNames;
         foreach ($generatorNames as $generatorName) {
             if (!isset($this->generators[$generatorName])) {
                 throw new \InvalidArgumentException("Requested generator '{$generatorName}' could not be found; was it registered?");
             }
             $generators[] = $this->generators[$generatorName];
         }
     } else {
         if ($isGenerator) {
             $source->setIsNotGenerator();
         }
         return;
     }
     $targetSources = array($source);
     foreach ($generators as $generator) {
         $newTargetSources = array();
         foreach ($targetSources as $targetSource) {
             foreach ((array) $generator->generate($targetSource) as $generatedSource) {
                 $generatedSource->setIsGenerated();
                 $newTargetSources[] = $generatedSource;
             }
         }
         $targetSources = $newTargetSources;
     }
     foreach ($targetSources as $generatedSource) {
         $sourceSet->mergeSource($generatedSource);
     }
 }
 /**
  * {@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();
         }
     }
 }