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

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\ExtensionFrameworkBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  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\ControllerArgumentsEvent;
  9. use Webkul\UVDesk\ExtensionFrameworkBundle\Definition\MappingResource;
  10. class Kernel
  11. {
  12. private $isTwigConfigured = false;
  13. public function __construct(ContainerInterface $container, MappingResource $mappingResource)
  14. {
  15. $this->container = $container;
  16. $this->mappingResource = $mappingResource;
  17. }
  18. public function onKernelRequest(RequestEvent $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(ControllerArgumentsEvent $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. // if ($reflectionClass->hasMethod($method)) {
  36. // $args = [];
  37. // $controllerArguments = $event->getArguments();
  38. // foreach ($reflectionClass->getMethod($method)->getParameters() as $index => $parameter) {
  39. // if ($parameter->getType() != null && ApplicationInterface::class === $parameter->getType()->getName()) {
  40. // if (false === (bool) ($controllerArguments[$index] instanceof ApplicationInterface)) {
  41. // $vendor = $request->get('vendor');
  42. // $package = $request->get('extension');
  43. // $name = $request->get('application');
  44. // $application = $this->applicationCollection->findApplicationByFullyQualifiedName($vendor, $package, $name);
  45. // if (!empty($application)) {
  46. // $args[] = $application;
  47. // continue;
  48. // }
  49. // }
  50. // }
  51. // $args[] = $controllerArguments[$index];
  52. // }
  53. // $event->setArguments($args);
  54. // }
  55. }
  56. private function configureTwigResources()
  57. {
  58. if ($this->isTwigConfigured) {
  59. return $this;
  60. }
  61. $twig = $this->container->get('uvdesk_extension.twig_loader');
  62. foreach ($this->mappingResource->getPackages() as $id => $attributes) {
  63. $class = new \ReflectionClass($id);
  64. $resources = dirname($class->getFileName()) . "/Resources/views";
  65. list($vendor, $package) = explode('/', $attributes['metadata']['name']);
  66. if (is_dir($resources)) {
  67. $twig->addPath($resources, sprintf("_uvdesk_extension_%s_%s", str_replace('-', '_', $vendor), str_replace('-', '_', $package)));
  68. }
  69. }
  70. $this->isTwigConfigured = true;
  71. return $this;
  72. }
  73. }