Exemplo n.º 1
0
 /**
  * Process the template and automatically fill in the values
  * @param $name
  * @param $fields
  * @return mixed
  */
 protected function generateModelConfigFromTemplate($name, array $fields)
 {
     // Prepare fields
     $listFields = [];
     foreach ($fields as $field) {
         $listFields[$field['property']] = ['title' => $this->translator->translate($field['property'])->toReadableName()];
     }
     // Prepare edit fields
     $editFields = [];
     foreach ($fields as $field) {
         $editFields[$field['property']] = array_merge(['title' => $this->translator->translate($field['property'])->toReadableName(), 'type' => $field['field']->getAdminType()], $field['field']->generateEditFieldsConfiguration());
     }
     // Compile configuration template
     return $this->generator->compile('model_config.txt', ['MODEL_TITLE_SINGULAR' => $name->toReadableName(), 'MODEL_TITLE_PLURAL' => $name->toReadablePlural(), 'MODEL_SINGULAR' => $name->toSingularForm(), 'MODEL_ELOQUENT' => $name->toModelName(), 'MODEL_LIST_COLUMNS' => $listFields, 'MODEL_EDIT_FIELDS' => $editFields]);
 }
Exemplo n.º 2
0
 /**
  * @param $template
  * @param $path
  * @param $data
  * @return int
  */
 protected function renderTemplate($template, $path, $data)
 {
     // Filter input
     $className = str_replace('.php', '', pathinfo($path, PATHINFO_FILENAME));
     // Check if the target file exists
     if ($this->filesystem->exists($path)) {
         $this->error("'{$className}' already exists.");
         return;
     }
     // Create the underlaying directory
     $this->filesystem->makeDirectory(pathinfo($path, PATHINFO_DIRNAME), 0777, true, true);
     // Compile the template
     $this->info("Creating '{$className}' ...");
     $template = $this->generator->compile($template, $data, false);
     return $this->filesystem->put($path, $template);
 }