-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from KejawenLab/5.4
5.4
- Loading branch information
Showing
76 changed files
with
201 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,12 +295,14 @@ php bin/console cron:stop | |
|
||
declare(strict_types=1); | ||
|
||
namespace KejawenLab\ApiSkeleton\Application\Test\Model; | ||
namespace KejawenLab\Application\Test\Model; | ||
|
||
use KejawenLab\ApiSkeleton\Entity\EntityInterface; | ||
|
||
/** | ||
* @author Muhamad Surya Iksanudin<surya[email protected]> | ||
*/ | ||
interface TestInterface | ||
interface TestInterface extends EntityInterface | ||
{ | ||
public function getId(): ?string; | ||
|
||
|
@@ -316,16 +318,15 @@ interface TestInterface | |
|
||
declare(strict_types=1); | ||
|
||
namespace KejawenLab\ApiSkeleton\Application\Entity; | ||
namespace KejawenLab\Application\Entity; | ||
|
||
use DH\DoctrineAuditBundle\Annotation\Auditable; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\Blameable\Traits\BlameableEntity; | ||
use Gedmo\Mapping\Annotation as Gedmo; | ||
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity; | ||
use Gedmo\Timestampable\Traits\TimestampableEntity; | ||
use KejawenLab\ApiSkeleton\Application\Repository\TestRepository; | ||
use KejawenLab\ApiSkeleton\Application\Test\Model\TestInterface; | ||
use KejawenLab\Application\Repository\TestRepository; | ||
use KejawenLab\Application\Test\Model\TestInterface; | ||
use KejawenLab\ApiSkeleton\Util\StringUtil; | ||
use Ramsey\Uuid\UuidInterface; | ||
use OpenApi\Annotations as OA; | ||
|
@@ -337,7 +338,6 @@ use Symfony\Component\Validator\Constraints as Assert; | |
* @ORM\Table(name="test_table") | ||
* | ||
* @Gedmo\SoftDeleteable(fieldName="deletedAt") | ||
* @Auditable() | ||
*/ | ||
class Test implements TestInterface | ||
{ | ||
|
@@ -403,7 +403,7 @@ php bin/console semart:generate Test | |
#### Update form type | ||
|
||
```php | ||
//class: KejawenLab\ApiSkeleton\Application\Form\TestType | ||
//class: KejawenLab\Application\Form\TestType | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add('name'); | ||
|
@@ -413,7 +413,7 @@ php bin/console semart:generate Test | |
#### Update search query extension | ||
|
||
```php | ||
//class: KejawenLab\ApiSkeleton\Application\Test\Query\SearchQueryExtension | ||
//class: KejawenLab\Application\Test\Query\SearchQueryExtension | ||
public function apply(QueryBuilder $queryBuilder, Request $request): void | ||
{ | ||
$query = $request->query->get('q'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,38 @@ | |
|
||
namespace KejawenLab\ApiSkeleton\Generator; | ||
|
||
use DH\Auditor\Provider\Doctrine\Persistence\Reader\Reader; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use KejawenLab\ApiSkeleton\Util\StringUtil; | ||
use ReflectionClass; | ||
use ReflectionProperty; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Twig\Environment; | ||
|
||
/** | ||
* @author Muhamad Surya Iksanudin<[email protected]> | ||
*/ | ||
final class AdminTemplateGenerator extends AbstractGenerator | ||
{ | ||
public function __construct( | ||
private Reader $reader, | ||
Environment $twig, | ||
Filesystem $fileSystem, | ||
KernelInterface $kernel, | ||
EntityManagerInterface $entityManager | ||
) { | ||
parent::__construct($twig, $fileSystem, $kernel, $entityManager); | ||
} | ||
|
||
public function generate(ReflectionClass $class, OutputInterface $output, ?string $folder = null): void | ||
{ | ||
$projectDir = $this->kernel->getProjectDir(); | ||
$shortName = $class->getShortName(); | ||
$lowercase = StringUtil::lowercase($shortName); | ||
$properties = $class->getProperties(ReflectionProperty::IS_PRIVATE); | ||
$deleteField = sprintf('semart_print(%s)', $shortName); | ||
$deleteField = sprintf('semart_print(%s)', $lowercase); | ||
$tableFields = ''; | ||
foreach ($properties as $property) { | ||
if ('id' === $property->getName()) { | ||
|
@@ -31,26 +46,32 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin | |
} | ||
|
||
$search = [ | ||
'{# entity #}', | ||
'{# entity | lower #}', | ||
'{# delete_field #}', | ||
'{# table_fields #}', | ||
]; | ||
$replace = [$lowercase, $deleteField, $tableFields]; | ||
$replace = [$shortName, $lowercase, $deleteField, $tableFields]; | ||
$form = 'templates/generator/admin/view/form.html.stub'; | ||
if ($this->hasAssociation($class)) { | ||
$form = 'templates/generator/admin/view/form.select2.html.stub'; | ||
} | ||
|
||
$template = 'no-audit-view.html.stub'; | ||
if ($this->reader->getProvider()->isAuditable($class->getName())) { | ||
$template = 'view.html.stub'; | ||
} | ||
|
||
$indexTemplate = str_replace($search, $replace, (string) file_get_contents(sprintf('%s/templates/generator/admin/view/all.html.stub', $projectDir))); | ||
$formTemplate = str_replace($search, $replace, (string) file_get_contents(sprintf('%s/%s', $projectDir, $form))); | ||
$tableTemplate = str_replace($search, $replace, (string) file_get_contents(sprintf('%s/templates/generator/admin/view/view.html.stub', $projectDir))); | ||
$viewTemplate = str_replace($search, $replace, (string) file_get_contents(sprintf('%s/templates/generator/admin/view/%s', $projectDir, $template))); | ||
|
||
$output->writeln(sprintf('<comment>Generating template <info>"%s/all.html.twig"</info></comment>', $lowercase)); | ||
$this->fileSystem->dumpFile(sprintf('%s/templates/%s/all.html.twig', $projectDir, $lowercase), $indexTemplate); | ||
$output->writeln(sprintf('<comment>Generating template <info>"%s/form.html.twig"</info></comment>', $lowercase)); | ||
$this->fileSystem->dumpFile(sprintf('%s/templates/%s/form.html.twig', $projectDir, $lowercase), $formTemplate); | ||
$output->writeln(sprintf('<comment>Generating template <info>"%s/view.html.twig"</info></comment>', $lowercase)); | ||
$this->fileSystem->dumpFile(sprintf('%s/templates/%s/view.html.twig', $projectDir, $lowercase), $tableTemplate); | ||
$this->fileSystem->dumpFile(sprintf('%s/templates/%s/view.html.twig', $projectDir, $lowercase), $viewTemplate); | ||
} | ||
|
||
public function support(string $scope): bool | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.