error if the URI of a final report is not on w3.org
authorJean-Guilhem Rouel <jean-gui@w3.org>
Tue, 05 Aug 2014 14:12:10 +0200
changeset 329 b1eee6b311f2
parent 328 b96853ef1ced
child 330 b5b5d02f9b01
error if the URI of a final report is not on w3.org
src/Org/W3/Cg/Pub/SpecBundle/Entity/SpecRev.php
--- a/src/Org/W3/Cg/Pub/SpecBundle/Entity/SpecRev.php	Fri Apr 18 16:02:43 2014 +0200
+++ b/src/Org/W3/Cg/Pub/SpecBundle/Entity/SpecRev.php	Tue Aug 05 14:12:10 2014 +0200
@@ -4,12 +4,14 @@
 
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Component\Validator\ExecutionContext;
 
 /**
  * Org\W3\Cg\Pub\SpecBundle\Entity\SpecRev
  *
  * @ORM\Table()
  * @ORM\Entity
+ * @Assert\Callback(methods={"isURLValid"})
  */
 class SpecRev
 {
@@ -283,5 +285,14 @@
     {
         $this->id = $id;
     }
+
+    public function isURLValid(ExecutionContext $context)
+    {
+        if ($this->getFinal() && preg_match('|^https?://([^/]+\.)?w3.org/|', $this->getUri()) === 1) {
+            $propertyPath = $context->getPropertyPath(). '.uri';
+            $context->setPropertyPath($propertyPath);
+            $context->addViolation('A final report must be hosted on w3.org');
+        }
+    }
     
-    }
\ No newline at end of file
+}
\ No newline at end of file