Skip to content

Commit

Permalink
Merge pull request #55 from KejawenLab/5.4
Browse files Browse the repository at this point in the history
5.4
  • Loading branch information
ad3n authored Jul 7, 2021
2 parents 1d787ad + 0eb5664 commit fd378b5
Show file tree
Hide file tree
Showing 76 changed files with 201 additions and 99 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@
"autoload": {
"psr-4": {
"KejawenLab\\ApiSkeleton\\": "lib/",
"KejawenLab\\ApiSkeleton\\Application\\": "app/"
"KejawenLab\\Application\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"KejawenLab\\ApiSkeleton\\Tests\\": "tests/"
"KejawenLab\\ApiSkeleton\\Tests\\": "tests/lib",
"KejawenLab\\Application\\Tests\\": "tests/app"
}
},
"replace": {
Expand Down
2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ doctrine:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/app/Entity'
prefix: 'KejawenLab\ApiSkeleton\Application\Entity'
prefix: 'KejawenLab\Application\Entity'
alias: App
6 changes: 3 additions & 3 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
KejawenLab\ApiSkeleton\:
resource: '../lib/*'
exclude: '../lib/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
KejawenLab\ApiSkeleton\Application\:
KejawenLab\Application\:
resource: '../app/*'
exclude: '../app/{Entity,Migrations,Tests}'

Expand All @@ -36,10 +36,10 @@ services:
KejawenLab\ApiSkeleton\Admin\Controller\:
resource: '../lib/Admin/Controller'
tags: ['controller.service_arguments']
KejawenLab\ApiSkeleton\Application\Controller\:
KejawenLab\Application\Controller\:
resource: '../app/Controller'
tags: [ 'controller.service_arguments' ]
KejawenLab\ApiSkeleton\Application\Admin\Controller\:
KejawenLab\Application\Admin\Controller\:
resource: '../app/Admin/Controller'
tags: [ 'controller.service_arguments' ]

Expand Down
4 changes: 2 additions & 2 deletions doc/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Secara otomatis, Semart Generator akan men-*generate* semua *property* yang ada

declare(strict_types=1);

namespace KejawenLab\ApiSkeleton\Application\Form;
namespace KejawenLab\Application\Form;

use KejawenLab\ApiSkeleton\Application\Entity\Test;
use KejawenLab\Application\Entity\Test;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand Down
4 changes: 2 additions & 2 deletions doc/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Ketika menggunakan [Semart Generator](generator.md), secara otomatis, akan dibua

declare(strict_types=1);

namespace KejawenLab\ApiSkeleton\Application\Test\Query;
namespace KejawenLab\Application\Test\Query;

use Doctrine\ORM\QueryBuilder;
use KejawenLab\ApiSkeleton\Application\Test\Model\TestInterface;
use KejawenLab\Application\Test\Model\TestInterface;
use KejawenLab\ApiSkeleton\Pagination\Query\AbstractQueryExtension;
use KejawenLab\ApiSkeleton\Util\StringUtil;
use Symfony\Component\HttpFoundation\Request;
Expand Down
10 changes: 9 additions & 1 deletion lib/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace KejawenLab\ApiSkeleton\Command;

use Exception;
use KejawenLab\ApiSkeleton\Generator\GeneratorFactory;
use KejawenLab\ApiSkeleton\Generator\Model\GeneratorInterface;
use KejawenLab\ApiSkeleton\Security\Service\MenuService;
Expand All @@ -22,7 +23,7 @@
*/
final class GenerateCommand extends Command
{
private const NAMESPACE = 'KejawenLab\\ApiSkeleton\\Application\\Entity';
private const NAMESPACE = 'KejawenLab\\Application\\Entity';

public function __construct(private GeneratorFactory $generator, private MenuService $menuService)
{
Expand All @@ -45,6 +46,7 @@ protected function configure(): void

/**
* @throws ReflectionException
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Expand Down Expand Up @@ -103,6 +105,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln(sprintf('<comment>RESTful Api and/or Admin files for class <info>"%s"</info> has been generated</comment>', $reflection->getName()));

$output->writeln('<info>Clearing Cache</info>');
$update = $application->find('cache:clear');
$update->run(new ArrayInput([
'command' => 'cache:clear',
]), $output);

return 0;
}
}
2 changes: 1 addition & 1 deletion lib/Controller/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace KejawenLab\ApiSkeleton\Controller;

use KejawenLab\ApiSkeleton\Application\App;
use KejawenLab\Application\App;
use KejawenLab\ApiSkeleton\SemartApiSkeleton;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down
2 changes: 1 addition & 1 deletion lib/EventSubscriber/LoadUrlPathSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
final class LoadUrlPathSubscriber implements EventSubscriber
{
private const ROUTE_NAMESPACE_PREFIX = 'KejawenLab\\ApiSkeleton\\Application\\Controller\\';
private const ROUTE_NAMESPACE_PREFIX = 'KejawenLab\\Application\\Controller\\';

private array $reservedRoutes = [
'KejawenLab\\ApiSkeleton\\Controller\\Me\\Profile',
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/AdminControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class AdminControllerGenerator extends AbstractGenerator
{
private const CONTROLLER_PREFIX = 'KejawenLab\\ApiSkeleton\\Application\\Admin\\Controller';
private const CONTROLLER_PREFIX = 'KejawenLab\\Application\\Admin\\Controller';

public function __construct(
private Reader $reader,
Expand Down
29 changes: 25 additions & 4 deletions lib/Generator/AdminTemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/ApiControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class ApiControllerGenerator extends AbstractGenerator
{
private const CONTROLLER_PREFIX = 'KejawenLab\\ApiSkeleton\\Application\\Controller';
private const CONTROLLER_PREFIX = 'KejawenLab\\Application\\Controller';

public function __construct(
private Reader $reader,
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/FormGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin
'properties' => $properties,
]);

$output->writeln(sprintf('<comment>Generating class <info>"KejawenLab\\ApiSkeleton\\Application\\Form\\%sType"</info></comment>', $shortName));
$output->writeln(sprintf('<comment>Generating class <info>"KejawenLab\\Application\\Form\\%sType"</info></comment>', $shortName));
$this->fileSystem->dumpFile($formFile, $template);
} else {
$output->writeln(sprintf('<info>File "%s" is exists. Skipped</info>', $formFile));
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/PermissionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
final class PermissionGenerator extends AbstractGenerator
{
private const ROUTE_PLACEHOLDER = 'KejawenLab\\ApiSkeleton\\Application\\Controller\\%s\\GetAll';
private const ROUTE_PLACEHOLDER = 'KejawenLab\\Application\\Controller\\%s\\GetAll';

public function __construct(
private PermissionService $permissionService,
Expand Down
4 changes: 2 additions & 2 deletions lib/Generator/RepositoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin
{
$shortName = $class->getShortName();
$repositoryFile = sprintf('%s/app/Repository/%sRepository.php', $this->kernel->getProjectDir(), $shortName);
$output->writeln(sprintf('<comment>Generating class <info>"KejawenLab\\ApiSkeleton\\Application\\Repository\\%sRepository"</info></comment>', $shortName));
$output->writeln(sprintf('<comment>Generating class <info>"KejawenLab\\Application\\Repository\\%sRepository"</info></comment>', $shortName));
if (!$this->fileSystem->exists($repositoryFile)) {
$repository = $this->twig->render('generator/repository.php.twig', ['entity' => $shortName]);
$this->fileSystem->dumpFile($repositoryFile, $repository);
Expand All @@ -34,7 +34,7 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin

$repositoryModelFile = sprintf('%s/app/%s/Model/%sRepositoryInterface.php', $this->kernel->getProjectDir(), ($folder ?: $shortName), $shortName);
$output->writeln(sprintf(
'<comment>Generating class <info>"KejawenLab\\ApiSkeleton\\Application\\%s\\Model\\%sRepositoryInterface"</info></comment>',
'<comment>Generating class <info>"KejawenLab\\Application\\%s\\Model\\%sRepositoryInterface"</info></comment>',
($folder ?: $shortName),
$shortName
));
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/SearchQueryExtensionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin
if (!$this->fileSystem->exists($queryFile)) {
$template = $this->twig->render('generator/search_query.php.twig', ['entity' => $shortName]);
$output->writeln(sprintf(
'<comment>Generating class <info>"KejawenLab\\ApiSkeleton\\Application\\%s\\Query\\%sQueryExtension"</info></comment>',
'<comment>Generating class <info>"KejawenLab\\Application\\%s\\Query\\%sQueryExtension"</info></comment>',
($folder ?: $shortName),
$shortName
));
Expand Down
2 changes: 1 addition & 1 deletion lib/Generator/ServiceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generate(ReflectionClass $class, OutputInterface $output, ?strin
if (!$this->fileSystem->exists($serviceFile)) {
$template = $this->twig->render('generator/service.php.twig', ['entity' => $shortName]);
$output->writeln(sprintf(
'<comment>Generating class <info>"KejawenLab\\ApiSkeleton\\Application\\%s\\%sService"</info></comment>',
'<comment>Generating class <info>"KejawenLab\\Application\\%s\\%sService"</info></comment>',
($folder ?: $shortName),
$shortName
));
Expand Down
6 changes: 3 additions & 3 deletions templates/generator/admin/audit.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
declare(strict_types=1);
namespace Kejawenlab\ApiSkeleton\Application\Controller\Admin\Controller\{{ entityHumanize }};
namespace KejawenLab\Application\Admin\Controller\{{ entityHumanize }};
use DH\Auditor\Provider\Doctrine\Persistence\Reader\Reader;
use Kejawenlab\ApiSkeleton\Application\Entity\{{ entityHumanize }};
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\Application\Entity\{{ entityHumanize }};
use KejawenLab\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\ApiSkeleton\Audit\AuditService;
use KejawenLab\ApiSkeleton\Security\Annotation\Permission;
use KejawenLab\ApiSkeleton\Util\StringUtil;
Expand Down
6 changes: 3 additions & 3 deletions templates/generator/admin/delete.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
declare(strict_types=1);
namespace Kejawenlab\ApiSkeleton\Application\Controller\Admin\Controller\{{ entityHumanize }};
namespace KejawenLab\Application\Admin\Controller\{{ entityHumanize }};
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\Model\{{ entityHumanize }}Interface;
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\Application\{{ entityHumanize }}\Model\{{ entityHumanize }}Interface;
use KejawenLab\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\ApiSkeleton\Security\Annotation\Permission;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down
4 changes: 2 additions & 2 deletions templates/generator/admin/download.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
declare(strict_types=1);
namespace Kejawenlab\ApiSkeleton\Application\Controller\Admin\Controller\{{ entityHumanize }};
namespace KejawenLab\Application\Admin\Controller\{{ entityHumanize }};
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\ApiSkeleton\Security\Annotation\Permission;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down
8 changes: 4 additions & 4 deletions templates/generator/admin/get.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
declare(strict_types=1);
namespace Kejawenlab\ApiSkeleton\Application\Controller\Admin\Controller\{{ entityHumanize }};
namespace KejawenLab\Application\Admin\Controller\{{ entityHumanize }};
use Kejawenlab\ApiSkeleton\Application\Entity\{{ entityHumanize }};
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\Model\{{ entityHumanize }}Interface;
use Kejawenlab\ApiSkeleton\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\Application\Entity\{{ entityHumanize }};
use KejawenLab\Application\{{ entityHumanize }}\Model\{{ entityHumanize }}Interface;
use KejawenLab\Application\{{ entityHumanize }}\{{ entityHumanize }}Service;
use KejawenLab\ApiSkeleton\Security\Annotation\Permission;
use KejawenLab\ApiSkeleton\Util\StringUtil;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down
Loading

0 comments on commit fd378b5

Please sign in to comment.