-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,3 @@ public function make(array $data, int $status, array $headers = []): JsonRespons | |
return $response; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,8 @@ protected function includeTransformerRelations(BaseTransformer $transformer) | |
$this->with(Collection::make($transformer->defaultRelations()) | ||
->filter(function ($constrain, $relation) use ($relations) { | ||
return ! in_array(is_numeric($relation) ? $constrain : $relation, $relations); | ||
})->all()); | ||
}) | ||
->all()); | ||
} | ||
|
||
/** | ||
|
@@ -289,29 +290,24 @@ protected function stripEagerLoadConstraints(array $relations): array | |
} | ||
|
||
/** | ||
* Remove parameters from relations that must be eager loaded and | ||
* filter out the relations which have an includeXxx method. | ||
* Remove parameters from relations that must be eager loaded and filter | ||
* out the relations which have an includeXxx method. | ||
* | ||
* @param array $relations | ||
* @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer | ||
* @param array $relations | ||
* @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer | ||
* @return array | ||
*/ | ||
protected function prepareEagerLoadableRelations(array $relations, $transformer): array | ||
{ | ||
$cleanedRelations = []; | ||
|
||
foreach ($relations as $key => $value) { | ||
// Strip out parameters from relation name | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
flugg
Author
Owner
|
||
$relationName = explode(':', is_numeric($key) ? $value : $key)[0]; | ||
// Ignores all relation which have a includeXxx method | ||
// method_exists does not care if the $transformer is actually an object or not | ||
if (method_exists($transformer, 'include' . ucfirst($relationName))) { | ||
continue; | ||
} | ||
|
||
// If the key is numeric, value is the relation name: return it | ||
// Otherwise the key is the relation name and the value is a custom scope: | ||
// return the relation with the value untouched | ||
if(is_numeric($key)) { | ||
if (is_numeric($key)) { | ||
$cleanedRelations[$key] = $relationName; | ||
} else { | ||
$cleanedRelations[$relationName] = $value; | ||
|
To me, it doesn't seem a good idea to strip away all comments...
The code becomes a lot more difficult to work on if you have to guess what code does and why it does it in that way