Loading config/merged/macro.config.php +7 −6 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ return [ 'options' => [ 'route' => '/macro', 'defaults' => [ /** @see MacroController::indexAction() */ 'controller' => MacroController::class, 'action' => 'index', ], Loading @@ -76,11 +77,11 @@ return [ 'may_terminate' => true, 'child_routes' => [ 'generer-json' => [ 'type' => Literal::class, 'type' => Segment::class, 'options' => [ 'route' => '/generer-json', 'route' => '/generer-json/:engine', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::genererJsonAction() */ 'action' => 'generer-json', ], ], Loading @@ -90,7 +91,7 @@ return [ 'options' => [ 'route' => '/ajouter', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::ajouterAction() */ 'action' => 'ajouter', ], ], Loading @@ -100,7 +101,7 @@ return [ 'options' => [ 'route' => '/modifier/:macro', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::modifierAction() */ 'action' => 'modifier', ], ], Loading @@ -110,7 +111,7 @@ return [ 'options' => [ 'route' => '/supprimer/:macro', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::supprimerAction() */ 'action' => 'supprimer', ], ], Loading src/UnicaenRenderer/Controller/MacroController.php +4 −4 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ use Laminas\View\Model\ViewModel; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Form\Macro\MacroFormAwareTrait; use UnicaenRenderer\Service\Macro\MacroServiceAwareTrait; use UnicaenRenderer\Service\Template\TemplateServiceAwareTrait; class MacroController extends AbstractActionController { use MacroServiceAwareTrait; use TemplateServiceAwareTrait; use MacroFormAwareTrait; public function indexAction(): ViewModel Loading Loading @@ -115,10 +117,8 @@ class MacroController extends AbstractActionController public function genererJsonAction(): ViewModel { // todo : le JSON dépend désormais du moteur de template throw new \BadMethodCallException("Non implémenté !"); $json = $this->getMacroService()->generateJSON(); $engine = $this->params()->fromRoute('engine'); $json = $this->getMacroService()->generateMacrosJsonForEngineCode($engine); return new ViewModel([ 'title' => 'JSON pour tinyMCE', Loading src/UnicaenRenderer/Controller/TemplateController.php +2 −20 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class TemplateController extends AbstractActionController 'title' => "Création d'un template", 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->generateMacrosJsonValueForTemplate($template), 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), ]); return $vm; Loading Loading @@ -106,7 +106,7 @@ class TemplateController extends AbstractActionController 'title' => "Modification d'un template", 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->generateMacrosJsonValueForTemplate($template), 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), ]); } Loading Loading @@ -136,22 +136,4 @@ class TemplateController extends AbstractActionController return $vm; } private function generateMacrosJsonValueForTemplate(Template $template): string { $templateEngine = $this->templateEngineManager->getEngineForTemplate($template); $macros = $this->macroService->getMacros(); $array = []; foreach ($macros as $macro) { //$description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $array[] = [ 'id' => $macro->getCode(), 'text' => $macro->getCode(), 'description' => $macro->getDescription() ?: 'Aucune description', 'value' => $templateEngine->generateMacroSourceCode($macro), ]; } return json_encode($array, JSON_HEX_APOS | JSON_HEX_QUOT); } } No newline at end of file src/UnicaenRenderer/Service/Macro/MacroService.php +26 −12 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ use DoctrineModule\Persistence\ProvidesObjectManager; use Laminas\Mvc\Controller\AbstractActionController; use RuntimeException; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Entity\Db\Template; use UnicaenRenderer\Service\TemplateEngine\TemplateEngineInterface; use UnicaenRenderer\Service\TemplateEngineManager\TemplateEngineManagerAwareTrait; /** * @property EntityManager $objectManager Loading @@ -16,6 +19,7 @@ use UnicaenRenderer\Entity\Db\Macro; class MacroService { use ProvidesObjectManager; use TemplateEngineManagerAwareTrait; /** GESTION DES ENTITES *******************************************************************************************/ Loading Loading @@ -110,23 +114,33 @@ class MacroService /** FACADE ********************************************************************************************************/ /** * @deprecated à supprimer, le JSON dépend désormais du moteur de template * @see \UnicaenRenderer\Controller\TemplateController::generateMacrosJsonValueForTemplate() */ public function generateJSON(): string public function generateMacrosJsonValueForTemplate(Template $template): string { $templateEngine = $this->templateEngineManager->getEngineForTemplate($template); return $this->generateMacrosJsonForEngine($templateEngine); } public function generateMacrosJsonForEngineCode(string $engineCode): string { $templateEngine = $this->templateEngineManager->get($engineCode); return $this->generateMacrosJsonForEngine($templateEngine); } public function generateMacrosJsonForEngine(TemplateEngineInterface $templateEngine): string { $macros = $this->getMacros(); $result = "macros = [\n"; $array = []; foreach ($macros as $macro) { $code = $macro->getCode(); $description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $result .= " { title:'" . $code . "', description:'" . $description . "', content:'VAR[" . $code . "]' },\n"; //$description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $array[] = [ 'id' => $macro->getCode(), 'text' => $macro->getCode(), 'description' => $macro->getDescription() ?: 'Aucune description', 'value' => $templateEngine->generateMacroSourceCode($macro), ]; } $result .= "];\n"; return $result; return json_encode($array, JSON_HEX_APOS | JSON_HEX_QUOT); } } No newline at end of file src/UnicaenRenderer/Service/Macro/MacroServiceFactory.php +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenRenderer\Service\TemplateEngineManager\TemplateEngineManager; class MacroServiceFactory { Loading @@ -18,11 +19,14 @@ class MacroServiceFactory { /** * @var EntityManager $entityManager * @var TemplateEngineManager $templateEngineManager */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $templateEngineManager = $container->get(TemplateEngineManager::class); $service = new MacroService(); $service->setObjectManager($entityManager); $service->setTemplateEngineManager($templateEngineManager); return $service; } Loading Loading
config/merged/macro.config.php +7 −6 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ return [ 'options' => [ 'route' => '/macro', 'defaults' => [ /** @see MacroController::indexAction() */ 'controller' => MacroController::class, 'action' => 'index', ], Loading @@ -76,11 +77,11 @@ return [ 'may_terminate' => true, 'child_routes' => [ 'generer-json' => [ 'type' => Literal::class, 'type' => Segment::class, 'options' => [ 'route' => '/generer-json', 'route' => '/generer-json/:engine', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::genererJsonAction() */ 'action' => 'generer-json', ], ], Loading @@ -90,7 +91,7 @@ return [ 'options' => [ 'route' => '/ajouter', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::ajouterAction() */ 'action' => 'ajouter', ], ], Loading @@ -100,7 +101,7 @@ return [ 'options' => [ 'route' => '/modifier/:macro', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::modifierAction() */ 'action' => 'modifier', ], ], Loading @@ -110,7 +111,7 @@ return [ 'options' => [ 'route' => '/supprimer/:macro', 'defaults' => [ 'controller' => MacroController::class, /** @see MacroController::supprimerAction() */ 'action' => 'supprimer', ], ], Loading
src/UnicaenRenderer/Controller/MacroController.php +4 −4 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ use Laminas\View\Model\ViewModel; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Form\Macro\MacroFormAwareTrait; use UnicaenRenderer\Service\Macro\MacroServiceAwareTrait; use UnicaenRenderer\Service\Template\TemplateServiceAwareTrait; class MacroController extends AbstractActionController { use MacroServiceAwareTrait; use TemplateServiceAwareTrait; use MacroFormAwareTrait; public function indexAction(): ViewModel Loading Loading @@ -115,10 +117,8 @@ class MacroController extends AbstractActionController public function genererJsonAction(): ViewModel { // todo : le JSON dépend désormais du moteur de template throw new \BadMethodCallException("Non implémenté !"); $json = $this->getMacroService()->generateJSON(); $engine = $this->params()->fromRoute('engine'); $json = $this->getMacroService()->generateMacrosJsonForEngineCode($engine); return new ViewModel([ 'title' => 'JSON pour tinyMCE', Loading
src/UnicaenRenderer/Controller/TemplateController.php +2 −20 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class TemplateController extends AbstractActionController 'title' => "Création d'un template", 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->generateMacrosJsonValueForTemplate($template), 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), ]); return $vm; Loading Loading @@ -106,7 +106,7 @@ class TemplateController extends AbstractActionController 'title' => "Modification d'un template", 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->generateMacrosJsonValueForTemplate($template), 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), ]); } Loading Loading @@ -136,22 +136,4 @@ class TemplateController extends AbstractActionController return $vm; } private function generateMacrosJsonValueForTemplate(Template $template): string { $templateEngine = $this->templateEngineManager->getEngineForTemplate($template); $macros = $this->macroService->getMacros(); $array = []; foreach ($macros as $macro) { //$description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $array[] = [ 'id' => $macro->getCode(), 'text' => $macro->getCode(), 'description' => $macro->getDescription() ?: 'Aucune description', 'value' => $templateEngine->generateMacroSourceCode($macro), ]; } return json_encode($array, JSON_HEX_APOS | JSON_HEX_QUOT); } } No newline at end of file
src/UnicaenRenderer/Service/Macro/MacroService.php +26 −12 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ use DoctrineModule\Persistence\ProvidesObjectManager; use Laminas\Mvc\Controller\AbstractActionController; use RuntimeException; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Entity\Db\Template; use UnicaenRenderer\Service\TemplateEngine\TemplateEngineInterface; use UnicaenRenderer\Service\TemplateEngineManager\TemplateEngineManagerAwareTrait; /** * @property EntityManager $objectManager Loading @@ -16,6 +19,7 @@ use UnicaenRenderer\Entity\Db\Macro; class MacroService { use ProvidesObjectManager; use TemplateEngineManagerAwareTrait; /** GESTION DES ENTITES *******************************************************************************************/ Loading Loading @@ -110,23 +114,33 @@ class MacroService /** FACADE ********************************************************************************************************/ /** * @deprecated à supprimer, le JSON dépend désormais du moteur de template * @see \UnicaenRenderer\Controller\TemplateController::generateMacrosJsonValueForTemplate() */ public function generateJSON(): string public function generateMacrosJsonValueForTemplate(Template $template): string { $templateEngine = $this->templateEngineManager->getEngineForTemplate($template); return $this->generateMacrosJsonForEngine($templateEngine); } public function generateMacrosJsonForEngineCode(string $engineCode): string { $templateEngine = $this->templateEngineManager->get($engineCode); return $this->generateMacrosJsonForEngine($templateEngine); } public function generateMacrosJsonForEngine(TemplateEngineInterface $templateEngine): string { $macros = $this->getMacros(); $result = "macros = [\n"; $array = []; foreach ($macros as $macro) { $code = $macro->getCode(); $description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $result .= " { title:'" . $code . "', description:'" . $description . "', content:'VAR[" . $code . "]' },\n"; //$description = $macro->getDescription()?strip_tags(str_replace("'", "\'", $macro->getDescription())):""; $array[] = [ 'id' => $macro->getCode(), 'text' => $macro->getCode(), 'description' => $macro->getDescription() ?: 'Aucune description', 'value' => $templateEngine->generateMacroSourceCode($macro), ]; } $result .= "];\n"; return $result; return json_encode($array, JSON_HEX_APOS | JSON_HEX_QUOT); } } No newline at end of file
src/UnicaenRenderer/Service/Macro/MacroServiceFactory.php +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenRenderer\Service\TemplateEngineManager\TemplateEngineManager; class MacroServiceFactory { Loading @@ -18,11 +19,14 @@ class MacroServiceFactory { /** * @var EntityManager $entityManager * @var TemplateEngineManager $templateEngineManager */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $templateEngineManager = $container->get(TemplateEngineManager::class); $service = new MacroService(); $service->setObjectManager($entityManager); $service->setTemplateEngineManager($templateEngineManager); return $service; } Loading