diff --git a/Controller/UploadController.php b/Controller/UploadController.php index 63074e0..e8f320a 100644 --- a/Controller/UploadController.php +++ b/Controller/UploadController.php @@ -25,7 +25,9 @@ use Glavweb\UploaderBundle\Response\Response as UploaderResponse; use Glavweb\UploaderBundle\Response\ResponseInterface; use Glavweb\UploaderBundle\UploadEvents; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\File\Exception\UploadException; use Symfony\Component\HttpFoundation\File\File; @@ -41,8 +43,10 @@ * @package Glavweb\UploaderBundle * @author Andrey Nilov */ -class UploadController extends AbstractController +class UploadController implements ContainerAwareInterface { + use ContainerAwareTrait; + /** * @var array */ @@ -382,12 +386,13 @@ protected function dispatchPreUploadEvent(UploaderManager $uploaderManager, $context) { $configContext = $uploaderManager->getContextConfig($context); - $dispatcher = $this->get('event_dispatcher'); + /** @var EventDispatcher $dispatcher */ + $dispatcher = $this->get('event_dispatcher'); // dispatch pre upload event (both the specific and the general) $event = new PreUploadEvent($uploadedFile, $response, $request, $context, $configContext); - $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $event); - $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $context), $event); + $dispatcher->dispatch($event, UploadEvents::PRE_UPLOAD); + $dispatcher->dispatch($event, sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $context)); } /** @@ -409,12 +414,13 @@ protected function dispatchPostEvents(UploaderManager $uploaderManager, $context) { $configContext = $uploaderManager->getContextConfig($context); - $dispatcher = $this->get('event_dispatcher'); + /** @var EventDispatcher $dispatcher */ + $dispatcher = $this->get('event_dispatcher'); // dispatch post upload event (both the specific and the general) $event = new PostUploadEvent($uploadedFile, $media, $response, $request, $context, $configContext); - $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $event); - $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $context), $event); + $dispatcher->dispatch($event, UploadEvents::POST_UPLOAD); + $dispatcher->dispatch($event, sprintf('%s.%s', UploadEvents::POST_UPLOAD, $context)); } /** @@ -426,12 +432,13 @@ protected function dispatchPostEvents(UploaderManager $uploaderManager, protected function validate(UploaderManager $uploaderManager, FileInterface $file, Request $request, $context) { $configContext = $uploaderManager->getContextConfig($context); - $dispatcher = $this->get('event_dispatcher'); + /** @var EventDispatcher $dispatcher */ + $dispatcher = $this->get('event_dispatcher'); // dispatch validation event (both the specific and the general) $event = new ValidationEvent($file, $request, $configContext, $context); - $dispatcher->dispatch(UploadEvents::VALIDATION, $event); - $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $context), $event); + $dispatcher->dispatch($event, UploadEvents::VALIDATION); + $dispatcher->dispatch($event, sprintf('%s.%s', UploadEvents::VALIDATION, $context)); } /** @@ -492,4 +499,20 @@ public function setErrorHandler($errorHandler) { $this->errorHandler = $errorHandler; } + + /** + * @param string $service + * @return object|null + */ + private function get(string $service) { + return $this->container->get($service); + } + + /** + * @param string $parameter + * @return array|bool|float|int|string|null + */ + private function getParameter(string $parameter) { + return $this->container->getParameter($parameter); + } } \ No newline at end of file diff --git a/DependencyInjection/GlavwebUploaderExtension.php b/DependencyInjection/GlavwebUploaderExtension.php index 22721a5..96dc8b3 100644 --- a/DependencyInjection/GlavwebUploaderExtension.php +++ b/DependencyInjection/GlavwebUploaderExtension.php @@ -41,6 +41,10 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); + $this->addAnnotatedClassesToCompile([ + 'Glavweb\\UploaderBundle\\Controller\\' + ]); + $container->setParameter('glavweb_uploader.config', $config); }