Download a set of documents

@param  Request          $request
@return RedirectResponse
436452
public function checkDownload(Request $request)
    {
        $lst = $request->request->get('lst');
        $ssttid = $request->request->get('ssttid', '');
        $subdefs = $request->request->get('obj', []);

        $download = new \set_export($this->app, $lst, $ssttid);

        if (0 === $download->get_total_download()) {
            $this->app->abort(403);
        }

        $list = $download->prepare_export(
            $this->getAuthenticatedUser(),
            $this->app['filesystem'],
            $subdefs,
            $request->request->get('type') === 'title' ? true : false,
            $request->request->get('businessfields')
        );

        $list['export_name'] = sprintf('%s.zip', $download->getExportName());
        $token = $this->getTokenManipulator()->createDownloadToken($this->getAuthenticatedUser(), serialize($list));
        $this->getDispatcher()->dispatch(PhraseaEvents::EXPORT_CREATE, new ExportEvent(
            $this->getAuthenticatedUser(), $ssttid, $lst, $subdefs, $download->getExportName())
        );

        return $this->app->redirectPath('prepare_download', ['token' => $token->getValue()]);
    }
633354
public function replaceURLAction(Request $request)
    {
        $response = new JsonResponse();

        $response->setData(['text' => $this->urlHelper->replaceUrl($request->get('text'))]);

        return $response;
    }
1187921
public function removeAction(Request $request): Response
    {
        $form = $this->formFactory->removeCustomUrl();
        $form->handleRequest($request);

        $location = $form->getData()->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (CustomUrlRemoveData $data) {
                $aliasToRemoveList = [];
                foreach ($data->getUrlAliases() as $customUrlId => $selected) {
                    $aliasToRemoveList[] = $this->urlAliasService->load($customUrlId);
                }
                $this->urlAliasService->removeAliases($aliasToRemoveList);

                return $this->redirectToLocation($data->getLocation(), UrlsTab::URI_FRAGMENT);
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        if ($location) {
            return $this->redirectToLocation($location, UrlsTab::URI_FRAGMENT);
        }

        return $this->redirectToRoute('ezplatform.dashboard');
    }
760984
public function fileAction(Request $request)
    {
        $fileId = $request->get('file_id');

        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        $volume = $volumeManager->getByFileId($fileId);
        $file = $volume->findFile($fileId);

        $debug = [
            ['key' => 'mimeType', 'value' => $file->getMimeType()],
            ['key' => 'mediaType', 'value' => strtolower($file->getMediaType())],
            ['key' => 'fileId', 'value' => $file->getId()],
            ['key' => 'folderId', 'value' => $file->getFolderId()],
        ];

        return new JsonResponse(['debug' => $debug]);
    }
445335
public function cgetAction(Request $request)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));
        $queryString = $request->get('query');

        if ($request->get('flat') == 'true') {
            $list = $this->getListRepresentation($request);
        } else {
            $list = new CollectionRepresentation(
                $this->getManager()->findAllByLocaleAndQueryString($locale, $queryString),
                self::$entityKey
            );
        }

        $view = $this->view($list, 200);

        return $this->handleView($view);
    }
1223726
public function handleContentsAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ez:infocollector:read');

        $contents = $request->request->get('ContentId', []);
        $count = count($contents);

        if (empty($contents)) {
            $this->addFlashMessage('errors', 'contents_not_selected');

            return $this->redirectToRoute('netgen_information_collection.route.admin.overview');
        }

        if ($request->request->has('DeleteCollectionByContentAction')) {
            $query = new Query([
                'contents' => $contents,
            ]);
            $this->service->deleteCollectionByContent($query);

            $this->addFlashMessage('success', 'content_removed', $count);

            return $this->redirectToRoute('netgen_information_collection.route.admin.overview');
        }

        $this->addFlashMessage('error', 'something_went_wrong');

        return $this->redirectToRoute('netgen_information_collection.route.admin.overview');
    }
180838
protected function redirectAfterContentChange(Request $request)
    {
        if (null !== $referer = $request->headers->get('referer', null)) {
            return $this->redirect($referer);
        }

        return $this->redirect($this->generateUrl('ekyna_cart_index'));
    }
1094058
public function exportAction(Request $request)
    {
        $id = $request->query->get('workspace');
        $file = $this->container->get('claroline.manager.agenda_manager')->export($id);

        $response = new StreamedResponse();

        $response->setCallBack(
          function () use ($file) {
              readfile($file);
          }
        );

        $workspace = $this->om->getRepository(Workspace::class)->find($id);
        $name = $workspace ? $workspace->getName() : 'desktop';
        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename='.$name.'.ics');
        $response->headers->set('Content-Type', ' text/calendar');
        $response->headers->set('Connection', 'close');

        return $response;
    }
1271346
public function zipAction(Request $request)
    {
        $filename = basename($request->get('filename'));

        $path = $this->container->getParameter('phlexible_media_manager.temp_dir');
        $filepath = $path.'/'.$filename;

        if (!$filename || !file_exists($filepath)) {
            return $this->createNotFoundException();
        }

        $response = new BinaryFileResponse($filepath, 200, array('Content-Type' => 'application/zip'));
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);

        return $response;
    }
183780
public function DownloadAction(Request $request, $path)
    {
        /** @var FileManagerService $service */
        $service = $this->get('youwe.file_manager.service');
        $service->checkToken($request->get('token'));

        /** @var FileManagerDriver $driver */
        $driver = $this->get('youwe.file_manager.driver');
        $parameters = $this->container->getParameter('youwe_file_manager');
        $fileManager = $service->createFileManager($parameters, $driver);

        $filepath = $fileManager->getPath($path, null, true);
        $content = file_get_contents($filepath);
        $filename = basename($path);
        $response = new Response();

        $response->headers->set('Content-Type', 'mime/type');
        $response->headers->set('Content-Disposition', 'attachment;filename="' . $filename . '"');
        $response->setContent($content);

        return $response;
    }
646466
public function request(Request $request) : Response
    {
        if (!$this->resource) {
            $this->resource = curl_init();
        }

        // options
        $options = [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => true,
        ];

        // gzip, deflate
        if ($this->options[self::OPTIONS_ACCEPT_ENCODING]) {
            if ($this->options[self::OPTIONS_ACCEPT_ENCODING] == true) {
                $options[CURLOPT_ENCODING] = ''; //force curl to send all Accept-Encoding available
            } else {
                $options[CURLOPT_ENCODING] = $this->options[self::OPTIONS_ACCEPT_ENCODING];
            }
        }

        // ssl
        if (isset($this->options[self::OPTIONS_SSL_VERIFY]) && $this->options[self::OPTIONS_SSL_VERIFY] === false) {
            $options[CURLOPT_SSL_VERIFYHOST] = false;
            $options[CURLOPT_SSL_VERIFYPEER] = false;
        }

        // timeout
        if ($this->options[self::OPTIONS_TIMEOUT]) {
            $options[CURLOPT_TIMEOUT_MS] = $this->options[self::OPTIONS_TIMEOUT];
        }

        if ($this->options[self::OPTIONS_CONNECT_TIMEOUT]) {
            $options[CURLOPT_CONNECTTIMEOUT_MS] = $this->options[self::OPTIONS_CONNECT_TIMEOUT];
        }

        // proxy
        if (!empty($this->options[self::OPTIONS_PROXY])) {
            $options[CURLOPT_PROXY] = $this->options[self::OPTIONS_PROXY];
        }

        // proxy
        if (!empty($this->options[self::OPTIONS_FOLLOW_REDIRECTION])) {
            $options[CURLOPT_FOLLOWLOCATION] = $this->options[self::OPTIONS_FOLLOW_REDIRECTION];

            if (!empty($this->options[self::OPTIONS_MAX_REDIRECTION])) {
                $options[CURLOPT_MAXREDIRS] = $this->options[self::OPTIONS_MAX_REDIRECTION];
            }
        }

        // debug temporary files
        if (!empty($this->options[self::OPTIONS_DEBUG])) {
            $options[CURLOPT_VERBOSE] = true;
            $options[CURLOPT_STDERR] = fopen('php://temp', 'rw');
        }

        // headers handling
        $headers = array_merge($this->defaultHeader, $request->getHeaders());

        // add cookie to current headers
        if ($request->getCookies()) {
            $cookies = [];
            foreach ($request->getCookies() as $name => $cookie) {
                $cookies[] = $name . '=' . urlencode($cookie->getValue());
            }

            $headers['Cookie'] = implode('; ', $cookies);
        }

        if ($headers) {
            $finalHeaders = [];
            foreach ($headers as $name => $value) {
                $finalHeaders[] = $name . ': ' . $value;
            }
            $options[CURLOPT_HTTPHEADER] = $finalHeaders;
        }

        // handle post
        $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
        if ($request->getMethod() != 'GET') {
            if ($request->getPayload()) {
                $options[CURLOPT_POSTFIELDS] = $request->getPayload();
            } elseif ($request->getHeader('Content-Type') == 'multipart/form-data') {
                // as an array(): The data will be sent as multipart/form-data
                // which is not always accepted by the serve

                // There are "@" issue on multipart POST requests.
                $options[CURLOPT_SAFE_UPLOAD] = true;
                $options[CURLOPT_POSTFIELDS] = $request->getPosts();
            } else {
                // as url encoded string: The data will be sent as application/x-www-form-urlencoded,
                // which is the default encoding for submitted html form data.
                $options[CURLOPT_POSTFIELDS] = http_build_query($request->getPosts());
            }
        }

        // progress
        if ($this->progress) {
            $options[CURLOPT_NOPROGRESS] = false;
            $options[CURLOPT_PROGRESSFUNCTION] = $this->progress;
            $options[CURLOPT_BUFFERSIZE] = 1024;
        }

        // user & password
        if ($request->getUri()->getUser()) {
            $options[CURLOPT_USERPWD] = $request->getUri()->getUser() .
                ($request->getUri()->getPassword() ? ':' . $request->getUri()->getPassword() : '');
        }

        // final options
        $options[CURLOPT_URL] = $request->getUri()->get(false);

        curl_reset($this->resource);
        curl_setopt_array($this->resource, $options);

        // send request
        $requestEvent = new TimerEvent($this->options[self::OPTIONS_EVENTS_PREFIX] . '.request');
        $response = curl_exec($this->resource);
        $infos = curl_getinfo($this->resource);

        // request event
        $requestEvent->addData([
            'method' => $request->getMethod(),
            'url' => $request->getUri()->get(false),
            'code' => $infos['http_code'],
            'header size' => $infos['header_size'],
            'request size' => $infos['request_size'],
        ]);
        self::emit($requestEvent);

        // generate events for all duration
        $data = [
            'method' => $request->getMethod(),
            'url' => $request->getUri()->get(false),
            'code' => $infos['http_code'],
        ];

        $event = new ManualTimerEvent($this->options[self::OPTIONS_EVENTS_PREFIX] . '.nameLookup', $data);
        $event->setDuration($infos['namelookup_time'])
            ->setStart($requestEvent->getStart());
        self::emit($event);

        $event = new ManualTimerEvent($this->options[self::OPTIONS_EVENTS_PREFIX] . '.connect', $data);
        $event->setDuration($infos['connect_time'])
            ->setStart($requestEvent->getStart() + $infos['namelookup_time']);
        self::emit($event);

        // debug log
        if (!empty($this->options[self::OPTIONS_DEBUG])) {
            rewind($options[CURLOPT_STDERR]);
            $log = stream_get_contents($options[CURLOPT_STDERR]);

            if (isset($options[CURLOPT_POSTFIELDS]) && is_array($options[CURLOPT_POSTFIELDS])) {
                $log .= json_encode($log) . "\r\n";
            } elseif (isset($options[CURLOPT_POSTFIELDS])) {
                $log .= $options[CURLOPT_POSTFIELDS] . "\r\n";
            }

            if ($response) {
                $log = $log . "\r\n" . htmlentities(explode("\r\n\r\n", $response)[1]);
            }
            self::logger()->debug($log);
        }

        // connection error
        if ($response === false) {
            $code = curl_errno($this->resource);
            $message = curl_error($this->resource);

            throw new ConnectionException($request, $message, $code);
        }

        // final response
        $response = new Response($response);

        if ($response->getStatus() >= 400) {
            throw new RequestException($request, $response, $response->getStatus());
        }

        return $response;
    }
126546
public function readAction(Request $request)
    {
        $response = $this->convertResourceToPlainText(
            $request->getRequestFormat('xml'),
            $this->mapper->getResource($request->get('id'))
        );

        return new Response($response);
    }
765451
public function loadAction(Request $request)
    {
        $repo = $this->getDoctrine()->getRepository('LibrinfoMediaBundle:File');
        $files = [];

        foreach ($request->get('load_files') as $key => $id) {
            $file = null;

            $dispatcher = $this->get('event_dispatcher');

            $event = new GenericEvent(
                [
                    'request' => $request,
                    'context' => [
                        'key'  => $key,
                        'id'   => $id,
                        'file' => $file,
                    ],
                ], [
                    'file'  => null,
                    'files' => $files,
                ]
            );
            $dispatcher->dispatch(UploadControllerEventListener::PRE_GET_ENTITY, $event);

            $file = $event->getArgument('file');

            if ($file) {
                $file->setFile($file->getBase64File());
            }

            $event = new GenericEvent(
                [
                    'request' => $request,
                    'context' => [
                        'key'  => $key,
                        'id'   => $id,
                        'file' => $file,
                    ],
                ], [
                    'file'  => $file,
                    'files' => $files,
                ]
            );
            $dispatcher->dispatch(UploadControllerEventListener::POST_GET_ENTITY, $event);

            $file = $event->getArgument('file');

            if ($file) {
                $files[] = $file;
            }
        }

        return new JsonResponse($files, 200);
    }
1213824
public function store(Request $request)
    {
        $this->validate($request, ['name' => 'required']);

        $role = Role::create($request->all());
        $role->permissions()->detach();

        if ($request->has('permissions')) {
            foreach ($request->permissions as $permission_name) {
                $permission = Permission::whereName($permission_name)->first();
                $role->givePermissionTo($permission);
            }
        }

        return redirect('admin/roles')->with('flash_message', 'Role added!');
    }
366459
public function fileSaveAction(Request $request)
    {
        $url = null;
        $fileName = $request->get('fileName');
        $objectClass = $request->get('objectClass');
        $objectUuid = $request->get('objectUuid');
        $objectName = $request->get('objectName');
        $sourceType = $request->get('sourceType');

        if ($request->files->get('file')) {
            $publicFile = $this->fileUtils->createFile(
                $request->files->get('file'),
                $fileName,
                $objectClass,
                $objectUuid,
                $objectName,
                $sourceType
            );
            $url = $publicFile->getUrl();
        }

        return new JsonResponse($url, 200);
    }
74123
public function markAllAsReadAction(Request $request): Response
    {
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
        $this->isGrantedOr403($configuration, ResourceActions::UPDATE);

        $this->messageManager->markAllAsRead($this->getUser());

        if (!$configuration->isHtmlRequest()) {
            return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
        }

        $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE);

        return $this->redirectHandler->redirectToIndex($configuration);
    }
1072497
protected function dispatchRequest(Request $request): Collection
    {
        try {
            $response = $this->client->send($request);

            $this->response = $response;

            return $this->parseResponse($response);
        } catch (ClientException $exception) {

            $this->response = $exception->getResponse();

            if ($this->response->getStatusCode() === 404) {
                return new Collection;
            }

            throw $exception;
        }
    }