Yosymfony\Spress\Scaffolding\PluginGenerator::generate PHP Method

generate() public method

Generates a plugin.
public generate ( ) : array
return array
    public function generate()
    {
        $this->dirctoryName = $this->getPluginDir($this->name);
        $pluginDir = $this->targetDir . '/' . $this->dirctoryName;
        if (file_exists($pluginDir)) {
            throw new \RuntimeException(sprintf('Unable to generate the plugin as the plugin directory "%s" exists.', $pluginDir));
        }
        $model = ['name' => $this->name, 'classname' => $this->getClassname($this->name), 'namespace' => $this->namespace, 'namespace_psr4' => $this->getNamespacePsr4($this->namespace), 'author' => $this->author, 'email' => $this->email, 'description' => $this->description, 'license' => $this->license];
        $this->cleanFilesAffected();
        $pluginTemplateFile = 'plugin/plugin.php.twig';
        if (empty($this->commandName) === false) {
            $pluginTemplateFile = 'plugin/commandPlugin.php.twig';
            $model['command_name'] = $this->commandName;
            $model['command_description'] = $this->commandDescription;
            $model['command_help'] = $this->commandHelp;
        }
        $this->renderFile($pluginTemplateFile, $pluginDir . '/' . $this->getPluginFilename($this->name), $model);
        $this->renderFile('plugin/composer.json.twig', $pluginDir . '/composer.json', $model);
        $licenseFile = $this->getLicenseFile($this->license);
        if ($licenseFile) {
            $model = ['author' => $this->author];
            $this->renderFile($licenseFile, $pluginDir . '/LICENSE', $model);
        }
        return $this->getFilesAffected();
    }

Usage Example

Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output);
     $name = Validators::validatePluginName($input->getOption('name'));
     $commandName = $input->getOption('command-name');
     if (empty($commandName) === false) {
         $commandName = Validators::validateCommandName($commandName);
     }
     $commandDescription = $input->getOption('command-description');
     $commandHelp = $input->getOption('command-help');
     $author = $input->getOption('author');
     $email = $input->getOption('email');
     if (empty($email) === false) {
         $email = Validators::validateEmail($email);
     }
     $description = $input->getOption('description');
     $license = $input->getOption('license') ?: 'MIT';
     $generator = new PluginGenerator('./src/plugins', $name);
     $generator->setSkeletonDirs([__DIR__ . '/../../app/skeletons']);
     $generator->setCommandData($commandName, $commandDescription, $commandHelp);
     $generator->setAuthor($author, $email);
     $generator->setDescription($description);
     $generator->setLicense($license);
     $files = $generator->generate();
     $this->resultMessage($io, $files);
 }
All Usage Examples Of Yosymfony\Spress\Scaffolding\PluginGenerator::generate