server/src/app/Models/WebResource.php
changeset 168 17f10b56c079
child 169 8fddc113095e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/app/Models/WebResource.php	Thu Jun 02 18:24:19 2016 +0200
@@ -0,0 +1,52 @@
+<?php
+namespace CorpusParole\Models;
+
+use CorpusParole\Libraries\RdfModel\RdfModelResource;
+use JsonSerializable;
+use Log;
+
+/**
+ * Model class for Document. Inherit from EasyRd\Resource
+ * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}
+ */
+abstract class WebResource extends RdfModelResource implements JsonSerializable {
+
+    public function __construct(...$args) {
+        list($uri, $graph) = $args;
+        parent::__construct($uri, $graph);
+    }
+
+    private $format = -1;
+
+    abstract protected function doClearMemoizationCache();
+
+    public function clearMemoizationCache() {
+        $this->format = -1;
+        $this->doClearMemoizationCache();
+    }
+
+    public function getFormat() {
+        if($this->format === -1) {
+            $format = $this->getLiteral("<http://purl.org/dc/elements/1.1/format>");
+            $this->format = is_null($format)?null:$format->getValue();
+        }
+        return $this->format;
+    }
+
+    public function getUrl() {
+        return $this->getUri();
+    }
+
+    abstract protected function jsonSerializeExtra();
+
+    public function jsonSerialize() {
+        return array_merge(
+            [
+                'url' => $this->getUrl(),
+                'format' => $this->getFormat()
+            ],
+            $this->jsonSerializeExtra()
+        );
+    }
+
+}
\ No newline at end of file