src/Controller/ParametersNormalizerController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\RealContainerBearerController;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\DependencyInjection\Argument\ServiceLocator;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use App\Entity\WebService;
  8. use App\Util\AccessControl;
  9. /**
  10.  * Description of ParametersNormalizerController
  11.  * @author aealan
  12.  */
  13. class ParametersNormalizerController extends RealContainerBearerController {
  14.     /**
  15.      * @param type $propertyName
  16.      * @return type
  17.      */
  18.     public function __get($propertyName) {  
  19.         if ($propertyName == "realContainer") {
  20.             return $this->get('real_kernel')->getContainer();
  21.         } else {
  22.             return $this->$propertyName;
  23.         }
  24.     }
  25.     
  26.     /**
  27.      * Gets a container parameter by its name.
  28.      *
  29.      * @return mixed
  30.      *
  31.      * @final
  32.      */
  33.     protected function getParameter(string $name) {
  34.         $parameters $this->get('real_kernel')->getContainer()->getParameterBag()->all();
  35.         if (!isset($parameters[$name])) {
  36.             throw new ServiceNotFoundException('parameter_bag'nullnull, [], sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', \get_class($this)));
  37.         }
  38.         return $parameters[$name];
  39.     }
  40.     public function getContentInRequest($request) {
  41.         $params json_decode($request->getContent(), true);
  42.         if (is_null($params)) {
  43.             $params $request->request->getIterator()->getArrayCopy();
  44.         }
  45.         return $params;
  46.     }
  47.     public function validateFullEmail($email) {
  48.         if(filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
  49.             $explodeResult explode("@",$email);
  50.             if(checkdnsrr(array_pop($explodeResult),"MX")) {
  51.                 return true;
  52.             } else {
  53.                 return false;
  54.             }
  55.         } else {
  56.             return false;
  57.         }   
  58.     }
  59.     /**
  60.      * Funcion para enviar una respuesta de symfony tipo json para un ajax
  61.      * @author Aealan Z <lrobledo@kijho.com> 11/06/2016
  62.      * @param array $responseToAjax arreglo para ser enviado como respuesta
  63.      * @param integer $httpCode codigo de respuesta
  64.      * @return Response respuesta tipo json generica para un ajax
  65.      */
  66.     public function respondJsonAjax($responseToAjax$httpCode WebService::CODE_SUCCESS) {
  67.         $r = new Response(json_encode($responseToAjax));
  68.         $r->headers->set('Content-Type''application/json');
  69.         $r->setStatusCode($httpCode);
  70.         if (isset($responseToAjax['code'])) {
  71.             $r->setStatusCode($responseToAjax['code']);
  72.         }
  73.         return $r;
  74.     }
  75.     protected function validateSession($request, array $rolesstring $module){
  76.         if (is_null($roles)) {
  77.             $roles = [
  78.                 $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN'),
  79.                 $this->get('security.authorization_checker')->isGranted('ROLE_INTERNAL_SUPPORT'),
  80.                 $this->get('security.authorization_checker')->isGranted('ROLE_ADMINISTRATOR'),
  81.             ];
  82.         }
  83.         $access_control $this->get('access_control')->checkAccessModule($module$request);
  84.         $access_rol $this->get('access_control')->checkAccessRol($roles);
  85.         
  86.         if ($access_control !== AccessControl::ACCESS_GRANTED || $access_rol === false) {
  87.             if ($access_control == AccessControl::SESSION_LOST)
  88.                 return $this->redirect($this->generateUrl('level_licensor_login', array('msg' => 'Your session has expired. Please login again')));
  89.             elseif ($access_control == AccessControl::ACCESS_DENIED || $access_rol === false
  90.                 return $this->render('Default\errorInformation.html.twig');
  91.         }
  92.     }
  93.     
  94. }