1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* balloon |
7
|
|
|
* |
8
|
|
|
* @copyright Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com) |
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Balloon\App\Wopi\Api\v2; |
13
|
|
|
|
14
|
|
|
use Balloon\App\Wopi\Template; |
15
|
|
|
use Balloon\Filesystem; |
16
|
|
|
use Balloon\Filesystem\Node\AttributeDecorator; |
17
|
|
|
use Balloon\Filesystem\Node\Collection; |
18
|
|
|
use Balloon\Server; |
19
|
|
|
use Micro\Http\Response; |
20
|
|
|
|
21
|
|
|
class Documents |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Filesystem. |
25
|
|
|
* |
26
|
|
|
* @var Filesystem |
27
|
|
|
*/ |
28
|
|
|
protected $fs; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Server. |
32
|
|
|
* |
33
|
|
|
* @var Server |
34
|
|
|
*/ |
35
|
|
|
protected $server; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Decorator. |
39
|
|
|
* |
40
|
|
|
* @var AttributeDecorator |
41
|
|
|
*/ |
42
|
|
|
protected $decorator; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor. |
46
|
|
|
*/ |
47
|
|
|
public function __construct(Server $server, AttributeDecorator $decorator) |
48
|
|
|
{ |
49
|
|
|
$this->server = $server; |
50
|
|
|
$this->fs = $server->getFilesystem(); |
51
|
|
|
$this->decorator = $decorator; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Create new empty document. |
56
|
|
|
*/ |
57
|
|
|
public function post(string $name, string $type, ?string $collection = null, int $conflict = 0, ?bool $readonly = null, ?array $meta = null): Response |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$parent = $this->fs->getNode($collection, Collection::class, false, true); |
60
|
|
|
$tpl = new Template($type); |
61
|
|
|
|
62
|
|
|
$attributes = compact('readonly', 'meta'); |
63
|
|
|
$attributes = array_filter($attributes, function ($attribute) {return !is_null($attribute); }); |
64
|
|
|
|
65
|
|
|
$stream = $tpl->get(); |
66
|
|
|
$storage = $parent->getStorage(); |
67
|
|
|
$session = $storage->storeTemporaryFile($stream, $this->server->getIdentity()); |
68
|
|
|
$result = $parent->addFile($name, $session, $attributes); |
69
|
|
|
fclose($stream); |
70
|
|
|
$result = $this->decorator->decorate($result); |
71
|
|
|
|
72
|
|
|
return (new Response())->setCode(201)->setBody($result); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.