Retrieve container and translator arguments in constructor
Use central getAlias() function
Switch to new array based config
namespace Rapsys\UserBundle\Controller;
namespace Rapsys\UserBundle\Controller;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Form\FormError;
use Rapsys\UserBundle\Utils\Slugger;
use Symfony\Component\Form\FormError;
use Rapsys\UserBundle\Utils\Slugger;
-class DefaultController extends Controller {
+class DefaultController extends AbstractController {
+ //Config array
+ protected $config;
+
+ //Translator instance
+ protected $translator;
+
+ public function __construct(ContainerInterface $container, Translator $translator) {
+ //Retrieve config
+ $this->config = $container->getParameter($this->getAlias());
+
+ //Set the translator
+ $this->translator = $translator;
+ }
+
//FIXME: we need to change the $this->container->getParameter($alias.'.xyz') to $this->container->getParameter($alias)['xyz']
public function loginAction(Request $request, AuthenticationUtils $authenticationUtils) {
//Get template
//FIXME: we need to change the $this->container->getParameter($alias.'.xyz') to $this->container->getParameter($alias)['xyz']
public function loginAction(Request $request, AuthenticationUtils $authenticationUtils) {
//Get template
- $template = $this->container->getParameter(($alias = $this->getAlias()).'.login.template');
+ $template = $this->config['login']['template'];
- $context = $this->container->getParameter($alias.'.login.context');
+ $context = $this->config['login']['context'];
//Create the form according to the FormType created previously.
//And give the proper parameters
//Create the form according to the FormType created previously.
//And give the proper parameters
//Get the login error if there is one
if ($error = $authenticationUtils->getLastAuthenticationError()) {
//Get the login error if there is one
if ($error = $authenticationUtils->getLastAuthenticationError()) {
- //Get translator
- $trans = $this->get('translator');
-
- $error = $trans->trans($error->getMessageKey());
+ $error = $this->translator->trans($error->getMessageKey());
//Add error message to mail field
$form->get('mail')->addError(new FormError($error));
//Add error message to mail field
$form->get('mail')->addError(new FormError($error));
public function registerAction(Request $request, UserPasswordEncoderInterface $encoder) {
//Get mail template
public function registerAction(Request $request, UserPasswordEncoderInterface $encoder) {
//Get mail template
- $mailTemplate = $this->container->getParameter(($alias = $this->getAlias()).'.register.mail_template');
+ $mailTemplate = $this->config['register']['mail_template'];
- $mailContext = $this->container->getParameter($alias.'.register.mail_context');
+ $mailContext = $this->config['register']['mail_context'];
- $template = $this->container->getParameter($alias.'.register.template');
+ $template = $this->config['register']['template'];
- $context = $this->container->getParameter($alias.'.register.context');
+ $context = $this->config['register']['context'];
- $homeName = $this->container->getParameter($alias.'.contact.home_name');
+ $homeName = $this->config['contact']['home_name'];
- $homeArgs = $this->container->getParameter($alias.'.contact.home_args');
+ $homeArgs = $this->config['contact']['home_args'];
- $contactName = $this->container->getParameter($alias.'.contact.name');
+ $contactName = $this->config['contact']['name'];
- $contactMail = $this->container->getParameter($alias.'.contact.mail');
+ $contactMail = $this->config['contact']['mail'];
//TODO: check if doctrine orm replacement is enough with default classes here
//Get class user
//TODO: check if doctrine orm replacement is enough with default classes here
//Get class user
- $classUser = $this->container->getParameter($alias.'.class.user');
+ $classUser = $this->config['class']['user'];
- $classGroup = $this->container->getParameter($alias.'.class.group');
+ $classGroup = $this->config['class']['group'];
- $classTitle = $this->container->getParameter($alias.'.class.title');
+ $classTitle = $this->config['class']['title'];
//Create the form according to the FormType created previously.
//And give the proper parameters
//Create the form according to the FormType created previously.
//And give the proper parameters
$form->handleRequest($request);
if ($form->isValid()) {
$form->handleRequest($request);
if ($form->isValid()) {
- //Get translator
- $trans = $this->get('translator');
-
//Set data
$data = $form->getData();
//Translate title
//Set data
$data = $form->getData();
//Translate title
- $mailContext['title'] = $trans->trans($mailContext['title']);
+ $mailContext['title'] = $this->translator->trans($mailContext['title']);
- $mailContext['subtitle'] = $trans->trans($mailContext['subtitle'], array('%name%' => $data['forename'].' '.$data['surname'].' ('.$data['pseudonym'].')'));
+ $mailContext['subtitle'] = $this->translator->trans($mailContext['subtitle'], array('%name%' => $data['forename'].' '.$data['surname'].' ('.$data['pseudonym'].')'));
- $mailContext['subject'] = $trans->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
+ $mailContext['subject'] = $this->translator->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
- $mailContext['message'] = $trans->trans($mailContext['message'], array('%title%' => $mailContext['title']));
+ $mailContext['message'] = $this->translator->trans($mailContext['message'], array('%title%' => $mailContext['title']));
//Create message
$message = \Swift_Message::newInstance()
//Create message
$message = \Swift_Message::newInstance()
}
} catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
//Add error message mail already exists
}
} catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
//Add error message mail already exists
- $form->get('mail')->addError(new FormError($trans->trans('Account already exists: %mail%', array('%mail%' => $data['mail']))));
+ $form->get('mail')->addError(new FormError($this->translator->trans('Account already exists: %mail%', array('%mail%' => $data['mail']))));
public function recoverAction(Request $request, Slugger $slugger) {
//Get mail template
public function recoverAction(Request $request, Slugger $slugger) {
//Get mail template
- $mailTemplate = $this->container->getParameter(($alias = $this->getAlias()).'.recover.mail_template');
+ $mailTemplate = $this->config['recover']['mail_template'];
- $mailContext = $this->container->getParameter($alias.'.recover.mail_context');
+ $mailContext = $this->config['recover']['mail_context'];
- $template = $this->container->getParameter($alias.'.recover.template');
+ $template = $this->config['recover']['template'];
- $context = $this->container->getParameter($alias.'.recover.context');
+ $context = $this->config['recover']['context'];
- $urlName = $this->container->getParameter($alias.'.recover.url_name');
+ $urlName = $this->config['recover']['url_name'];
- $urlArgs = $this->container->getParameter($alias.'.recover.url_args');
+ $urlArgs = $this->config['recover']['url_args'];
- $homeName = $this->container->getParameter($alias.'.contact.home_name');
+ $homeName = $this->config['contact']['home_name'];
- $homeArgs = $this->container->getParameter($alias.'.contact.home_args');
+ $homeArgs = $this->config['contact']['home_args'];
- $contactName = $this->container->getParameter($alias.'.contact.name');
+ $contactName = $this->config['contact']['name'];
- $contactMail = $this->container->getParameter($alias.'.contact.mail');
+ $contactMail = $this->config['contact']['mail'];
- $classUser = $this->container->getParameter($alias.'.class.user');
+ $classUser = $this->config['class']['user'];
//Create the form according to the FormType created previously.
//And give the proper parameters
//Create the form according to the FormType created previously.
//And give the proper parameters
$form->handleRequest($request);
if ($form->isValid()) {
$form->handleRequest($request);
if ($form->isValid()) {
- //Get translator
- $trans = $this->get('translator');
-
//Get doctrine
$doctrine = $this->getDoctrine();
//Get doctrine
$doctrine = $this->getDoctrine();
$data = $form->getData();
//Translate title
$data = $form->getData();
//Translate title
- $mailContext['title'] = $trans->trans($mailContext['title']);
+ $mailContext['title'] = $this->translator->trans($mailContext['title']);
//Try to find user
if ($user = $doctrine->getRepository($classUser)->findOneByMail($data['mail'])) {
//Translate title
//Try to find user
if ($user = $doctrine->getRepository($classUser)->findOneByMail($data['mail'])) {
//Translate title
- $mailContext['subtitle'] = $trans->trans($mailContext['subtitle'], array('%name%' => $user->getForename().' '.$user->getSurname().' ('.$user->getPseudonym().')'));
+ $mailContext['subtitle'] = $this->translator->trans($mailContext['subtitle'], array('%name%' => $user->getForename().' '.$user->getSurname().' ('.$user->getPseudonym().')'));
- $mailContext['subject'] = $trans->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
+ $mailContext['subject'] = $this->translator->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
- $mailContext['raw'] = $trans->trans($mailContext['raw'], array('%title%' => $mailContext['title'], '%url%' => $this->get('router')->generate($urlName, $urlArgs+array('mail' => $slugger->short($user->getMail()), 'hash' => $slugger->hash($user->getPassword())), UrlGeneratorInterface::ABSOLUTE_URL)));
+ $mailContext['raw'] = $this->translator->trans($mailContext['raw'], array('%title%' => $mailContext['title'], '%url%' => $this->get('router')->generate($urlName, $urlArgs+array('mail' => $slugger->short($user->getMail()), 'hash' => $slugger->hash($user->getPassword())), UrlGeneratorInterface::ABSOLUTE_URL)));
//Create message
$message = \Swift_Message::newInstance()
//Create message
$message = \Swift_Message::newInstance()
//Accout not found
} else {
//Add error message to mail field
//Accout not found
} else {
//Add error message to mail field
- $form->get('mail')->addError(new FormError($trans->trans('Unable to find account: %mail%', array('%mail%' => $data['mail']))));
+ $form->get('mail')->addError(new FormError($this->translator->trans('Unable to find account: %mail%', array('%mail%' => $data['mail']))));
public function recoverMailAction(Request $request, UserPasswordEncoderInterface $encoder, Slugger $slugger, $mail, $hash) {
//Get mail template
public function recoverMailAction(Request $request, UserPasswordEncoderInterface $encoder, Slugger $slugger, $mail, $hash) {
//Get mail template
- $mailTemplate = $this->container->getParameter(($alias = $this->getAlias()).'.recover_mail.mail_template');
+ $mailTemplate = $this->config['recover_mail']['mail_template'];
- $mailContext = $this->container->getParameter($alias.'.recover_mail.mail_context');
+ $mailContext = $this->config['recover_mail']['mail_context'];
- $template = $this->container->getParameter($alias.'.recover_mail.template');
+ $template = $this->config['recover_mail']['template'];
- $context = $this->container->getParameter($alias.'.recover_mail.context');
+ $context = $this->config['recover_mail']['context'];
- $urlName = $this->container->getParameter($alias.'.recover_mail.url_name');
+ $urlName = $this->config['recover_mail']['url_name'];
- $urlArgs = $this->container->getParameter($alias.'.recover_mail.url_args');
+ $urlArgs = $this->config['recover_mail']['url_args'];
- $homeName = $this->container->getParameter($alias.'.contact.home_name');
+ $homeName = $this->config['contact']['home_name'];
- $homeArgs = $this->container->getParameter($alias.'.contact.home_args');
+ $homeArgs = $this->config['contact']['home_args'];
- $contactName = $this->container->getParameter($alias.'.contact.name');
+ $contactName = $this->config['contact']['name'];
- $contactMail = $this->container->getParameter($alias.'.contact.mail');
+ $contactMail = $this->config['contact']['mail'];
- $classUser = $this->container->getParameter($alias.'.class.user');
+ $classUser = $this->config['class']['user'];
//Create the form according to the FormType created previously.
//And give the proper parameters
//Create the form according to the FormType created previously.
//And give the proper parameters
//Get doctrine
$doctrine = $this->getDoctrine();
//Get doctrine
$doctrine = $this->getDoctrine();
- //Get translator
- $trans = $this->get('translator');
-
//Init not found
$notfound = 1;
//Init not found
$notfound = 1;
$data = $form->getData();
//Translate title
$data = $form->getData();
//Translate title
- $mailContext['title'] = $trans->trans($mailContext['title']);
+ $mailContext['title'] = $this->translator->trans($mailContext['title']);
- $mailContext['subtitle'] = $trans->trans($mailContext['subtitle'], array('%name%' => $user->getForename().' '.$user->getSurname().' ('.$user->getPseudonym().')'));
+ $mailContext['subtitle'] = $this->translator->trans($mailContext['subtitle'], array('%name%' => $user->getForename().' '.$user->getSurname().' ('.$user->getPseudonym().')'));
- $mailContext['subject'] = $trans->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
+ $mailContext['subject'] = $this->translator->trans($mailContext['subject'], array('%title%' => $mailContext['title']));
//Set user password
$user->setPassword($encoder->encodePassword($user, $data['password']));
//Translate message
//Set user password
$user->setPassword($encoder->encodePassword($user, $data['password']));
//Translate message
- $mailContext['raw'] = $trans->trans($mailContext['raw'], array('%title%' => $mailContext['title'], '%url%' => $this->get('router')->generate($urlName, $urlArgs+array('mail' => $slugger->short($user->getMail()), 'hash' => $slugger->hash($user->getPassword())), UrlGeneratorInterface::ABSOLUTE_URL)));
+ $mailContext['raw'] = $this->translator->trans($mailContext['raw'], array('%title%' => $mailContext['title'], '%url%' => $this->get('router')->generate($urlName, $urlArgs+array('mail' => $slugger->short($user->getMail()), 'hash' => $slugger->hash($user->getPassword())), UrlGeneratorInterface::ABSOLUTE_URL)));
//Get manager
$manager = $doctrine->getManager();
//Get manager
$manager = $doctrine->getManager();