summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php b/www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php
new file mode 100644
index 00000000..277f86ea
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/Parser/SemanticLinksParser.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace SMW\Parser;
+
+/**
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class SemanticLinksParser {
+
+ /**
+ * @var LinksProcessor
+ */
+ private $linksProcessor;
+
+ /**
+ * @since 2.5
+ *
+ * @param LinksProcessor $linksProcessor
+ */
+ public function __construct( LinksProcessor $linksProcessor ) {
+ $this->linksProcessor = $linksProcessor;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param $text
+ *
+ * @return array
+ */
+ public function parse( $text ) {
+
+ $matches = [];
+
+ preg_match(
+ $this->linksProcessor->getRegexpPattern(),
+ $text,
+ $matches
+ );
+
+ if ( $matches === [] ) {
+ return [];
+ }
+
+ $semanticLinks = $this->linksProcessor->preprocess( $matches );
+
+ if ( is_string( $semanticLinks ) ) {
+ return [];
+ }
+
+ $semanticLinks = $this->linksProcessor->process( $semanticLinks );
+
+ if ( is_string( $semanticLinks ) ) {
+ return [];
+ }
+
+ return $semanticLinks;
+ }
+
+}