Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12317614
D3800.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D3800.diff
View Options
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -19,6 +19,7 @@
"require": {
"keruald/database": "0.5.2",
"keruald/omnitools": "0.15.1",
+ "netresearch/jsonmapper": "^v5.0.0",
"smarty/smarty": "^5.6.0",
"vlucas/phpdotenv": "^v5.6.2",
"ext-mysqli": "*"
diff --git a/workspaces/composer.json b/workspaces/composer.json
--- a/workspaces/composer.json
+++ b/workspaces/composer.json
@@ -10,6 +10,7 @@
"require-dev": {
"phpunit/phpunit": "^12.4",
"nasqueron/codestyle": "^0.1.2",
+ "netresearch/jsonmapper": "^v5.0.0",
"squizlabs/php_codesniffer": "^4.0",
"vlucas/phpdotenv": "^v5.6.2",
"ext-mysqli": "*"
diff --git a/workspaces/src/apps/documents/Document.php b/workspaces/src/apps/documents/Document.php
new file mode 100644
--- /dev/null
+++ b/workspaces/src/apps/documents/Document.php
@@ -0,0 +1,15 @@
+<?php
+
+class Document {
+ public string $id;
+
+ public string $title;
+
+ public string $date;
+
+ public DocumentType $type;
+
+ public array $refs = [];
+
+ public string $content;
+}
diff --git a/workspaces/src/apps/documents/DocumentType.php b/workspaces/src/apps/documents/DocumentType.php
new file mode 100644
--- /dev/null
+++ b/workspaces/src/apps/documents/DocumentType.php
@@ -0,0 +1,7 @@
+<?php
+
+enum DocumentType: string {
+ case Out = "Out";
+ case In = "In";
+ case Note = "Note";
+}
diff --git a/workspaces/src/apps/documents/DocumentsApplication.php b/workspaces/src/apps/documents/DocumentsApplication.php
--- a/workspaces/src/apps/documents/DocumentsApplication.php
+++ b/workspaces/src/apps/documents/DocumentsApplication.php
@@ -16,6 +16,7 @@
*/
use Waystone\Workspaces\Engines\Apps\Application;
+use Waystone\Workspaces\Engines\Errors\ErrorHandling;
/**
* Documents application class
@@ -67,11 +68,26 @@
public function getDocument ($docId) {
$file = $this->getFilePath($docId . '.json');
$data = file_get_contents($file);
- return json_decode($data);
+
+ $data = json_decode($data);
+ if ($data === null) {
+ ErrorHandling::messageAndDie(
+ GENERAL_ERROR,
+ json_last_error_msg(),
+ "Can't parse JSON to load $docId"
+ );
+ }
+
+ if (property_exists($data, "type")) {
+ $data->type = DocumentType::from(ucfirst($data->type));
+ }
+
+ $mapper = new JsonMapper();
+ return $mapper->map($data, new Document);
}
- public static function getDocumentType ($type) {
- $key = 'DocumentType' . ucfirst(strtolower($type));
+ public static function getDocumentType (DocumentType $type) : string {
+ $key = 'DocumentType' . $type->value;
return Language::get($key);
}
diff --git a/workspaces/src/includes/autoload.php b/workspaces/src/includes/autoload.php
--- a/workspaces/src/includes/autoload.php
+++ b/workspaces/src/includes/autoload.php
@@ -22,8 +22,10 @@
/// Applications
///
+ if ($name == 'Document') { require $dir . '/apps/documents/Document.php'; return true; }
if ($name == 'DocumentsApplication') { require $dir . '/apps/documents/DocumentsApplication.php'; return true; }
if ($name == 'DocumentsApplicationConfiguration') { require $dir . '/apps/documents/DocumentsApplicationConfiguration.php'; return true; }
+ if ($name == 'DocumentType') { require $dir . '/apps/documents/DocumentType.php'; return true; }
if ($name == 'HelloWorldApplication') { require $dir . '/apps/helloworld/HelloWorldApplication.php'; return true; }
diff --git a/workspaces/src/skins/bluegray/apps/documents/documents_view.tpl b/workspaces/src/skins/bluegray/apps/documents/documents_view.tpl
--- a/workspaces/src/skins/bluegray/apps/documents/documents_view.tpl
+++ b/workspaces/src/skins/bluegray/apps/documents/documents_view.tpl
@@ -9,8 +9,8 @@
<p><strong>{#Date#}{#_t#}</strong> {$document->date}</p>
<p><strong>{#Type#}{#_t#}</strong> {$documentType}</p>
{if $document->refs}
- <p><strong>{#RefsUs#}{#_t#}</strong> {$document->refs->us}</p>
- <p><strong>{#RefsYours#}{#_t#}</strong> {$document->refs->yours}</p>
+ <p><strong>{#RefsUs#}{#_t#}</strong> {$document->refs["us"]}</p>
+ <p><strong>{#RefsYours#}{#_t#}</strong> {$document->refs["yours"]}</p>
{/if}
</div>
</section>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 24, 00:56 (19 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3099657
Default Alt Text
D3800.diff (4 KB)
Attached To
Mode
D3800: Map loaded document into a proper Document class
Attached
Detach File
Event Timeline
Log In to Comment