mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Api point for docgen templates
This commit is contained in:
parent
9a1f56a820
commit
d8ca9cf082
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Controller;
|
||||
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Class DocGeneratorTemplateController
|
||||
*
|
||||
* @package Chill\DocGeneratorBundle\Controller
|
||||
*/
|
||||
class DocGeneratorTemplateController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/templates/for/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(
|
||||
string $entityClassName, DocGeneratorTemplateRepository $templateRepository): Response
|
||||
{
|
||||
$entities = $templateRepository->findByEntity($entityClassName);
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$ret[] = array(
|
||||
'id' => $entity->getId(),
|
||||
'name' => $entity->getName(),
|
||||
'description' => $entity->getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
return new JsonResponse(["results" => $ret]);
|
||||
}
|
||||
}
|
@ -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'
|
||||
)
|
||||
)
|
||||
));
|
||||
|
@ -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")
|
||||
|
||||
*/
|
||||
|
@ -1,21 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Repository;
|
||||
|
||||
use App\Entity\DocGeneratorTemplate;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* @method DocGeneratorTemplate|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method DocGeneratorTemplate|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method DocGeneratorTemplate[] findAll()
|
||||
* @method DocGeneratorTemplate[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class DocGeneratorTemplateRepository extends ServiceEntityRepository
|
||||
final class DocGeneratorTemplateRepository implements ObjectRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
parent::__construct($registry, DocGeneratorTemplate::class);
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
---
|
||||
services:
|
||||
|
||||
Chill\DocGeneratorBundle\Repository\:
|
||||
autowire: true
|
||||
resource: '../../Repository/'
|
||||
tags:
|
||||
- { name: 'doctrine.repository_service' }
|
@ -1,3 +1,3 @@
|
||||
chill_docgen_controllers:
|
||||
resource: '../../Controller/'
|
||||
resource: '../Controller/'
|
||||
type: annotation
|
10
src/Bundle/ChillDocGeneratorBundle/config/services.yaml
Normal file
10
src/Bundle/ChillDocGeneratorBundle/config/services.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\DocGeneratorBundle\Repository\:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
resource: '../Repository/'
|
@ -1,5 +1,6 @@
|
||||
services:
|
||||
Chill\DocGeneratorBundle\Controller\:
|
||||
autowire: true
|
||||
resource: '../../../Controller'
|
||||
autoconfigure: true
|
||||
resource: '../../Controller'
|
||||
tags: ['controller.service_arguments']
|
Loading…
x
Reference in New Issue
Block a user