ResponseFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 1
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