vendor/uvdesk/extension-framework/EventListener/Kernel.php line 34

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\ExtensionFrameworkBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  7. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  8. use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
  9. use Webkul\UVDesk\ExtensionFrameworkBundle\Definition\MappingResource;
  10. class Kernel
  11. {
  12.     private $isTwigConfigured false;
  13.     public function __construct(ContainerInterface $containerMappingResource $mappingResource)
  14.     {
  15.         $this->container $container;
  16.         $this->mappingResource $mappingResource;
  17.     }
  18.     public function onKernelRequest(GetResponseEvent $event)
  19.     {
  20.         if (!$event->isMasterRequest()) {
  21.             return;
  22.         }
  23.         if ('GET' === strtoupper($event->getRequest()->getMethod())) {
  24.             $this->configureTwigResources();
  25.         }
  26.     }
  27.     public function onKernelControllerArguments(FilterControllerArgumentsEvent $event)
  28.     {
  29.         if (!$event->isMasterRequest()) {
  30.             return;
  31.         }
  32.         // $request = $event->getRequest();
  33.         // list($class, $method) = explode('::', $request->get('_controller'));
  34.         // $reflectionClass = new \ReflectionClass($class);
  35.         
  36.         // if ($reflectionClass->hasMethod($method)) {
  37.         //     $args = [];
  38.         //     $controllerArguments = $event->getArguments();
  39.         //     foreach ($reflectionClass->getMethod($method)->getParameters() as $index => $parameter) {
  40.         //         if ($parameter->getType() != null && ApplicationInterface::class === $parameter->getType()->getName()) {
  41.         //             if (false === (bool) ($controllerArguments[$index] instanceof ApplicationInterface)) {
  42.         //                 $vendor = $request->get('vendor');
  43.         //                 $package = $request->get('extension');
  44.         //                 $name = $request->get('application');
  45.         //                 $application = $this->applicationCollection->findApplicationByFullyQualifiedName($vendor, $package, $name);
  46.         //                 if (!empty($application)) {
  47.         //                     $args[] = $application;
  48.         //                     continue;
  49.         //                 }
  50.         //             }
  51.         //         }
  52.                 
  53.         //         $args[] = $controllerArguments[$index];
  54.         //     }
  55.         //     $event->setArguments($args);
  56.         // }
  57.     }
  58.     private function configureTwigResources()
  59.     {
  60.         if ($this->isTwigConfigured) {
  61.             return $this;
  62.         }
  63.         $twig $this->container->get('uvdesk_extension.twig_loader');
  64.         foreach ($this->mappingResource->getPackages() as $id => $attributes) {
  65.             $class = new \ReflectionClass($id);
  66.             $resources dirname($class->getFileName()) . "/Resources/views";
  67.             list($vendor$package) = explode('/'$attributes['metadata']['name']);
  68.             if (is_dir($resources)) {
  69.                 $twig->addPath($resourcessprintf("_uvdesk_extension_%s_%s"str_replace('-''_'$vendor), str_replace('-''_'$package)));
  70.             }
  71.         }
  72.         $this->isTwigConfigured true;
  73.         
  74.         return $this;
  75.     }
  76. }