summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php b/www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php
new file mode 100644
index 00000000..ec412a02
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueValidators/CompoundConstraintValueValidator.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace SMW\DataValues\ValueValidators;
+
+use RuntimeException;
+
+/**
+ * @private
+ *
+ * @license GNU GPL v2+
+ * @since 2.4
+ *
+ * @author mwjames
+ */
+class CompoundConstraintValueValidator implements ConstraintValueValidator {
+
+ /**
+ * @var boolean
+ */
+ private $hasConstraintViolation = false;
+
+ /**
+ * @var array
+ */
+ private $constraintValueValidators = [];
+
+ /**
+ * @since 2.4
+ *
+ * @param ConstraintValueValidator $constraintValueValidator
+ */
+ public function registerConstraintValueValidator( ConstraintValueValidator $constraintValueValidator ) {
+ $this->constraintValueValidators[] = $constraintValueValidator;
+ }
+
+ /**
+ * @since 2.4
+ *
+ * {@inheritDoc}
+ */
+ public function hasConstraintViolation() {
+ return $this->hasConstraintViolation;
+ }
+
+ /**
+ * @since 2.4
+ *
+ * {@inheritDoc}
+ */
+ public function validate( $dataValue ) {
+
+ $this->hasConstraintViolation = false;
+
+ if ( $this->constraintValueValidators === [] ) {
+ throw new RuntimeException( "Missing a registered ConstraintValueValidator" );
+ }
+
+ // Any constraint violation by a ConstraintValueValidator registered will
+ // force an immediate halt without checking any other possible constraint
+ foreach ( $this->constraintValueValidators as $constraintValueValidator ) {
+ $constraintValueValidator->validate( $dataValue );
+
+ if ( $constraintValueValidator->hasConstraintViolation() ) {
+ $this->hasConstraintViolation = true;
+ break;
+ }
+ }
+ }
+
+}