private function processProfileImage($event)
 {
     $em = $this->container->get('doctrine')->getManager();
     $user = $this->container->get('security.context')->getToken()->getUser();
     $file = $event->getFile();
     $request = $event->getRequest();
     $response = $event->getResponse();
     $galleryId = $request->get('gallery');
     $config = $event->getConfig();
     $gallery = $em->getRepository('ConnectionUserBundle:Profile\\Gallery')->getGalleryByIdOrDefault($user->getId(), $galleryId);
     if (!$file instanceof File || !$gallery) {
         throw new AccessDeniedException('No Gallery found');
     }
     $cropResult = $this->cropImage($file, $request->request);
     if (!$cropResult) {
         throw new \Exception('Fail cropping image');
     }
     $fileDir = str_replace($this->container->get('kernel')->getRootDir() . '/../web', "", $config['storage']['directory']);
     $image = new Image();
     $image->setName($file->getFilename());
     $image->setGallery($gallery);
     $image->setPath($fileDir . "/" . $user->getId() . "/" . $file->getFilename());
     if ($request->get('profile_default_image')) {
         $user->getProfile()->setAvatar($image->getPath());
         $em->persist($user);
     }
     $em->persist($image);
     $em->flush();
     $this->container->get('session')->getFlashBag()->add('success', 'Image uploaded successfully.');
     if (file_exists($image->getUploadRootDir())) {
         $response['id'] = $image->getId();
         $response['name'] = $image->getPath();
         $response['size'] = filesize($image->getUploadRootDir());
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getPath()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPath', array());
     return parent::getPath();
 }