Last active
December 30, 2015 19:39
-
-
Save sscovil/7875810 to your computer and use it in GitHub Desktop.
Revised (untested) map method for class-mapper.php: https://github.com/mediasilo/vulture/blob/master/inc/class-mapper.php#L60-L61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function map( $entity, $model ) { | |
$mapped = $entity; | |
foreach ( $entity as $key => $value ) { | |
if ( is_object( $entity ) ) { | |
if ( is_object( $value ) || is_array( $value ) ) | |
$mapped->$key = $this->map( $value, $model ); | |
else if ( property_exists( $model, $value ) ) | |
$mapped->$key = $this->translate( $value, $model->$value ); | |
} | |
else if ( is_array( $entity ) ) { | |
if ( is_object( $value ) || is_array( $value ) ) | |
$mapped[$key] = $this->map( $value, $model ); | |
else if ( property_exists( $model, $value ) ) { | |
if (isset($mapped[$key])) | |
$mapped[$key][] = $this->translate( $value, $model->$value ); | |
else | |
$mapped[$key] = $this->translate( $value, $model->$value ); | |
} | |
} | |
} | |
return $mapped; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment