Skip to content

Commit

Permalink
DP-28 Add on demand toggling of resource wrapper
Browse files Browse the repository at this point in the history
- Add wrapping on request parameter or header
  • Loading branch information
yaroslavmo committed Apr 30, 2020
1 parent 71c97dc commit 2d5f1ab
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Utility/ResourcesWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,19 @@ public static function cleanResources(

public static function wrapResources($resources, $force = false)
{
if ($force || Config::get('df.always_wrap_resources', false)) {
$wrapParameter = request()->wrap;
$wrapHeader = request()->header('wrap');
$wrappingOnDemandEnabled = !is_null($wrapParameter) || !is_null($wrapHeader);

if ($wrappingOnDemandEnabled) {
return static::wrapOnCondition(to_bool($wrapParameter) || to_bool($wrapHeader), $resources);
}

return static::wrapOnCondition($force || Config::get('df.always_wrap_resources', false), $resources);
}

public static function wrapOnCondition($condition, $resources){
if ($condition) {
return [static::getWrapper() => $resources];
}

Expand Down

0 comments on commit 2d5f1ab

Please sign in to comment.