Skip to content

Commit

Permalink
Merge pull request #3 from dekuan/dev
Browse files Browse the repository at this point in the history
1, Added new method isValidId
  • Loading branch information
dekuan committed Aug 4, 2017
2 parents ddfcda8 + d7218ba commit e339bd6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/CDId.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,35 @@ public function parseId( $nId )
];
}

/**
* Verify whether the id is valid
*
* @param $nVal int 64 bits unique id
* @return boolean true or false
*/
public function isValidId( $nVal )
{
$bRet = false;
$arrD = $this->parseId( $nVal );
if ( is_array( $arrD ) &&
array_key_exists( 'center', $arrD ) &&
array_key_exists( 'node', $arrD ) &&
array_key_exists( 'time', $arrD ) &&
array_key_exists( 'rand', $arrD ) )
{
if ( $this->isValidCenterId( $arrD[ 'center' ] ) &&
$this->isValidNodeId( $arrD[ 'node' ] ) &&
$this->isValidTime( $arrD[ 'time' ] ) &&
$this->isValidRand( $arrD[ 'rand' ] ) )
{
$bRet = true;
}
}

return $bRet;
}


public function isValidCenterId( $nVal )
{
return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 63 );
Expand All @@ -153,6 +182,14 @@ public function isValidNodeId( $nVal )
{
return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 63 );
}
public function isValidTime( $nVal )
{
return is_numeric( $nVal ) && ( $nVal >= 0 );
}
public function isValidRand( $nVal )
{
return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 0x3FF );
}


/**
Expand Down

0 comments on commit e339bd6

Please sign in to comment.