This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lloric Mayuga Garcia <[email protected]>
- Loading branch information
Showing
12 changed files
with
896 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Dingo\Api\Transformer\Adapter\Fractal; | ||
use Dingo\Api\Transformer\Factory; | ||
use League\Fractal\Manager; | ||
use League\Fractal\Serializer\JsonApiSerializer; | ||
|
||
class SerializerSwitch | ||
{ | ||
// protected $drivers = [ | ||
// 'default_array' => 'League\Fractal\Serializer\ArraySerializer', | ||
// 'default_data_array' => 'League\Fractal\Serializer\DataArraySerializer', | ||
// 'json_api' => 'League\Fractal\Serializer\JsonApiSerializer', | ||
// | ||
// // change null resource return null instead of [] | ||
// 'array' => 'Liyu\Dingo\Serializers\ArraySerializer', | ||
// 'data_array' => 'Liyu\Dingo\Serializers\DataArraySerializer', | ||
// ]; | ||
|
||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
app(Factory::class)->setAdapter( | ||
function ($app) { | ||
$fractal = new Manager; | ||
$serializer = new JsonApiSerializer; | ||
|
||
$fractal->setSerializer($serializer); | ||
return new Fractal($fractal); | ||
} | ||
); | ||
return $next($request); | ||
} | ||
|
||
// protected function getDriver($name) | ||
// { | ||
// $name = array_key_exists($name, $this->drivers) ? $name : 'data_array'; | ||
// return $this->drivers[$name]; | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.