ResponseFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the slince/think-glide
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Slince\Glide;
13
14
use League\Flysystem\FilesystemInterface;
15
use League\Glide\Responses\ResponseFactoryInterface;
16
use think\Response;
17
18
class ResponseFactory implements ResponseFactoryInterface
19
{
20
    /**
21
     * Create response.
22
     *
23
     * @param FilesystemInterface $cache
24
     * @param string              $path
25
     *
26
     * @return Response
27
     *
28
     * @throws \League\Flysystem\FileNotFoundException
29
     */
30
    public function create(FilesystemInterface $cache, $path)
31
    {
32
        $contentType = $cache->getMimetype($path);
33
        $contentLength = $cache->getSize($path);
34
35
        $response = new Response();
36
        $response->data(stream_get_contents($cache->readStream($path)))
37
            ->header([
38
                'Content-Type' => $contentType,
39
                'Content-Length' => $contentLength
40
            ]);
41
42
        return $response;
43
    }
44
}
45