Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1, Added new method isValidId #3

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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