/** * Handle the command. * */ public function handle() { $module = $this->module; $stream = $this->stream; $assignment = $this->assignment; $destination = $module->getPath(); $entity = __DIR__ . '/../../resources/stubs/entity'; $source = $entity . '/code/{namespace}/'; /* get the field config params from build.php */ $fieldConfig = _getFieldConfig($module, $stream->getNamespace(), $assignment->getFieldSlug()); /* set a list of files to avoid overwrite */ $this->files->setAvoidOverwrite(_getAvoidOverwrite($module)); /* get the template data */ $data = $this->getTemplateData($module, $stream, $assignment, $fieldConfig); /* get the namespace destination folder, if any! */ $namespaceFolder = _getNamespaceFolder($module, $data['namespace'], true); $entityDest = $destination . '/src/' . $namespaceFolder . $data['entity_name']; /* get the assigned class name, i.e. TextFieldType */ $fieldTypeClassName = _getFieldTypeClassName($assignment); /* (1) process the form builder class */ if (!$fieldConfig['hide_field']) { $this->processFormBuilder($entityDest . '/Form/' . $data['entity_name'] . 'FormBuilder.php', $entity . '/templates/field/form/', $fieldTypeClassName, $data); } /* (2) process the table column class */ if (!$fieldConfig['hide_column']) { $this->processTableColumns($entityDest . '/Table/' . $data['entity_name'] . 'TableColumns.php', $entity . '/templates/field/table/' . ($data['column_template'] ? 'template/' : ''), $fieldTypeClassName, $data); } /* (3) process the field language file */ $this->processFile($destination . '/resources/lang/en/field.php', [$data['field_slug'] => $entity . '/templates/module/field.php'], $data); }
/** * Handle the command. * */ public function handle() { $stream = $this->stream; $module = $this->module; $entityPath = __DIR__ . '/../../resources/stubs/entity'; $modulePath = __DIR__ . '/../../resources/stubs/module'; $namespace_folder = _getNamespaceFolderTemplate($module); $data = $this->getTemplateData($module, $stream); /* uncomment the array entries to protect these files from being overwriten or add your own */ $this->files->setAvoidOverwrite(_getAvoidOverwrite($module, [])); $dest = $module->getPath(); /* initially, copy the template files to the entity's src folder */ $this->files->parseDirectory($entityPath . "/code/{$namespace_folder}", $dest . '/src', $data); /* create an empty seeder if it does not exist */ $this->put($dest . '/resources/seeders/' . $data['entity_name_lower'] . '.php', '', true); try { /* secondly, stitch the entity with the module classes */ $this->processFile($dest . '/src/' . $data['module_name'] . 'ModuleServiceProvider.php', ['routes' => $entityPath . '/templates/module/routes.php', 'bindings' => $entityPath . '/templates/module/bindings.php', 'singletons' => $entityPath . '/templates/module/singletons.php'], $data); $this->processFile($dest . '/src/' . $data['module_name'] . 'Module.php', ['sections' => $entityPath . '/templates/module/sections.php'], $data); $this->processFile($dest . '/src/' . $data['module_name'] . 'ModuleSeeder.php', ['seeders' => $entityPath . '/templates/module/seeding.php'], $data); $this->processFile($dest . '/resources/lang/en/section.php', [$data['entity_name_lower_plural'] => $entityPath . '/templates/module/section.php'], $data); $this->processFile($dest . '/resources/lang/en/stream.php', [$data['stream_slug'] => $entityPath . '/templates/module/stream.php'], $data); } catch (\PhpParser\Error $e) { die($e->getMessage()); } }