Ejemplo n.º 1
0
 public function testFieldsDefault()
 {
     $optionReader = new OptionReader([]);
     $this->assertFalse($optionReader->isGenerationForced());
     $this->assertEquals($optionReader->getArchitecture(), GeneratorDelegateFactory::ARCH_HEXAGONAL);
     $this->assertEquals($optionReader->getFields(), []);
 }
 /**
  * Primary method to make a generator delegate, finds
  * the architecture required and calls a subsequent
  * method to handle the details.
  * 
  * @param  GenerateCommand          $cmd            cli command that was run
  * @param  array                    $args           cmmand arguments
  * @param  \Console\OptionReader    $optionReader   command options
  * @return Delegates\GeneratorDelegate
  */
 public function make(GenerateCommand $cmd, array $args, OptionReader $optionReader)
 {
     $architecture = $optionReader->getArchitecture();
     switch ($architecture) {
         case static::ARCH_HEXAGONAL:
             $delegate = $this->makeHexagonalGeneratorDelegate($cmd, $args, $optionReader);
             break;
         default:
             throw new \InvalidArgumentException("[{$architecture}] is not a valid architecture option");
             break;
     }
     //end switch
     return $delegate;
 }
Ejemplo n.º 3
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;
 }