Skip to content

Commit

Permalink
✨ Add syntax for aliasing keys of nested object.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawndev authored Jun 11, 2020
1 parent 6901a82 commit dcaeeba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ExporterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ protected function exportAttribute(string $attribute)
return $export;
}

if (preg_match('/^(.*) as (.*)$/', $attribute, $matches)) {
return [$matches[2] => $this->getAttributeValue($matches[1])];
}

return [$attribute => $this->getAttributeValue($attribute)];
}

protected function attributeIsAFunction($attribute)
{
if (preg_match("/(.*)\((.*)\)$/", $attribute, $groups)) {
return [$groups[1] => call_user_func_array([$this->exportable, $groups[1]], array_map('trim', explode(',', $groups[2])))];
if (preg_match("/(.*)\((.*)\)$/", $attribute, $matches)) {
return [$matches[1] => call_user_func_array([$this->exportable, $matches[1]], array_map('trim', explode(',', $matches[2])))];
}

return null;
Expand Down

0 comments on commit dcaeeba

Please sign in to comment.