-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeId.php
More file actions
37 lines (30 loc) · 790 Bytes
/
CompositeId.php
File metadata and controls
37 lines (30 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace sporm;
class CompositeId {
private $aIds; // [id] => function to get value, or the value
function __construct( $aIds ) {
$aIdNames = array_keys( $aIds );
asort( $aIdNames );
foreach( $aIdNames as $sIdName ) {
$this->aIds[$sIdName] = $aIds[$sIdName];
}
$this->aIds = $aIds;
}
function extractIdAsStringFromObject( $oObject ) {
$aValues = array();
foreach( $this->aIds as $sFunctionToGetId ) {
$aValues[] = $oObject->$sFunctionToGetId();
}
return implode( ",", $aValues );
}
function extractIdValuesAsString() {
$aValues = array();
foreach( $this->aIds as $sIdName => $sValue ) {
$aValues[] = $sValue;
}
return implode( ",", $aValues );
}
function __toString() {
return implode( ",", array_keys( $this->aIds ) );
}
}