From a97c204472f432241138463a8faba8b62a8cd3da Mon Sep 17 00:00:00 2001 From: Andi Voelpel Date: Fri, 6 Nov 2015 14:37:27 +0100 Subject: [PATCH 1/2] add relationsships with dash in relationship name --- src/AbstractSerializer.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/AbstractSerializer.php b/src/AbstractSerializer.php index 2c57ad1..747e005 100644 --- a/src/AbstractSerializer.php +++ b/src/AbstractSerializer.php @@ -53,6 +53,10 @@ public function getAttributes($model, array $fields = null) */ public function getRelationship($model, $name) { + if (stripos($name, '-')) { + $name = $this->replaceDashWithUppercase($name); + } + if (method_exists($this, $name)) { $relationship = $this->$name($model); @@ -64,4 +68,16 @@ public function getRelationship($model, $name) return $relationship; } } + + /** + * Removes all dashes from relationsship and uppercases the following letter. + * @example If relationship parent-page is needed the the function name will be changed to parentPage + * + * @param string Name of the function + * + * @return string New function name + */ + private function replaceDashWithUppercase($name) { + return lcfirst(implode('', array_map('ucfirst', explode('-', $name)))); + } } From 7099f7221a6fa7d70fcb1b310d9ba962da96e324 Mon Sep 17 00:00:00 2001 From: Andi Voelpel Date: Fri, 6 Nov 2015 14:46:35 +0100 Subject: [PATCH 2/2] code styling: moved bracket to next line --- src/AbstractSerializer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AbstractSerializer.php b/src/AbstractSerializer.php index 747e005..53dcd7a 100644 --- a/src/AbstractSerializer.php +++ b/src/AbstractSerializer.php @@ -77,7 +77,8 @@ public function getRelationship($model, $name) * * @return string New function name */ - private function replaceDashWithUppercase($name) { + private function replaceDashWithUppercase($name) + { return lcfirst(implode('', array_map('ucfirst', explode('-', $name)))); } }