Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function setIsGenerator()
 {
     return $this->source->setIsGenerator();
 }
 /**
  * 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);
     }
 }