|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Icybee package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Olivier Laviale <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Icybee\Modules\Files\Routing; |
|
13
|
|
|
|
|
14
|
|
|
use ICanBoogie\HTTP\FileResponse; |
|
15
|
|
|
use ICanBoogie\HTTP\Request; |
|
16
|
|
|
use ICanBoogie\Routing\Controller; |
|
17
|
|
|
use ICanBoogie\Binding\Routing\ControllerBindings; |
|
18
|
|
|
use ICanBoogie\Binding\Routing\ForwardUndefinedPropertiesToApplication; |
|
19
|
|
|
use ICanBoogie\Module\ControllerBindings as ModuleBindings; |
|
20
|
|
|
|
|
21
|
|
|
use Icybee\Modules\Files\Binding\CoreBindings; |
|
22
|
|
|
use Icybee\Modules\Files\File; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Files public controller. |
|
26
|
|
|
*/ |
|
27
|
|
|
class FilesController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
use Controller\ActionTrait; |
|
30
|
|
|
use ControllerBindings, CoreBindings, ModuleBindings; |
|
31
|
|
|
use ForwardUndefinedPropertiesToApplication; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $uuid |
|
35
|
|
|
* |
|
36
|
|
|
* @return FileResponse |
|
37
|
|
|
*/ |
|
38
|
|
|
public function action_get_show($uuid) |
|
39
|
|
|
{ |
|
40
|
|
|
$pathname = $this->file_storage->find($uuid); |
|
41
|
|
|
|
|
42
|
|
|
if (!$pathname) |
|
43
|
|
|
{ |
|
44
|
|
|
return null; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return new FileResponse($pathname, $this->request, [ |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
FileResponse::OPTION_ETAG => $pathname->hash |
|
50
|
|
|
|
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $uuid |
|
56
|
|
|
* |
|
57
|
|
|
* @return FileResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public function action_get_download($uuid) |
|
60
|
|
|
{ |
|
61
|
|
|
$matches = $this->file_storage_index->find($uuid); |
|
62
|
|
|
|
|
63
|
|
|
if (!$matches) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$key = $matches[0]; |
|
69
|
|
|
$pathname = $this->file_storage->find($key); |
|
70
|
|
|
|
|
71
|
|
|
if (!$pathname) |
|
72
|
|
|
{ |
|
73
|
|
|
return null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/* @var $record File */ |
|
77
|
|
|
|
|
78
|
|
|
$record = $this->model[$key->id]; |
|
79
|
|
|
|
|
80
|
|
|
return new FileResponse($pathname, $this->request, [ |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
FileResponse::OPTION_ETAG => $pathname->hash, |
|
83
|
|
|
FileResponse::OPTION_FILENAME => $record->title . $record->extension, |
|
84
|
|
|
FileResponse::OPTION_MIME => $record->mime |
|
85
|
|
|
|
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.