file::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2021 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\controller;
12
13
use Symfony\Component\HttpFoundation\BinaryFileResponse;
14
use phpbb\exception\http_exception;
15
16
class file
17
{
18
	/** @var \blitze\sitemaker\services\filemanager */
19
	protected $filemanager;
20
21
	/** @var string */
22
	protected $phpbb_root_path;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * @param \blitze\sitemaker\services\filemanager		$filemanager		Filemanager object
28
	 * @param string										$phpbb_root_path	phpBB root path
29
	 */
30
	public function __construct(\blitze\sitemaker\services\filemanager $filemanager, $phpbb_root_path)
31
	{
32
		$this->filemanager = $filemanager;
33
		$this->phpbb_root_path = $phpbb_root_path;
34
	}
35
36
	/**
37
	 * @param string $file
38
	 * @return BinaryFileResponse
39
	 */
40
	public function handle($file)
41
	{
42
		$upload_path = $this->filemanager->get_upload_destination();
43
		$file = $this->phpbb_root_path . $upload_path . $file;
44
45
		if (!file_exists($file))
46
		{
47
			throw new http_exception(404, 'URL_NOT_FOUND');
48
		}
49
50
		return new BinaryFileResponse($file, 200);
51
	}
52
}
53