2016-08-29 22:48:55 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use Response;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
class ResponseMacroServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Perform post-registration booting of services.
|
|
|
|
*
|
|
|
|
* @param ResponseFactory $factory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
Response::macro('png', function ($src = "", $status = 200, $header = []) {
|
|
|
|
return Response::stream(function() use ($src, $status) {
|
|
|
|
echo $src;
|
|
|
|
}, $status, array_merge([
|
|
|
|
'Content-type' => 'image/png',
|
|
|
|
], $header));
|
|
|
|
});
|
2016-09-04 15:35:12 +08:00
|
|
|
|
|
|
|
Response::macro('rawJson', function ($src = "", $status = 200, $header = []) {
|
|
|
|
return Response::make($src)->header('Content-type', 'application/json');
|
|
|
|
});
|
2016-08-29 22:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|