-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.php
More file actions
66 lines (50 loc) · 1.59 KB
/
Controller.php
File metadata and controls
66 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Import additionnal class into the global namespace
use \LaswitchTech\Core\Abstracts\Controller;
class DocumentsController extends Controller {
/**
* Constructor
*/
public function __construct()
{
// Call Parent Constructor
parent::__construct();
// Retrieve the namespace
$namespace = $this->Request->getNamespace();
// Set Properties
switch($namespace){
case "/documents/get":
$this->Public = false;
$this->Level = 0;
break;
}
}
/**
* Get a Document
*
* @return mixed
*/
public function getAction(): mixed
{
// Retrieve the parameters
$uuid = $this->Request->getParams('GET', 'uuid') ?? null;
// Retrieve the document metadata
$document = $this->Model->Documents->fetchByUUID($uuid);
// Check if the document exists
if($document){
// Generate the document
$document['path'] = $this->Model->Documents->generate($document);
// Check if the document was generated
if($document['path']){
// Retrieve the document content
$document['content'] = file_get_contents($document['path']);
// Retrieve the document type
$document['type'] = mime_content_type($document['path']);
// Retrieve the document size
$document['size'] = filesize($document['path']);
}
}
// Return the document
return $document;
}
}