|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
4
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
5
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace midgard\portable\api; |
|
8
|
|
|
|
|
9
|
|
|
use midgard\portable\storage\connection; |
|
10
|
|
|
use midgard_connection; |
|
11
|
|
|
|
|
12
|
|
|
class blob |
|
13
|
|
|
{ |
|
14
|
|
|
public $parentguid; |
|
15
|
|
|
|
|
16
|
|
|
public $content; |
|
17
|
|
|
|
|
18
|
|
|
protected attachment $attachment; |
|
19
|
|
|
|
|
20
|
9 |
|
public function __construct(attachment $attachment, string $encoding = 'UTF-8') |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
9 |
|
$this->attachment = $attachment; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
5 |
|
public function read_content() : ?string |
|
26
|
|
|
{ |
|
27
|
5 |
|
if ($this->exists()) { |
|
28
|
5 |
|
return file_get_contents($this->get_path()); |
|
29
|
|
|
} |
|
30
|
2 |
|
return null; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
4 |
|
public function write_content($content) : bool |
|
34
|
|
|
{ |
|
35
|
4 |
|
return file_put_contents($this->get_path(), $content) !== false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function remove_file() |
|
39
|
|
|
{ |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
3 |
|
public function get_handler(string $mode = 'w') |
|
43
|
|
|
{ |
|
44
|
3 |
|
return fopen($this->get_path(), $mode); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
8 |
|
public function get_path() : string |
|
48
|
|
|
{ |
|
49
|
8 |
|
if (empty($this->attachment->location)) { |
|
50
|
7 |
|
$location = connection::generate_guid(); |
|
51
|
7 |
|
$subdir1 = strtoupper($location[0]); |
|
52
|
7 |
|
$subdir2 = strtoupper($location[1]); |
|
53
|
7 |
|
$this->attachment->location = $subdir1 . DIRECTORY_SEPARATOR . $subdir2 . DIRECTORY_SEPARATOR . $location; |
|
54
|
|
|
} |
|
55
|
8 |
|
$blobdir = midgard_connection::get_instance()->config->blobdir; |
|
56
|
8 |
|
return $blobdir . DIRECTORY_SEPARATOR . $this->attachment->location; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
6 |
|
public function exists() : bool |
|
60
|
|
|
{ |
|
61
|
6 |
|
return file_exists($this->get_path()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.