summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Flow/includes/Parsoid/ReferenceFactory.php')
-rw-r--r--Flow/includes/Parsoid/ReferenceFactory.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/Flow/includes/Parsoid/ReferenceFactory.php b/Flow/includes/Parsoid/ReferenceFactory.php
new file mode 100644
index 00000000..1443b79b
--- /dev/null
+++ b/Flow/includes/Parsoid/ReferenceFactory.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Flow\Parsoid;
+
+use Flow\Model\URLReference;
+use Flow\Model\UUID;
+use Flow\Model\WikiReference;
+use Flow\Model\Workflow;
+use Title;
+
+class ReferenceFactory {
+ /**
+ * @var UUID
+ */
+ protected $workflowId;
+
+ /**
+ * @var Title
+ */
+ protected $title;
+
+ /**
+ * @var string
+ */
+ protected $objectType;
+
+ /**
+ * @var UUID
+ */
+ protected $objectId;
+
+ /**
+ * @param Workflow $workflow
+ * @param string $objectType
+ * @param UUID $objectId
+ */
+ public function __construct( Workflow $workflow, $objectType, UUID $objectId ) {
+ $this->workflowId = $workflow->getId();
+ $this->title = $workflow->getArticleTitle();
+ $this->objectType = $objectType;
+ $this->objectId = $objectId;
+ }
+
+ /**
+ * @param string $refType
+ * @param string $value
+ * @return URLReference
+ */
+ public function createUrlReference( $refType, $value ) {
+ return new URLReference(
+ $this->workflowId,
+ $this->title,
+ $this->objectType,
+ $this->objectId,
+ $refType,
+ $value
+ );
+ }
+
+ /**
+ * @param string $refType
+ * @param string $value
+ * @return WikiReference|null
+ */
+ public function createWikiReference( $refType, $value ) {
+ $title = Utils::createRelativeTitle( $value, $this->title );
+
+ if ( $title === null ) {
+ return null;
+ }
+
+ return new WikiReference(
+ $this->workflowId,
+ $this->title,
+ $this->objectType,
+ $this->objectId,
+ $refType,
+ $title
+ );
+ }
+}