Ejemplo n.º 1
0
 /**
  * Function to create and write out a parsed template
  * 
  * @param  string $entity         name of the entity being operated on
  * @param  string $sourceTemplate path to the raw template to work with
  * @param  string $destinationDir destination directory to write parsed template into
  * @param  string $fileName       templatized filename (not path) to write to
  * @return bool
  */
 public function make($entity, $sourceTemplate, $destinationDir, $fileName = null)
 {
     //set the entity we're creating for
     //later template parsing operations
     list($this->base, $this->entity) = $this->parseEntity($entity);
     //if any field data was given, parse it
     $fieldData = $this->optionReader->getFields();
     if ($fieldData) {
         $this->fieldData = $this->fieldParser->parse($fieldData);
     }
     //set local var for template vars used for subsequent calls
     $templateVars = $this->getTemplateVars();
     //set into a class var vor getFileName() to use if necessary
     if (!is_null($fileName)) {
         $this->destinationFileName = $this->mustache->render($fileName, $templateVars);
     }
     //parse any template values in the destinationDir
     $destinationDir = $this->mustache->render($destinationDir, $templateVars);
     //get the compiled template
     $this->parsedTemplate = $this->getTemplate($sourceTemplate);
     //find out where to write the file
     $this->templateDestination = implode(DIRECTORY_SEPARATOR, [$destinationDir, $this->getFileName()]);
     //dir where template will be written
     $templateDestinationDir = pathinfo($this->templateDestination, PATHINFO_DIRNAME);
     //create directory rendered template will go into if necessary
     if (!$this->filesystem->exists($templateDestinationDir)) {
         $this->filesystem->makeDirectory($templateDestinationDir, 0777, true);
     }
     //actually do the write operation
     if (!$this->filesystem->exists($this->templateDestination) || $this->optionReader->isGenerationForced()) {
         return $this->filesystem->put($this->templateDestination, $this->parsedTemplate) !== false;
     }
     return false;
 }
Ejemplo n.º 2
0
 public function testFieldsDefault()
 {
     $optionReader = new OptionReader([]);
     $this->assertFalse($optionReader->isGenerationForced());
     $this->assertEquals($optionReader->getArchitecture(), GeneratorDelegateFactory::ARCH_HEXAGONAL);
     $this->assertEquals($optionReader->getFields(), []);
 }