Skip to content

Instantly share code, notes, and snippets.

@sscovil
Last active December 30, 2015 19:39
Show Gist options
  • Save sscovil/7875810 to your computer and use it in GitHub Desktop.
Save sscovil/7875810 to your computer and use it in GitHub Desktop.
<?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