From d8ca9cf082b4e427252dc1621062bf9802a1fda9 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 18 Aug 2021 17:05:13 +0200 Subject: [PATCH] Api point for docgen templates --- .../DocGeneratorTemplateController.php | 41 ++++++++++++ .../ChillDocGeneratorExtension.php | 15 ++--- .../Entity/DocGeneratorTemplate.php | 2 +- .../DocGeneratorTemplateRepository.php | 65 +++++++++++++++---- .../Resources/config/services.yml | 8 --- .../config/routes.yml => config/routes.yaml} | 2 +- .../config/services.yaml | 10 +++ .../services/controller.yaml} | 3 +- .../services/fixtures.yaml} | 0 .../form.yml => config/services/form.yaml} | 0 10 files changed, 114 insertions(+), 32 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php delete mode 100644 src/Bundle/ChillDocGeneratorBundle/Resources/config/services.yml rename src/Bundle/ChillDocGeneratorBundle/{Resources/config/routes.yml => config/routes.yaml} (58%) create mode 100644 src/Bundle/ChillDocGeneratorBundle/config/services.yaml rename src/Bundle/ChillDocGeneratorBundle/{Resources/config/services/controller.yml => config/services/controller.yaml} (65%) rename src/Bundle/ChillDocGeneratorBundle/{Resources/config/services/fixtures.yml => config/services/fixtures.yaml} (100%) rename src/Bundle/ChillDocGeneratorBundle/{Resources/config/services/form.yml => config/services/form.yaml} (100%) diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php new file mode 100644 index 000000000..0ab610e6b --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -0,0 +1,41 @@ +findByEntity($entityClassName); + + $ret = array(); + + foreach ($entities as $entity) { + $ret[] = array( + 'id' => $entity->getId(), + 'name' => $entity->getName(), + 'description' => $entity->getDescription() + ); + } + + return new JsonResponse(["results" => $ret]); + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php index 24f3a2d01..dfa604d9e 100644 --- a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php +++ b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php @@ -20,14 +20,11 @@ class ChillDocGeneratorExtension extends Extension implements PrependExtensionIn */ public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); - - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); - $loader->load('services/controller.yml'); - $loader->load('services/fixtures.yml'); - $loader->load('services/form.yml'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $loader->load('services.yaml'); + $loader->load('services/controller.yaml'); + $loader->load('services/fixtures.yaml'); + $loader->load('services/form.yaml'); } public function prepend(ContainerBuilder $container) @@ -41,7 +38,7 @@ class ChillDocGeneratorExtension extends Extension implements PrependExtensionIn $container->prependExtensionConfig('chill_main', array( 'routing' => array( 'resources' => array( - '@ChillDocGeneratorBundle/Resources/config/routes.yml' + '@ChillDocGeneratorBundle/config/routes.yaml' ) ) )); diff --git a/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php index bf9c89839..d377773a5 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php +++ b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php @@ -6,7 +6,7 @@ use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=DocGeneratorTemplateRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_docgen_template") */ diff --git a/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php index 83f206d4b..1dc4f41f1 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php +++ b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php @@ -1,21 +1,62 @@ repository = $entityManager->getRepository(DocGeneratorTemplate::class); + } + + public function find($id, $lockMode = null, $lockVersion = null): ?DocGeneratorTemplate + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + public function findOneBy(array $criteria, array $orderBy = null): ?DocGeneratorTemplate + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return DocGeneratorTemplate[] + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return DocGeneratorTemplate[] + */ + public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findByEntity($entity) { + + $builder = $this->repository->createQueryBuilder('t'); + + $builder + ->where('t.entities LIKE :entity') + ->setParameter('entity', '%'.addslashes($entity).'%') + ; + + return $builder->getQuery()->execute(); + } + + public function getClassName() { + return DocGeneratorTemplate::class; } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services.yml b/src/Bundle/ChillDocGeneratorBundle/Resources/config/services.yml deleted file mode 100644 index e77482da3..000000000 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -services: - - Chill\DocGeneratorBundle\Repository\: - autowire: true - resource: '../../Repository/' - tags: - - { name: 'doctrine.repository_service' } diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/config/routes.yml b/src/Bundle/ChillDocGeneratorBundle/config/routes.yaml similarity index 58% rename from src/Bundle/ChillDocGeneratorBundle/Resources/config/routes.yml rename to src/Bundle/ChillDocGeneratorBundle/config/routes.yaml index 72b39e1da..c33caad18 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/config/routes.yml +++ b/src/Bundle/ChillDocGeneratorBundle/config/routes.yaml @@ -1,3 +1,3 @@ chill_docgen_controllers: - resource: '../../Controller/' + resource: '../Controller/' type: annotation diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml new file mode 100644 index 000000000..fb8ec28a1 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml @@ -0,0 +1,10 @@ +--- +services: + _defaults: + autowire: true + autoconfigure: true + + Chill\DocGeneratorBundle\Repository\: + autowire: true + autoconfigure: true + resource: '../Repository/' diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services/controller.yml b/src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml similarity index 65% rename from src/Bundle/ChillDocGeneratorBundle/Resources/config/services/controller.yml rename to src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml index b082fa9af..73d240428 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services/controller.yml +++ b/src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml @@ -1,5 +1,6 @@ services: Chill\DocGeneratorBundle\Controller\: autowire: true - resource: '../../../Controller' + autoconfigure: true + resource: '../../Controller' tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services/fixtures.yml b/src/Bundle/ChillDocGeneratorBundle/config/services/fixtures.yaml similarity index 100% rename from src/Bundle/ChillDocGeneratorBundle/Resources/config/services/fixtures.yml rename to src/Bundle/ChillDocGeneratorBundle/config/services/fixtures.yaml diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/config/services/form.yml b/src/Bundle/ChillDocGeneratorBundle/config/services/form.yaml similarity index 100% rename from src/Bundle/ChillDocGeneratorBundle/Resources/config/services/form.yml rename to src/Bundle/ChillDocGeneratorBundle/config/services/form.yaml