First commit with working command entity question bundle

This commit is contained in:
Tim 2022-09-23 22:36:08 +02:00
commit 1e74905cb5
7 changed files with 1485 additions and 0 deletions

22
.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
/temp

15
composer.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "ardent/util-bundle",
"description": "Some utilities usefull for multiple projects",
"type": "symfony-bundle",
"license": "GPL-3.0-only",
"autoload": {
"psr-4": {
"Ardent\\UtilBundle\\": "src/"
}
},
"require": {
"symfony/http-kernel": "^6.1",
"symfony/console": "^6.1"
}
}

1341
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
src/ArdentUtilBundle.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace Ardent\UtilBundle;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
class ArdentUtilBundle extends AbstractBundle
{
}

View File

@ -0,0 +1,30 @@
<?php
namespace Ardent\UtilBundle\Command;
use Ardent\UtilBundle\EntityBuilder\Builder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
abstract class AbstractEntityCommand extends Command
{
abstract function getConfig(): Builder;
protected function configure(): void
{
$this
->addOption('create', 'c', InputOption::VALUE_NONE, 'Create entity')
->addOption('edit', 'e', InputOption::VALUE_NONE, 'Edit entity')
->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete entity')
->addOption('show', 's', InputOption::VALUE_NONE, 'Show entity');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Ardent\UtilBundle\EntityBuilder;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;
class Builder
{
/**
* @var SimpleElement[]
*/
private array $elements = [];
public function __construct(
private readonly SymfonyStyle $io,
)
{
}
public function add(SimpleElement|string $element): self
{
if (is_string($element)) {
$element = new SimpleElement($element);
}
$this->elements[] = $element;
return $this;
}
public function setObject(mixed $object): void
{
foreach ($this->elements as $element) {
$setter = sprintf('set%s', ucfirst($element->getProperty()));
if (!method_exists($object, $setter)) {
throw new Exception(sprintf('Object does not have setter "%s"', $setter));
}
$object->$setter($this->io->askQuestion($element->getQuestion()));
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Ardent\UtilBundle\EntityBuilder;
use Symfony\Component\Console\Question\Question;
class SimpleElement
{
public function getQuestion(): Question
{
$name = ucfirst(strtolower(implode(' ', preg_split('/(?=[A-Z])/', $this->getProperty()))));
return new Question($name);
}
public function __construct(
private readonly string $property,
private readonly array $config = [],
)
{
}
public function getProperty(): string
{
return $this->property;
}
}