Create a streamed response for a given file.

@param  string  $path
@param  string|null  $name
@param  array|null  $headers
@param  string|null  $disposition
@return \Symfony\Component\HttpFoundation\StreamedResponse
322787
public function response($path, $name = null, array $headers = [], $disposition = 'inline')
    {
        $response = new StreamedResponse;

        $disposition = $response->headers->makeDisposition($disposition, $name ?? basename($path));

        $response->headers->replace($headers + [
            'Content-Type' => $this->mimeType($path),
            'Content-Length' => $this->size($path),
            'Content-Disposition' => $disposition,
        ]);

        $response->setCallback(function () use ($path) {
            $stream = $this->readStream($path);
            fpassthru($stream);
            fclose($stream);
        });

        return $response;
    }
1372320
protected function httpPostRaw(string $path, $body, array $requestHeaders = []): ResponseInterface
    {
        return $response = $this->httpClient->sendRequest(
            $this->requestBuilder->create('POST', $path, $requestHeaders, $body)
        );
    }
744974
public function store($name, $path)
    {
        $rawData = file_get_contents($path);

        $attachment = $this->client->post('attachments.json', [
            'query' => [
                'name' => $name,
            ],
            'body' => $rawData,
            'headers' => [
                'Content-Type' => mime_content_type($path),
                'Content-Length' => filesize($path),
            ],
        ]);

        return $this->response($attachment);
    }
988341
public static function response(
        $file,
        $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT,
        $fileName = null
    ) {
        if (!class_exists('Symfony\\Component\\HttpFoundation\\Response')) {
            throw new MimeTypeException('HttpFoundation component not found, install it.');
        }

        if (
        !in_array(
            $disposition,
            [ResponseHeaderBag::DISPOSITION_INLINE, ResponseHeaderBag::DISPOSITION_ATTACHMENT],
            true
        )
        ) {
            $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
        }

        $info = static::info($file);
        $spl = $info->getSplFileObject();

        $response = new Response($spl->fread($spl->getSize()));

        $response->headers->set('Content-Type', $info->getMimeType());
        $disposition = $response->headers->makeDisposition(
            $disposition,
            null === $fileName ? $spl->getFileName() : $fileName
        );
        $response->headers->set('Content-Disposition', $disposition);

        return $response;
    }
469113
public function read($name, $path = null) {
        // in cache?
        if(isset($this->cache[$name]))
            return !is_null($path) && isset($this->cache[$name][$path]) ? $this->cache[$name][$path] : $this->cache[$name];

        // no cookie?
        if(!$this->check($name))
            return null;

        return $this->cookies->get($name)->read($path);
    }
490662
public function seed($name, $paths = null)
    {
        $directories = is_null($paths) ? $this->getPaths($name, 'seeds') : $paths;
        $files       = $this->app->make('files');


        foreach ($directories as $path) {


            if ($files->isDirectory($path)) {
                $allFiles = $files->allFiles($path);


                foreach ($allFiles as $file) {

                    $class = $this->prepareSeedClass($file);
                    if (!is_null($class)) {
                        $this->seeder->call($this->prepareSeedClass($file));
                    }
                }
            }
        }
    }
1147256
private function doRequest($path, $headers = [])
    {
        if (!$this->isAvailable()) {
            throw new NotAvailableException('Service not available.');
        }

        if ($this->loadBalance !== null) {
            $uri = $this->loadBalance->getUri($this->serviceName);
            $this->zendClient->setUri($uri);
        }
        if ($this->appendPath && strlen($path) > 0 && $this->zendClient->getUri()->getPath() != '/') {
            $path = $this->zendClient->getUri()->getPath() . $path;
        }
        $this->zendClient->getUri()->setPath($path);

        $this->zendClient->getRequest()->getHeaders()->addHeaders($headers);

        if (!$this->zendClient->getRequest()->getHeaders()->has('X-Request-Id')) {
            $this->addRequestId();
        }

        $this->addRequestName($this->serviceName);

        $this->getEventManager()->trigger('request.pre', $this);

        $this->responseTime = 0;

        try {
            $requestTime = microtime(true);

            $zendHttpResponse = $this->zendClient->send();

            $this->responseTime = (float) sprintf('%.2f', (microtime(true) - $requestTime) * 1000);

            $this->addRequestTime($this->responseTime);

            $response = new Response($this->zendClient, $zendHttpResponse, $this->depth);
            $this->reportSuccess();
        } catch (RuntimeException $ex) {
            $this->reportFailure();
            $this->getEventManager()->trigger('request.fail', $this, $ex);
            throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
        } catch (\Exception $ex) {
            $this->reportFailure();
            $this->getEventManager()->trigger('request.fail', $this, $ex);
            throw new RuntimeException($ex->getMessage(), 500, $ex);
        }

        $this->getEventManager()->trigger('request.post', $this);

        $content = $response->getContent();

        return $content;
    }
936014
public function addPathHeader(string $name, $path)
    {
        return $this->add(new PathHeader($name, $path instanceof Address ? $path : new Address($path)));
    }
823282
protected function responseStream($path)
    {
        $response = new Response(file_get_contents($path), 200, [
            'Content-type' => 'application/pdf',
            'Content-Transfer-Encoding' => 'binary'
        ]);

        @unlink($path);

        return $response->send();
    }
815004
public function package($name, $path = '/packages/%s.json')
	{
		$url = sprintf($this->getUrl() . $path, $name);
		$this->_response = new Response(['json' => $this->request($url)]);
		return $this;
	}
375371
protected function httpPut(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
    {
        try {
            $response = $this->httpClient->sendRequest(
                $this->requestBuilder->create('PUT', $path, $requestHeaders, $this->createRequestBody($parameters))
            );
        } catch (Psr18\NetworkExceptionInterface $e) {
            throw HttpServerException::networkError($e);
        }

        return $response;
    }
991958
protected function postRaw($path, $body, $requestHeaders = array())
    {
        $response = $this->client->getHttpClient()->post(
            $path,
            $body,
            $requestHeaders
        );

        return ResponseMediator::getContent($response);
    }
316457
public function downloadFile($path = '', $destination = '', $name = '')
    {
        $response = $this->sendRequest('GET', $path);
        if ($name === '' && $response->getHeader('Content-Disposition')
            && is_array($response->getHeader('Content-Disposition'))
            && count($response->getHeader('Content-Disposition')) > 0
        ) {
            $matchResults = [];
            preg_match(
                "/.*?filename=\"(.*?)\".*?/",
                $response->getHeader('Content-Disposition')[0],
                $matchResults
            );
            $name = urldecode($matchResults[1]);
        }

        $file = $destination . $name;

        $result = file_put_contents($file, $response->getBody()) ? $file : false;

        return $result;
    }
1038922
public function serve($path, SymfonyRequest $request, $disposition = 'inline', $fileName = null, $prepared = true)
    {
        if (! file_exists($path)) {
            return new Response('File Not Found', 404);
        } else if (! is_readable($path)) {
            return new Response('Unauthorized Access', 403);
        }

        // Create a Binary File Response instance.
        $headers = array(
            'Access-Control-Allow-Origin' => '*',
        );

        $mimeType = $this->guessMimeType($path);

        if ($request->getMethod() == 'OPTIONS') {
            $headers = array_merge($headers, array(
                'Access-Control-Allow-Methods' => 'GET, HEAD, OPTIONS',
                'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin',
            ));

            return new Response('OK', 200, $headers);
        }

        // Not an OPTIONS request.
        else {
            $headers['Content-Type'] = $mimeType;
        }

        if ($mimeType !== 'application/json') {
            $response = new BinaryFileResponse($path, 200, $headers, true, $disposition, true, false);

            // Set the Content Disposition.
            $response->setContentDisposition($disposition, $fileName ?: basename($path));

            // Setup the (browser) Cache Control.
            $this->setupCacheControl($response);

            // Setup the Not Modified since...
            $response->isNotModified($request);
        } else {
            // We will do a special processing for the JSON files.
            $response = new JsonResponse(
                json_decode(file_get_contents($path), true), 200, $headers
            );
        }

        // Prepare the Response against the Request instance, if is requested.
        if ($prepared) {
            return $response->prepare($request);
        }

        return $response;
    }
549840
protected function httpGet(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
    {
        if (count($parameters) > 0) {
            $path .= '?'.http_build_query($parameters);
        }

        try {
            $response = $this->httpClient->sendRequest(
                $this->requestBuilder->create('GET', $path, $requestHeaders)
            );
        } catch (Psr18\NetworkExceptionInterface $e) {
            throw HttpServerException::networkError($e);
        }

        return $response;
    }
936142
public function updatePsrStream($path, StreamInterface $stream, $mimeType = null)
    {
        return $this->getFile($path)->update($stream, $mimeType);
    }
1144033
public function sendFile($filePath, $fileName = null)
    {
        if ($filePath instanceof File) {
            $filePath = $filePath->getPathname();
        }

        $response = new Response();
        $response->headers->set('Cache-Control', 'private');
        $response->headers->set('Content-Type', mime_content_type($filePath));
        $response->headers->set('Content-Disposition', 'attachment;filename="' . ($fileName ?: basename($filePath)). '"');
        $response->headers->set('Content-Length', filesize($filePath));

        $response->setContent(file_get_contents($filePath));

        return $response;
    }