Generate a .info file
This commit is contained in:
parent
000716d670
commit
55ca3647c4
6 changed files with 255 additions and 69 deletions
src/Command
|
@ -7,11 +7,31 @@ use Symfony\Component\Console\Command\Command;
|
|||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
class GenerateDrupal7Command extends Command
|
||||
{
|
||||
/** @var Filesystem */
|
||||
private $filesystem;
|
||||
|
||||
/** @var Finder */
|
||||
private $finder;
|
||||
|
||||
/** @var SymfonyStyle $io */
|
||||
private $io;
|
||||
|
||||
private $moduleName;
|
||||
|
||||
public function __construct(Finder $finder, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->finder = $finder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -32,11 +52,14 @@ class GenerateDrupal7Command extends Command
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->io = new SymfonyStyle($input, $output);
|
||||
|
||||
$this->moduleName = $input->getArgument('module-name');
|
||||
|
||||
$this->ensureDirectoryDoesNotExist();
|
||||
|
||||
mkdir($this->moduleName);
|
||||
$this
|
||||
->ensureDirectoryDoesNotExist()
|
||||
->createModuleDirectory()
|
||||
->createFiles();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -49,5 +72,40 @@ class GenerateDrupal7Command extends Command
|
|||
if (is_dir($this->moduleName)) {
|
||||
throw CannotCreateModuleException::directoryAlreadyExists();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function createModuleDirectory()
|
||||
{
|
||||
mkdir($this->moduleName);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function createFiles()
|
||||
{
|
||||
$createdFiles = [];
|
||||
|
||||
/** @var SplFileInfo $file */
|
||||
foreach ($this->finder->in('fixtures/drupal7_module')->name('/.info/') as $file) {
|
||||
$contents = $this->updateFileContents($file->getContents());
|
||||
|
||||
file_put_contents(
|
||||
"{$this->moduleName}/{$this->moduleName}.{$file->getExtension()}",
|
||||
$contents
|
||||
);
|
||||
|
||||
$createdFiles[] = "{$this->moduleName}.{$file->getExtension()}";
|
||||
}
|
||||
|
||||
$this->io->definitionList($createdFiles);
|
||||
}
|
||||
|
||||
private function updateFileContents($contents)
|
||||
{
|
||||
$contents = str_replace('{{ name }}', $this->moduleName, $contents);
|
||||
|
||||
return $contents;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue