예제 #1
0
 public function validate($data)
 {
     if (!is_object($data)) {
         throw new InvalidArgumentException('Json Schema must be an object');
     }
     $this->validator->reset();
     $this->validator->check($data, $this->schemaData);
     if (!$this->validator->isValid()) {
         $errors = [];
         foreach ((array) $this->validator->getErrors() as $error) {
             $errors[] = ($error['property'] ? $error['property'] . ' : ' : '') . $error['message'];
         }
         throw new JsonValidationException('Manifest file does not match the expected JSON schema', $errors);
     }
     if (!preg_match('/^[a-z0-9-_]+$/', $data->name)) {
         throw new JsonValidationException('Does not match the expected JSON schema', ['"name" must not contains only alphanumeric caracters']);
     }
     if (isset($data->{'minimum-phraseanet-version'})) {
         if (version::lt($this->version->getNumber(), $data->{'minimum-phraseanet-version'})) {
             throw new JsonValidationException(sprintf('Version incompatibility : Minimum Phraseanet version required is %s, current version is %s', $data->{'minimum-phraseanet-version'}, $this->version->getNumber()));
         }
     }
     if (isset($data->{'maximum-phraseanet-version'})) {
         if (version::gte($this->version->getNumber(), $data->{'maximum-phraseanet-version'})) {
             throw new JsonValidationException(sprintf('Version incompatibility : Maximum Phraseanet version required is %s, current version is %s', $data->{'maximum-phraseanet-version'}, $this->version->getNumber()));
         }
     }
 }
예제 #2
0
 function testEquality()
 {
     $compare = array(array("1.2.3", "v1.2.3"), array("1.2.3", "=1.2.3"), array("1.2.3", "v 1.2.3"), array("1.2.3", "= 1.2.3"), array("1.2.3", " v1.2.3"), array("1.2.3", " =1.2.3"), array("1.2.3", " v 1.2.3"), array("1.2.3", " = 1.2.3"), array("1.2.3-0", "v1.2.3-0"), array("1.2.3-0", "=1.2.3-0"), array("1.2.3-0", "v 1.2.3-0"), array("1.2.3-0", "= 1.2.3-0"), array("1.2.3-0", " v1.2.3-0"), array("1.2.3-0", " =1.2.3-0"), array("1.2.3-0", " v 1.2.3-0"), array("1.2.3-0", " = 1.2.3-0"), array("1.2.3-01", "v1.2.3-1"), array("1.2.3-01", "=1.2.3-1"), array("1.2.3-01", "v 1.2.3-1"), array("1.2.3-01", "= 1.2.3-1"), array("1.2.3-01", " v1.2.3-1"), array("1.2.3-01", " =1.2.3-1"), array("1.2.3-01", " v 1.2.3-1"), array("1.2.3-01", " = 1.2.3-1"), array("1.2.3beta", "v1.2.3beta"), array("1.2.3beta", "=1.2.3beta"), array("1.2.3beta", "v 1.2.3beta"), array("1.2.3beta", "= 1.2.3beta"), array("1.2.3beta", " v1.2.3beta"), array("1.2.3beta", " =1.2.3beta"), array("1.2.3beta", " v 1.2.3beta"), array("1.2.3beta", " = 1.2.3beta"));
     foreach ($compare as $set) {
         $a = $set[0];
         $b = $set[1];
         $this->assertTrue(SemVer\version::eq($a, $b), "%s > eq('" . $a . "', '" . $b . "')");
         $this->assertFalse(SemVer\version::neq($a, $b), "%s > !neq('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::cmp($a, "==", $b), "%s > cmp(" . $a . "==" . $b . ")");
         $this->assertFalse(SemVer\version::cmp($a, "!=", $b), "%s > !cmp(" . $a . "!=" . $b . ")");
         $this->assertFalse(SemVer\version::cmp($a, "===", $b), "%s > !cmp(" . $a . "===" . $b . ")");
         $this->assertTrue(SemVer\version::cmp($a, "!==", $b), "%s > cmp(" . $a . "!==" . $b . ")");
         $this->assertFalse(SemVer\version::gt($a, $b), "%s > !gt('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::gte($a, $b), "%s > gte('" . $a . "', '" . $b . "')");
         $this->assertFalse(SemVer\version::lt($a, $b), "%s > !lt('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::lte($a, $b), "%s > lte('" . $a . "', '" . $b . "')");
     }
 }