Browse Source

remove core from app

develop
Simon Vieille 2 months ago
parent
commit
079e52eb42
  1. 3
      composer.json
  2. 2
      config/bundles.php
  3. 2
      config/packages/app.yaml
  4. 11
      config/packages/doctrine.yaml
  5. 2
      config/packages/security.yaml
  6. 4
      config/routes/annotations.yaml
  7. 11
      config/services.yaml
  8. 96
      src/Authenticator/LoginFormAuthenticator.php
  9. 23
      src/Bundle/AppBundle.php
  10. 153
      src/Controller/Account/AccountAdminController.php
  11. 21
      src/Controller/Admin/AdminController.php
  12. 159
      src/Controller/Auth/AuthController.php
  13. 4
      src/Controller/Blog/CategoryAdminController.php
  14. 6
      src/Controller/Blog/PostAdminController.php
  15. 27
      src/Controller/Dashboard/DashboardAdminController.php
  16. 82
      src/Controller/Site/MenuAdminController.php
  17. 116
      src/Controller/Site/NavigationAdminController.php
  18. 263
      src/Controller/Site/NodeAdminController.php
  19. 109
      src/Controller/Site/PageAdminController.php
  20. 25
      src/Controller/Site/PageController.php
  21. 66
      src/Controller/Site/TreeAdminController.php
  22. 157
      src/Controller/User/UserAdminController.php
  23. 28
      src/DependencyInjection/AppExtension.php
  24. 44
      src/DependencyInjection/Configuration.php
  25. 4
      src/Entity/Blog/Category.php
  26. 4
      src/Entity/Blog/Post.php
  27. 7
      src/Entity/EntityInterface.php
  28. 6
      src/Entity/Page/SimplePage.php
  29. 146
      src/Entity/Site/Menu.php
  30. 127
      src/Entity/Site/Navigation.php
  31. 304
      src/Entity/Site/Node.php
  32. 80
      src/Entity/Site/Page/Block.php
  33. 248
      src/Entity/Site/Page/Page.php
  34. 77
      src/Entity/User.php
  35. 28
      src/Event/Account/PasswordRequestEvent.php
  36. 33
      src/Event/EntityManager/EntityManagerEvent.php
  37. 50
      src/EventSuscriber/Account/PasswordRequestEventSubscriber.php
  38. 6
      src/EventSuscriber/Blog/PostEventSubscriber.php
  39. 50
      src/EventSuscriber/EntityManagerEventSubscriber.php
  40. 92
      src/EventSuscriber/Site/MenuEventSubscriber.php
  41. 46
      src/EventSuscriber/Site/NavigationEventSubscriber.php
  42. 109
      src/EventSuscriber/Site/NodeEventSubscriber.php
  43. 70
      src/EventSuscriber/Site/SiteEventSubscriber.php
  44. 25
      src/Factory/Site/MenuFactory.php
  45. 18
      src/Factory/Site/NavigationFactory.php
  46. 30
      src/Factory/Site/NodeFactory.php
  47. 21
      src/Factory/Site/Page/PageFactory.php
  48. 23
      src/Factory/UserFactory.php
  49. 28
      src/Form/FileUploadHandler.php
  50. 51
      src/Form/Site/MenuType.php
  51. 65
      src/Form/Site/NavigationType.php
  52. 62
      src/Form/Site/NodeMoveType.php
  53. 158
      src/Form/Site/NodeType.php
  54. 116
      src/Form/Site/Page/PageType.php
  55. 32
      src/Form/Site/Page/TextBlockType.php
  56. 21
      src/Form/Site/Page/TextareaBlockType.php
  57. 78
      src/Form/UserType.php
  58. 98
      src/Manager/EntityManager.php
  59. 338
      src/Notification/MailNotifier.php
  60. 2
      src/Repository/Blog/CategoryRepositoryQuery.php
  61. 2
      src/Repository/Blog/PostRepositoryQuery.php
  62. 96
      src/Repository/RepositoryQuery.php
  63. 15
      src/Repository/Site/MenuRepository.php
  64. 19
      src/Repository/Site/MenuRepositoryQuery.php
  65. 15
      src/Repository/Site/NavigationRepository.php
  66. 19
      src/Repository/Site/NavigationRepositoryQuery.php
  67. 38
      src/Repository/Site/NodeRepository.php
  68. 15
      src/Repository/Site/Page/BlockRepository.php
  69. 19
      src/Repository/Site/Page/BlockRepositoryQuery.php
  70. 15
      src/Repository/Site/Page/PageRepository.php
  71. 29
      src/Repository/Site/Page/PageRepositoryQuery.php
  72. 1
      src/Repository/UserRepositoryQuery.php
  73. 69
      src/Router/SiteRouteLoader.php
  74. 13
      src/Security/TokenGenerator.php
  75. 51
      src/Site/PageConfiguration.php
  76. 48
      src/Site/PageLocator.php
  77. 69
      src/Site/SiteRequest.php
  78. 26
      src/Slugify/CodeSlugify.php
  79. 31
      src/Slugify/Slugify.php
  80. 32
      templates/user/user_admin/show.html.twig

3
composer.json

@ -72,7 +72,8 @@
},
"autoload": {
"psr-4": {
"App\\": "src/"
"App\\": "src/",
"App\\Core\\": "core/"
}
},
"autoload-dev": {

2
config/bundles.php

@ -17,5 +17,5 @@ return [
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
App\Bundle\AppBundle::class => ['all' => true],
App\Core\Bundle\AppBundle::class => ['all' => true],
];

2
config/packages/app.yaml

@ -1,7 +1,7 @@
app:
site:
pages:
App\Site\Page\SimplePage:
App\Entity\Page\SimplePage:
name: 'Page simple'
templates:
- {name: "Template 1", file: "site/page/simple/page.html.twig"}

11
config/packages/doctrine.yaml

@ -10,17 +10,18 @@ doctrine:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App\Core\Entity:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/core/Entity'
prefix: 'App\Core\Entity'
alias: App\Core\Entity
App\Entity:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App\Entity
App\Site\Page:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Site/Page'
prefix: 'App\Site\Page'
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity

2
config/packages/security.yaml

@ -26,7 +26,7 @@ security:
check_path: 2fa_login_check # The route name you have used in the routes.yaml
guard:
authenticators:
- App\Authenticator\LoginFormAuthenticator
- App\Core\Authenticator\LoginFormAuthenticator
form_login:
login_path: auth_login
check_path: auth_login

4
config/routes/annotations.yaml

@ -2,6 +2,10 @@ controllers:
resource: ../../src/Controller/
type: annotation
core_controllers:
resource: ../../core/Controller/
type: annotation
kernel:
resource: ../../src/Kernel.php
type: annotation

11
config/services.yaml

@ -13,6 +13,11 @@ services:
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\Core\:
resource: '../core/'
exclude:
- '../core/DependencyInjection/'
- '../core/Entity/'
App\:
resource: '../src/'
exclude:
@ -23,12 +28,16 @@ services:
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Core\Controller\:
resource: '../core/Controller/'
tags: ['controller.service_arguments']
App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
site.route_loader:
class: App\Router\SiteRouteLoader
class: App\Core\Router\SiteRouteLoader
tags: [routing.loader]
gedmo.listener.tree:

96
src/Authenticator/LoginFormAuthenticator.php

@ -1,96 +0,0 @@
<?php
namespace App\Authenticator;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
use Symfony\Component\Security\Http\Util\TargetPathTrait;
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
{
use TargetPathTrait;
private EntityManagerInterface $entityManager;
private UrlGeneratorInterface $urlGenerator;
private CsrfTokenManagerInterface $csrfTokenManager;
private UserPasswordEncoderInterface $passwordEncoder;
public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $passwordEncoder)
{
$this->entityManager = $entityManager;
$this->urlGenerator = $urlGenerator;
$this->csrfTokenManager = $csrfTokenManager;
$this->passwordEncoder = $passwordEncoder;
}
public function supports(Request $request)
{
return 'auth_login' === $request->attributes->get('_route') && $request->isMethod('POST');
}
public function getCredentials(Request $request)
{
$credentials = [
'email' => $request->request->get('_username'),
'password' => $request->request->get('_password'),
'csrf_token' => $request->request->get('_csrf_token'),
];
$request->getSession()->set(Security::LAST_USERNAME, $credentials['email']);
return $credentials;
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
$token = new CsrfToken('authenticate', $credentials['csrf_token']);
if (!$this->csrfTokenManager->isTokenValid($token)) {
throw new InvalidCsrfTokenException();
}
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $credentials['email']]);
if (!$user) {
// fail authentication with a custom error
throw new CustomUserMessageAuthenticationException('Email could not be found.');
}
return $user;
}
public function checkCredentials($credentials, UserInterface $user)
{
return $this->passwordEncoder->isPasswordValid($user, $credentials['password']);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {
return new RedirectResponse($targetPath);
}
return new RedirectResponse($this->urlGenerator->generate('admin_dashboard_index'));
}
protected function getLoginUrl()
{
return $this->urlGenerator->generate('auth_login');
}
}

23
src/Bundle/AppBundle.php

@ -1,23 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Bundle;
use App\DependencyInjection\AppExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle
{
public function getContainerExtension()
{
return new AppExtension();
}
}

153
src/Controller/Account/AccountAdminController.php

@ -1,153 +0,0 @@
<?php
namespace App\Controller\Account;
use App\Controller\Admin\AdminController;
use App\Manager\EntityManager;
use App\Repository\UserRepository;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface as TotpAuthenticatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
use ZxcvbnPhp\Zxcvbn;
/**
* @Route("/admin/account")
*/
class AccountAdminController extends AdminController
{
/**
* @Route("/", name="admin_account")
*/
public function account(Request $request, TotpAuthenticatorInterface $totpAuthenticatorService): Response
{
$account = $this->getUser();
return $this->render('account/admin/edit.html.twig', [
'account' => $account,
]);
}
/**
* @Route("/2fa", name="admin_account_2fa")
*/
public function twoFactorAuthentication(
Request $request,
GoogleAuthenticatorInterface $totpAuthenticatorService,
EntityManager $entityManager
): Response {
if ($request->isMethod('GET')) {
return $this->redirectToRoute('admin_account');
}
$account = $this->getUser();
$csrfToken = $request->request->get('_csrf_token');
$enable = (bool) $request->request->get('enable');
$code = $request->request->get('code', '');
$secret = $request->request->get('secret', '');
$qrCodeContent = null;
if ($this->isCsrfTokenValid('2fa', $csrfToken)) {
if ($enable && !$account->isTotpAuthenticationEnabled()) {
if (empty($secret)) {
$secret = $totpAuthenticatorService->generateSecret();
$account->setTotpSecret($secret);
$qrCodeContent = $totpAuthenticatorService->getQRContent($account);
} else {
$account->setTotpSecret($secret);
$qrCodeContent = $totpAuthenticatorService->getQRContent($account);
if (!$totpAuthenticatorService->checkCode($account, $code)) {
$this->addFlash('error', 'Le code n\'est pas valide.');
} else {
$this->addFlash('success', 'Double authentification activée.');
$entityManager->update($account);
return $this->redirectToRoute('admin_account');
}
}
}
if (!$enable && $account->isTotpAuthenticationEnabled()) {
$account->setTotpSecret(null);
$entityManager->update($account);
$this->addFlash('success', 'Double authentification désactivée.');
return $this->redirectToRoute('admin_account');
}
}
return $this->render('account/admin/edit.html.twig', [
'account' => $account,
'twoFaKey' => $secret,
'twoFaQrCodeContent' => $qrCodeContent,
]);
}
/**
* @Route("/password", name="admin_account_password", methods={"POST"})
*/
public function password(
Request $request,
UserRepository $repository,
TokenGeneratorInterface $tokenGenerator,
UserPasswordEncoderInterface $encoder,
EntityManager $entityManager
): Response {
$account = $this->getUser();
$csrfToken = $request->request->get('_csrf_token');
if ($this->isCsrfTokenValid('password', $csrfToken)) {
$password = $request->request->get('password');
if (!$encoder->isPasswordValid($account, $password)) {
$this->addFlash('error', 'Le formulaire n\'est pas valide.');
return $this->redirectToRoute('admin_account');
}
$password1 = $request->request->get('password1');
$password2 = $request->request->get('password2');
$zxcvbn = new Zxcvbn();
$strength = $zxcvbn->passwordStrength($password1, []);
if (4 === $strength['score'] && $password1 === $password2) {
$account
->setPassword($encoder->encodePassword(
$account,
$password1
))
->setConfirmationToken($tokenGenerator->generateToken())
;
$entityManager->update($account);
$this->addFlash('success', 'Mot de passe modifié !');
return $this->redirectToRoute('admin_account');
}
}
$this->addFlash('error', 'Le formulaire n\'est pas valide.');
return $this->redirectToRoute('admin_account');
}
/**
* {@inheritdoc}
*/
protected function getSection(): string
{
return 'account';
}
}

21
src/Controller/Admin/AdminController.php

@ -1,21 +0,0 @@
<?php
namespace App\Controller\Admin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
abstract class AdminController extends AbstractController
{
/**
* {@inheritdoc}
*/
protected function render(string $view, array $parameters = [], Response $response = null): Response
{
$parameters['section'] = $this->getSection();
return parent::render($view, $parameters, $response);
}
abstract protected function getSection(): string;
}

159
src/Controller/Auth/AuthController.php

@ -1,159 +0,0 @@
<?php
namespace App\Controller\Auth;
use App\Event\Account\PasswordRequestEvent;
use App\Manager\EntityManager;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use ZxcvbnPhp\Zxcvbn;
class AuthController extends AbstractController
{
/**
* @Route("/login", name="auth_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('admin_dashboard_index');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('auth/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/resetting/request", name="auth_resetting_request")
*/
public function requestResetting(
Request $request,
UserRepository $repository,
TokenGeneratorInterface $tokenGenerator,
EntityManager $entityManager,
EventDispatcherInterface $eventDispatcher
): Response {
if ($this->getUser()) {
return $this->redirectToRoute('admin_dashboard_index');
}
$emailSent = false;
if ($request->isMethod('POST')) {
$csrfToken = $request->request->get('_csrf_token');
if ($this->isCsrfTokenValid('resetting_request', $csrfToken)) {
$username = trim((string) $request->request->get('username'));
if ($username) {
$account = $repository->findOneByEmail($username);
if ($account) {
$passwordRequestedAt = $account->getPasswordRequestedAt();
if (null !== $passwordRequestedAt && $passwordRequestedAt->getTimestamp() > (time() - 3600 / 2)) {
$emailSent = true;
}
if (!$emailSent) {
$account->setConfirmationToken($tokenGenerator->generateToken());
$account->setPasswordRequestedAt(new \DateTime('now'));
$entityManager->update($account);
$eventDispatcher->dispatch(new PasswordRequestEvent($account), PasswordRequestEvent::EVENT);
$emailSent = true;
}
}
}
}
}
return $this->render('auth/resetting_request.html.twig', [
'email_sent' => $emailSent,
]);
}
/**
* @Route("/resetting/update/{token}", name="auth_resetting_update")
*/
public function requestUpdate(
string $token,
Request $request,
UserRepository $repository,
TokenGeneratorInterface $tokenGenerator,
UserPasswordEncoderInterface $encoder,
EntityManager $entityManager
): Response {
if ($this->getUser()) {
return $this->redirectToRoute('admin_dashboard_index');
}
$account = $repository->findOneByConfirmationToken($token);
$passwordUpdated = false;
$expired = false;
if ($account) {
$passwordRequestedAt = $account->getPasswordRequestedAt();
if (null !== $passwordRequestedAt && $passwordRequestedAt->getTimestamp() < (time() - 3600 * 2)) {
$expired = true;
}
} else {
$expired = true;
}
if ($request->isMethod('POST') && !$expired) {
$csrfToken = $request->request->get('_csrf_token');
if ($this->isCsrfTokenValid('resetting_update', $csrfToken)) {
$password = $request->request->get('password');
$password2 = $request->request->get('password2');
$zxcvbn = new Zxcvbn();
$strength = $zxcvbn->passwordStrength($password, []);
if (4 === $strength['score'] && $password === $password2) {
$account
->setPassword($encoder->encodePassword(
$account,
$password
))
->setConfirmationToken($tokenGenerator->generateToken())
->setPasswordRequestedAt(new \DateTime('now'))
;
$entityManager->update($account);
$passwordUpdated = true;
}
}
}
return $this->render('auth/resetting_update.html.twig', [
'password_updated' => $passwordUpdated,
'token' => $token,
'expired' => $expired,
]);
}
/**
* @Route("/logout", name="auth_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
}

4
src/Controller/Blog/CategoryAdminController.php

@ -2,11 +2,11 @@
namespace App\Controller\Blog;
use App\Controller\Admin\AdminController;
use App\Core\Controller\Admin\AdminController;
use App\Entity\Blog\Category as Entity;
use App\Factory\Blog\CategoryFactory as EntityFactory;
use App\Form\Blog\CategoryType as EntityType;
use App\Manager\EntityManager;
use App\Core\Manager\EntityManager;
use App\Repository\Blog\CategoryRepositoryQuery as RepositoryQuery;
use App\Repository\Blog\PostRepositoryQuery;
use Symfony\Component\HttpFoundation\Request;

6
src/Controller/Blog/PostAdminController.php

@ -2,12 +2,12 @@
namespace App\Controller\Blog;
use App\Controller\Admin\AdminController;
use App\Core\Controller\Admin\AdminController;
use App\Entity\Blog\Post as Entity;
use App\Factory\Blog\PostFactory as EntityFactory;
use App\Form\Blog\PostType as EntityType;
use App\Form\FileUploadHandler;
use App\Manager\EntityManager;
use App\Core\Form\FileUploadHandler;
use App\Core\Manager\EntityManager;
use App\Repository\Blog\PostRepositoryQuery as RepositoryQuery;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

27
src/Controller/Dashboard/DashboardAdminController.php

@ -1,27 +0,0 @@
<?php
namespace App\Controller\Dashboard;
use App\Controller\Admin\AdminController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin")
*/
class DashboardAdminController extends AdminController
{
/**
* @Route("/", name="admin_dashboard_index")
*/
public function index(): Response
{
return $this->render('dashboard/admin/index.html.twig', [
]);
}
protected function getSection(): string
{
return 'dashboard';
}
}

82
src/Controller/Site/MenuAdminController.php

@ -1,82 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Controller\Admin\AdminController;
use App\Entity\Site\Menu as Entity;
use App\Entity\Site\Navigation;
use App\Factory\Site\MenuFactory as EntityFactory;
use App\Form\Site\MenuType as EntityType;
use App\Manager\EntityManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/site/menu")
*/
class MenuAdminController extends AdminController
{
/**
* @Route("/new/{navigation}", name="admin_site_menu_new", methods={"POST"})
*/
public function new(Navigation $navigation, EntityFactory $factory, EntityManager $entityManager, Request $request): Response
{
$entity = $factory->create($navigation);
$form = $this->createForm(EntityType::class, $entity);
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->create($entity);
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $navigation->getId(),
]);
}
/**
* @Route("/edit/{entity}", name="admin_site_menu_edit", methods={"POST"})
*/
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
{
$form = $this->createForm(EntityType::class, $entity);
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getNavigation()->getId(),
]);
}
/**
* @Route("/delete/{entity}", name="admin_site_menu_delete", methods={"DELETE"})
*/
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager->delete($entity);
$this->addFlash('success', 'Données supprimée..');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getNavigation()->getId(),
]);
}
public function getSection(): string
{
return '';
}
}

116
src/Controller/Site/NavigationAdminController.php

@ -1,116 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Controller\Admin\AdminController;
use App\Entity\Site\Navigation as Entity;
use App\Factory\Site\NavigationFactory as EntityFactory;
use App\Form\Site\NavigationType as EntityType;
use App\Manager\EntityManager;
use App\Repository\Site\NavigationRepositoryQuery as RepositoryQuery;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/site/navigation")
*/
class NavigationAdminController extends AdminController
{
/**
* @Route("/{page}", name="admin_site_navigation_index", requirements={"page": "\d+"})
*/
public function index(int $page = 1, RepositoryQuery $query, Request $request): Response
{
$pager = $query->paginate($page);
return $this->render('site/navigation_admin/index.html.twig', [
'pager' => $pager,
]);
}
/**
* @Route("/new", name="admin_site_navigation_new")
*/
public function new(EntityFactory $factory, EntityManager $entityManager, Request $request): Response
{
$entity = $factory->create();
$form = $this->createForm(EntityType::class, $entity);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->create($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_site_navigation_edit', [
'entity' => $entity->getId(),
]);
}
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->render('site/navigation_admin/new.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/edit/{entity}", name="admin_site_navigation_edit")
*/
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
{
$form = $this->createForm(EntityType::class, $entity);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_site_navigation_edit', [
'entity' => $entity->getId(),
]);
}
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->render('site/navigation_admin/edit.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/show/{entity}", name="admin_site_navigation_show")
*/
public function show(Entity $entity): Response
{
return $this->render('site/navigation_admin/show.html.twig', [
'entity' => $entity,
]);
}
/**
* @Route("/delete/{entity}", name="admin_site_navigation_delete", methods={"DELETE"})
*/
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager->delete($entity);
$this->addFlash('success', 'Données supprimée..');
}
return $this->redirectToRoute('admin_site_navigation_index');
}
public function getSection(): string
{
return 'site_navigation';
}
}

263
src/Controller/Site/NodeAdminController.php

@ -1,263 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Controller\Admin\AdminController;
use App\Entity\Site\Node;
use App\Entity\Site\Node as Entity;
use App\Entity\Site\Page\Page;
use App\Event\EntityManager\EntityManagerEvent;
use App\Factory\Site\NodeFactory as EntityFactory;
use App\Factory\Site\Page\PageFactory;
use App\Form\Site\NodeMoveType;
use App\Form\Site\NodeType as EntityType;
use App\Manager\EntityManager;
use App\Repository\Site\NodeRepository;
use App\Site\PageLocator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/site/node")
*/
class NodeAdminController extends AdminController
{
/**
* @Route("/new/{node}", name="admin_site_node_new")
*/
public function new(
Node $node,
EntityFactory $factory,
PageFactory $pageFactory,
EntityManager $entityManager,
NodeRepository $nodeRepository,
PageLocator $pageLocator,
Request $request
): Response {
$entity = $factory->create($node->getMenu());
$form = $this->createForm(EntityType::class, $entity, [
'pages' => $pageLocator->getPages(),
]);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$position = $form->get('position')->getData();
$parent = 'above' === $position ? $node : $node->getParent();
$entity->setParent($parent);
if ('above' === $position) {
$nodeRepository->persistAsLastChild($entity, $node);
} else {
if ('after' === $position) {
$nodeRepository->persistAsNextSiblingOf($entity, $node);
} elseif ('before' === $position) {
$nodeRepository->persistAsPrevSiblingOf($entity, $node);
}
}
$this->handlePageAssociation(
$form->get('pageAction')->getData(),
$form->get('pageEntity')->getData(),
$form->get('pageType')->getData(),
$entity,
$pageFactory,
$pageLocator
);
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $node->getMenu()->getNavigation()->getId(),
]);
}
return $this->render('site/node_admin/new.html.twig', [
'form' => $form->createView(),
'node' => $node,
'entity' => $entity,
]);
}
/**
* @Route("/edit/{entity}", name="admin_site_node_edit")
*/
public function edit(
Entity $entity,
EntityManager $entityManager,
PageFactory $pageFactory,
PageLocator $pageLocator,
Request $request
): Response {
$form = $this->createForm(EntityType::class, $entity, [
'pages' => $pageLocator->getPages(),
]);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->handlePageAssociation(
$form->get('pageAction')->getData(),
$form->get('pageEntity')->getData(),
$form->get('pageType')->getData(),
$entity,
$pageFactory,
$pageLocator
);
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getMenu()->getNavigation()->getId(),
]);
}
return $this->render('site/node_admin/edit.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/move/{entity}", name="admin_site_node_move")
*/
public function move(
Entity $entity,
EntityManager $entityManager,
NodeRepository $nodeRepository,
Request $request
): Response {
$form = $this->createForm(NodeMoveType::class, null, [
'menu' => $entity->getMenu(),
]);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->get('node')->getData()->getId() === $entity->getId()) {
$form->get('node')->addError(new FormError('Élement de référence invalide.'));
}
if ($form->isValid()) {
$position = $form->get('position')->getData();
$node = $form->get('node')->getData();
$parent = 'above' === $position ? $node : $node->getParent();
$entity->setParent($parent);
if ('above' === $position) {
$nodeRepository->persistAsLastChild($entity, $node);
$entityManager->flush();
} else {
if ('after' === $position) {
$nodeRepository->persistAsNextSiblingOf($entity, $node);
} elseif ('before' === $position) {
$nodeRepository->persistAsPrevSiblingOf($entity, $node);
}
$entityManager->flush();
}
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getMenu()->getNavigation()->getId(),
]);
}
return $this->render('site/node_admin/move.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/toggle/visibility/{entity}", name="admin_site_node_toggle_visibility", methods={"POST"})
*/
public function toggleVisibility(Entity $entity, EntityManager $entityManager, Request $request): Response
{
if ($this->isCsrfTokenValid('toggle_visibility'.$entity->getId(), $request->request->get('_token'))) {
$entity->setIsVisible(!$entity->getIsVisible());
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getMenu()->getNavigation()->getId(),
]);
}
/**
* @Route("/delete/{entity}", name="admin_site_node_delete", methods={"DELETE"})
*/
public function delete(
Entity $entity,
NodeRepository $nodeRepository,
EventDispatcherInterface $eventDispatcher,
Request $request
): Response {
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::PRE_DELETE_EVENT);
$nodeRepository->removeFromTree($entity);
$nodeRepository->reorder($entity->getMenu()->getRootNode());
$eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::DELETE_EVENT);
$this->addFlash('success', 'Donnée supprimée.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getMenu()->getNavigation()->getId(),
]);
}
public function getSection(): string
{
return '';
}
protected function handlePageAssociation(
string $pageAction,
?Page $pageEntity,
string $pageType,
Entity $entity,
PageFactory $pageFactory,
PageLocator $pageLocator
) {
if ('new' === $pageAction) {
$pageConfiguration = $pageLocator->getPage($pageType);
$page = $pageFactory->create($pageType, $entity->getLabel());
$page->setTemplate($pageConfiguration->getTemplates()[0]['file']);
$entity->setPage($page);
} elseif ('existing' === $pageAction) {
if ($pageEntity) {
$entity->setPage($pageEntity);
} else {
$this->addFlash('info', 'Aucun changement de page effectué.');
}
} elseif ('none' === $pageAction) {
$entity->setPage(null);
}
}
}

109
src/Controller/Site/PageAdminController.php

@ -1,109 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Controller\Admin\AdminController;
use App\Entity\Site\Page\Page as Entity;
use App\Factory\Site\Page\PageFactory as EntityFactory;
use App\Form\Site\Page\PageType as EntityType;
use App\Manager\EntityManager;
use App\Page\FooPage;
use App\Page\SimplePage;
use App\Repository\Site\Page\PageRepositoryQuery as RepositoryQuery;
use App\Site\PageLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/site/page")
*/
class PageAdminController extends AdminController
{
/**
* @Route("/{page}", name="admin_site_page_index", requirements={"page": "\d+"})
*/
public function index(int $page = 1, RepositoryQuery $query, Request $request): Response
{
$pager = $query->paginate($page);
return $this->render('site/page_admin/index.html.twig', [
'pager' => $pager,
]);
}
/**
* @Route("/new", name="admin_site_page_new")
*/
public function new(EntityFactory $factory, EntityManager $entityManager): Response
{
// $entity = $factory->create(FooPage::class);
$entity = $factory->create(SimplePage::class);
$entity->setName('Page de test '.mt_rand());
$entityManager->create($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_site_page_edit', [
'entity' => $entity->getId(),
]);
}
/**
* @Route("/edit/{entity}", name="admin_site_page_edit")
*/
public function edit(
int $entity,
EntityFactory $factory,
EntityManager $entityManager,
RepositoryQuery $repositoryQuery,
PageLocator $pageLocator,
Request $request
): Response {
$entity = $repositoryQuery->filterById($entity)->findOne();
$form = $this->createForm(EntityType::class, $entity, [
'pageConfiguration' => $pageLocator->getPage(get_class($entity)),
]);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_site_page_edit', [
'entity' => $entity->getId(),
]);
}
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->render('site/page_admin/edit.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/delete/{entity}", name="admin_site_page_delete", methods={"DELETE"})
*/
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager->delete($entity);
$this->addFlash('success', 'Données supprimée..');
}
return $this->redirectToRoute('admin_site_page_index');
}
public function getSection(): string
{
return 'site_page';
}
}

25
src/Controller/Site/PageController.php

@ -1,25 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Site\SiteRequest;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class PageController extends AbstractController
{
public function show(Request $request, SiteRequest $siteRequest): Response
{
if (!$siteRequest->getPage()) {
throw $this->createNotFoundException();
}
return $this->render($siteRequest->getPage()->getTemplate(), [
'_node' => $siteRequest->getNode(),
'_page' => $siteRequest->getPage(),
'_menu' => $siteRequest->getMenu(),
'_navigation' => $siteRequest->getNavigation(),
]);
}
}

66
src/Controller/Site/TreeAdminController.php

@ -1,66 +0,0 @@
<?php
namespace App\Controller\Site;
use App\Controller\Admin\AdminController;
use App\Entity\Site\Navigation;
use App\Factory\Site\MenuFactory;
use App\Form\Site\MenuType;
use App\Repository\Site\NavigationRepositoryQuery;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/site/tree")
*/
class TreeAdminController extends AdminController
{
/**
* @Route("/", name="admin_site_tree_index")
*/
public function index(NavigationRepositoryQuery $navigationQuery): Response
{
$navigation = $navigationQuery->create()->findOne();
if (null === $navigation) {
$this->addFlash('warning', 'Vous devez ajouter une navigation.');
return $this->redirectToRoute('admin_site_navigation_new');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $navigation->getId(),
]);
}
/**
* @Route("/navigation/{navigation}", name="admin_site_tree_navigation")
*/
public function navigation(
Navigation $navigation,
NavigationRepositoryQuery $navigationQuery,
MenuFactory $menuFactory
): Response {
$navigations = $navigationQuery->create()->find();
$forms = [
'menu' => $this->createForm(MenuType::class, $menuFactory->create())->createView(),
'menus' => [],
];
foreach ($navigation->getMenus() as $menu) {
$forms['menus'][$menu->getId()] = $this->createForm(MenuType::class, $menu)->createView();
}
return $this->render('site/tree_admin/navigation.html.twig', [
'navigation' => $navigation,
'navigations' => $navigations,
'forms' => $forms,
]);
}
public function getSection(): string
{
return 'site_tree';
}
}

157
src/Controller/User/UserAdminController.php

@ -1,157 +0,0 @@
<?php
namespace App\Controller\User;
use App\Controller\Admin\AdminController;
use App\Entity\User as Entity;
use App\Event\Account\PasswordRequestEvent;
use App\Factory\UserFactory as EntityFactory;
use App\Form\UserType as EntityType;
use App\Manager\EntityManager;
use App\Repository\Blog\PostRepositoryQuery;
use App\Repository\UserRepositoryQuery as RepositoryQuery;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
/**
* @Route("/admin/user")
*/
class UserAdminController extends AdminController
{
/**
* @Route("/{page}", name="admin_user_index", requirements={"page": "\d+"})
*/
public function index(int $page = 1, RepositoryQuery $query, Request $request): Response
{
$pager = $query->paginate($page);
return $this->render('user/user_admin/index.html.twig', [
'pager' => $pager,
]);
}
/**
* @Route("/new", name="admin_user_new")
*/
public function new(
EntityFactory $factory,
EntityManager $entityManager,
UserPasswordEncoderInterface $encoder,
Request $request
): Response {
$entity = $factory->create($this->getUser());
$form = $this->createForm(EntityType::class, $entity);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->create($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_user_edit', [
'entity' => $entity->getId(),
]);
}
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->render('user/user_admin/new.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/edit/{entity}", name="admin_user_edit")
*/
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
{
$form = $this->createForm(EntityType::class, $entity);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
return $this->redirectToRoute('admin_user_edit', [
'entity' => $entity->getId(),
]);
}
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->render('user/user_admin/edit.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/show/{entity}", name="admin_user_show")
*/
public function show(Entity $entity, PostRepositoryQuery $postQuery): Response
{
$posts = $postQuery->create()
->orderBy('.publishedAt', 'DESC')
->orderBy('.createdAt', 'DESC')
->filterByAuthor($entity)
->paginate(1, 10)
;
return $this->render('user/user_admin/show.html.twig', [
'entity' => $entity,
'posts' => $posts,
]);
}
/**
* @Route("/resetting_request/{entity}", name="admin_user_resetting_request", methods={"POST"})
*/
public function requestResetting(
Entity $entity,
EntityManager $entityManager,
TokenGeneratorInterface $tokenGenerator,
EventDispatcherInterface $eventDispatcher,
Request $request
): Response {
if ($this->isCsrfTokenValid('resetting_request'.$entity->getId(), $request->request->get('_token'))) {
$entity->setConfirmationToken($tokenGenerator->generateToken());
$entity->setPasswordRequestedAt(new \DateTime('now'));
$entityManager->update($entity);
$eventDispatcher->dispatch(new PasswordRequestEvent($entity), PasswordRequestEvent::EVENT);
$this->addFlash('success', 'Demande envoyée.');
}
return $this->redirectToRoute('admin_user_edit', [
'entity' => $entity->getId(),
]);
}
/**
* @Route("/delete/{entity}", name="admin_user_delete", methods={"DELETE"})
*/
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager->delete($entity);
$this->addFlash('success', 'Données supprimée..');
}
return $this->redirectToRoute('admin_user_index');
}
public function getSection(): string
{
return 'user';
}
}

28
src/DependencyInjection/AppExtension.php

@ -1,28 +0,0 @@
<?php
namespace App\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
class AppExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('app', $config);
}
/**
* {@inheritdoc}
*/
public function getConfiguration(array $configs, ContainerBuilder $container)
{
return new Configuration();
}
}

44
src/DependencyInjection/Configuration.php

@ -1,44 +0,0 @@
<?php
namespace App\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('app');
$treeBuilder->getRootNode()
->children()
->arrayNode('site')
->children()
->arrayNode('pages')
->prototype('array')
->children()
->scalarNode('name')
->isRequired()
->cannotBeEmpty()
->end()
->arrayNode('templates')
->prototype('array')
->children()
->scalarNode('name')
->cannotBeEmpty()
->end()
->scalarNode('file')