-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrmConfigurationGenerator.php
More file actions
51 lines (34 loc) · 1.28 KB
/
OrmConfigurationGenerator.php
File metadata and controls
51 lines (34 loc) · 1.28 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace sporm;
class OrmConfigurationGenerator extends OrmConfiguration {
private $sClass;
private $aMappingConfiguration;
function __construct( $sClass, $sBaseTable, $aMappingConfiguration ) {
parent::__construct( $sBaseTable, array_keys( $aMappingConfiguration ) );
$this->sClass = $sClass;
$this->aMappingConfiguration = $aMappingConfiguration;
}
function buildRawData( $oObject ) {
$aRawData = array();
foreach ( $this->aMappingConfiguration as $sColumn => $sMethod ) {
// Needs some crazy error handling
$aRawData[ $sColumn ] = $oObject->$sMethod();
}
return $aRawData;
}
function buildReturnObject( $aData ) {
$fMapFunction = function( &$sValue , $sKey ) { $sValue = '$aData["'.$sKey.'"]'; };
$aParameters = $this->aMappingConfiguration;
array_walk( $aParameters, $fMapFunction );
$sParameters = implode( $aParameters, ',' );
$sCreateStatement = '$oObject = new ' . $this->sClass . " ( $sParameters );";
eval( $sCreateStatement );
return $oObject;
}
function buildInvalidObject( $sId = false ) {
$sParameters = 'false' . str_repeat( ',null', count( $this->aMappingConfiguration )-1 );
$sCreateStatement = '$oObject = new ' . $this->sClass . " ( $sParameters );";
eval( $sCreateStatement );
return $oObject;
}
}