Exemplo n.º 1
0
 public function testValidate()
 {
     $this->assertTrue(Location::validate(Location::US_CENTRAL1_B, true));
     $this->assertTrue(Location::validate(Location::US_CENTRAL1_B, false));
     $this->assertTrue(Location::validate('AKDBF', false));
     $this->assertTrue(Location::validate(Location::US_CENTRAL1_B, false));
     $this->assertFalse(Location::validate('USBC1', true));
 }
Exemplo n.º 2
0
Arquivo: Fid.php Projeto: fid/php
 /**
  * Generate a new FID
  *
  * @param string $vendor Vendor Key
  * @param string $app    App key
  * @param string $type
  * @param string $indicator
  * @param null   $secret
  * @param string $location
  *
  * @throws FidGenerateException
  *
  * @return string FID
  */
 public static function generate($vendor, $app, $type, $indicator = SystemIndicator::ENTITY, $secret = null, $location = Location::UNKNOWN_REGION)
 {
     if (strlen($vendor) !== 3) {
         throw new FidGenerateException("Vendor Key must be 3 characters");
     }
     if (strlen($app) !== 2) {
         throw new FidGenerateException("App Key must be 2 characters");
     }
     if (strlen($type) !== 2) {
         throw new FidGenerateException("Entity Type must be 2 characters");
     }
     if (!SystemIndicator::validate($indicator)) {
         throw new FidGenerateException("Invalid System Indicator");
     }
     if (!Location::validate($location)) {
         throw new FidGenerateException("Invalid Data Location");
     }
     $fid = sprintf("%s%s%s%s-%s-%s-%s", $indicator, $vendor, $app, $type, Base36TimeKey::generate(), $location, static::randomString($secret === null ? 7 : 6));
     if ($secret !== null) {
         $fid .= strtoupper(substr(md5($secret . $fid), 0, 1));
     }
     return $fid;
 }