Пример #1
0
 /**
  * Check if an URN equals this one
  *
  * @param Urn $urn
  *
  * @return bool
  */
 public function equals($urn)
 {
     if (!$urn instanceof Urn) {
         return false;
     }
     return $this->toString() === $urn->toString();
 }
Пример #2
0
 /**
  * Test URN construction from string.
  *
  * @dataProvider provideUrnStrings()
  *
  * @param string $input
  * @param string $output
  * @param array  $expectations
  */
 public function testUrnConstructionFromString($input, $output, array $expectations)
 {
     $urn = Urn::fromString($input);
     $this->assertSame($output, (string) $urn);
     $this->assertSame($expectations['nid'], $urn->getNamespaceIdentifier());
     $this->assertSame($expectations['nss'], $urn->getNamespaceSpecificString());
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function setNamespaceSpecificString($namespaceSpecificString)
 {
     parent::setNamespaceSpecificString($namespaceSpecificString);
     $tuple = explode(':', parent::getNamespaceSpecificString(), 3);
     $category = array_shift($tuple);
     if (2 !== count($tuple) || $category !== $this->getCategory()) {
         throw new InvalidArgumentException(sprintf('Invalid namespace specific string "%s"', $namespaceSpecificString));
     }
     $this->setType(array_shift($tuple));
     $this->setVersion(intval(array_pop($tuple)));
     return $this;
 }
Пример #4
0
 /**
  * Create notification type from string
  *
  * @param string $string
  *
  * @throws InvalidArgumentException
  * @return $this
  */
 public static function fromString($string = self::DEFAULT_NOTIFICATION_TYPE)
 {
     $tuple = explode(':', $string, 2);
     $token = array_shift($tuple);
     if (self::UUID_TOKEN === strtolower($token)) {
         return self::fromUuid(Uuid::fromString($string));
     }
     if (self::URN_TOKEN === strtolower($token)) {
         return self::fromUrn(Urn::fromString($string));
     }
     $notificationType = new static();
     $notificationType->setToken($token);
     $notificationType->setValue(array_pop($tuple));
     return $notificationType;
 }
Пример #5
0
 /**
  * @covers GravityMedia\Urn\Urn::isValid()
  */
 public function testValidator()
 {
     $this->assertTrue(Urn::isValid('urn:this-is-an-example:t(h)i+s,i-s.a:n=o@t;h$e_r!e*x\'a%m/p?l#e'));
 }