Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Added CreateUniqueIdentifier function to Base class, creates a unique…
Browse files Browse the repository at this point in the history
… identifier string, then calls components to check to see if it truly is unique. Continues until a completely unique identifier string is found.
  • Loading branch information
michaelchisari authored and The Appleseed Project committed Oct 19, 2010
1 parent 5637e64 commit 7295aab
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions system/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public function Set ( $pVariable, $pValue ) {
return ( true );
}

/**
* Destroy a private variable
*
* @access public
*/
public function Destroy ( $pVariable ) {

$variable = '_' . ltrim ( rtrim ( $pVariable ) );

unset ( $this->$variable );

return ( true );
}

public function AddSys ( $pVariable, $pLocation ) {

$variable = ltrim ( rtrim ( $pVariable ) );
Expand Down Expand Up @@ -93,4 +107,30 @@ public function GetSys ( $pVariable ) {
return ( $zApp->$variable );
}

public function CreateUniqueIdentifier ( $pLength = 32 ) {

$length = (int) $pLength;

$components = $this->GetSys ( 'Components' );
$componentList = $components->Get ( 'Config' )->Get ( 'Components' );

$unique = false;
while ( !$unique ) {
$id = $this->GetSys ( 'Crypt' )->Identifier ( $length );

$exists = false;
foreach ( $componentList as $c => $component ) {
$data = array ( 'Identifier' => $id );
if ( $check = $components->Talk ( $component, 'IdentifierExists', $data ) ) {
// Existing record has been found, break the loop, and generate another.
$exists = true;
break;
}
}
if ( !$exists ) break;
}

return ( $id );
}

}

0 comments on commit 7295aab

Please sign in to comment.