Skip to content

Commit

Permalink
✨ trying out a ServiceProvider and a Facade
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 20, 2018
1 parent 9c8cb81 commit 7023a89
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@
"psr-4": {
"acidjazz\\metapi\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"acidjazz\\metapi\\ServiceProvider"
],
"aliases": {
"MetaApiController": "acidjazz\\metapi\\Facade"
}
}
}
}
11 changes: 11 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace acidjazz\metapi;

class Facade extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor()
{
return MetApiController::class;
}
}
6 changes: 3 additions & 3 deletions src/MetApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,21 @@ protected function render($data=false,$code=200) {
$code = 403;
} else {
$response = $this->getMeta();
$response['query'] = $this->getQuery();
$response['query'] = $this->verify();
$response['data'] = $data;
}

if ($this->request->query('callback') !== null) {
$json = json_encode($response, JSON_PRETTY_PRINT);
$response = ['callback' => $this->request->query('callback'),'json' => $json];
return response(view('jsonp', $response), 200)->header('Content-type', 'text/javascript');
return response(view('metapi:jsonp', $response), 200)->header('Content-type', 'text/javascript');
}

if (
strpos($this->request->header('accept'),'text/html') !== false &&
config('app.debug') === true && $this->request->query('json') !== 'true')
{
return response(view('json', ['json' => json_encode($response, JSON_PRETTY_PRINT)]), $code);
return response(view('metapi:json', ['json' => json_encode($response, JSON_PRETTY_PRINT)]), $code);
}

return response()->json($response, $code, [], JSON_PRETTY_PRINT);
Expand Down

0 comments on commit 7023a89

Please sign in to comment.