|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bernhard Posselt <[email protected]> |
|
6
|
|
|
* @author Lukas Reschke <[email protected]> |
|
7
|
|
|
* @author Morris Jobke <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OCP\AppFramework\Http; |
|
26
|
|
|
|
|
27
|
|
|
use OCP\AppFramework\Http; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class StreamResponse |
|
31
|
|
|
* |
|
32
|
|
|
* @package OCP\AppFramework\Http |
|
33
|
|
|
* @since 8.1.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
class StreamResponse extends Response implements ICallbackResponse { |
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
private $filePath; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string|resource $filePath the path to the file or a file handle which should be streamed |
|
41
|
|
|
* @since 8.1.0 |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct ($filePath) { |
|
44
|
|
|
$this->filePath = $filePath; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Streams the file using readfile |
|
50
|
|
|
* |
|
51
|
|
|
* @param IOutput $output a small wrapper that handles output |
|
52
|
|
|
* @since 8.1.0 |
|
53
|
|
|
*/ |
|
54
|
|
|
public function callback (IOutput $output) { |
|
55
|
|
|
// handle caching |
|
56
|
|
|
if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
|
57
|
|
|
if (!(file_exists($this->filePath) || is_resource($this->filePath))) { |
|
58
|
|
|
$output->setHttpResponseCode(Http::STATUS_NOT_FOUND); |
|
59
|
|
|
} elseif ($output->setReadfile($this->filePath) === false) { |
|
60
|
|
|
$output->setHttpResponseCode(Http::STATUS_BAD_REQUEST); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.