diff options
author | Camil Staps | 2015-05-17 16:44:43 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-17 16:44:43 +0200 |
commit | 1a115cfc53782fd51e55ed86671d10c7c2bb08b2 (patch) | |
tree | a880bcd98ed231dafcac199c57a8b4f2927de3a6 /src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php | |
parent | Support array as config.allowed_origin (diff) |
First attempt
Diffstat (limited to 'src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php | 83 |
1 files changed, 46 insertions, 37 deletions
diff --git a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php index 76167e2..35826b9 100644 --- a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php +++ b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php @@ -5,7 +5,7 @@ use \Illuminate\Support\Facades\Request; use \Illuminate\Support\ServiceProvider; use \Illuminate\Support\Facades\App; use \Illuminate\Support\Facades\Config; -use \Dingo\Api\Facade\API; +#use \Dingo\Api\Facade\API; use Redirect; use Response; @@ -25,13 +25,21 @@ class BotleaguesApiServiceProvider extends ServiceProvider { */ public function boot() { - $this->package('camil-staps/botleagues-api', null, __DIR__.'/../..'); + #$this->package('camil-staps/botleagues-api', null, __DIR__.'/../..'); + #$this->loadAutoloader(base_path('vendor')); + + $this->loadViewsFrom(__DIR__ . '/../../views', 'botleagues-api'); + $this->publishes([ __DIR__ . '/../../views' => base_path('resources/view/vendor/botleagues-api')], 'views'); + + $this->publishes([ __DIR__ . '/../../config/botleaguesapi.php' => config_path('botleaguesapi.php')], 'config'); include __DIR__ . '/../../filters.php'; + + $api = app('api.router'); include __DIR__ . '/../../routes.php'; - // To allow loading API requests from the specified domain - $allowed_origin = Config::get('config.allowed_origin'); + // To allow loading API requests from the specified domain + $allowed_origin = config('botleaguesapi.allowed_origin'); if (is_array($allowed_origin)) { $origin = Request::header('Origin'); if (in_array($origin, $allowed_origin)) { @@ -44,9 +52,11 @@ class BotleaguesApiServiceProvider extends ServiceProvider { } header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: Authorization'); + + var_dump(true); $this->setupErrorHandlers(); - } + } /** * Register the service provider. @@ -55,8 +65,7 @@ class BotleaguesApiServiceProvider extends ServiceProvider { */ public function register() { - $this->app->register('Dingo\Api\Provider\ApiServiceProvider'); - } + } /** * Get the services provided by the provider. @@ -65,43 +74,43 @@ class BotleaguesApiServiceProvider extends ServiceProvider { */ public function provides() { - return array(); + return array('CamilStaps\BotleaguesApi\BotleaguesApiServiceProvider'); } /** * Setup nice error handlers for exceptions and fatal errors */ private function setupErrorHandlers() { - App::fatal(function($e) { - return Response::make( - ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"], - 500); - }); +// App::fatal(function($e) { +// return Response::make( +// ['error' => config('app.debug') ? $e->getMessage() : "Internal error"], +// 500); +// }); - API::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e) { - return Response::make( - ['error' => 'Resource not found'], - 404); - }); - API::error(function(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $e) { - return Response::make( - ['error' => !Config::get('app.debug') || empty($e->getMessage()) ? 'Access denied' : $e->getMessage()], - 404); - }); - API::error(function(Exception\ValidationException $e) { - return Response::make( - [ - 'error' => $e->getMessage(), - 'errors' => $e->errors - ], - 500); - }); - - API::error(function(\Exception $e) { - return Response::make( - ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"], - 500); - }); +// API::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e) { +// return Response::make( +// ['error' => 'Resource not found'], +// 404); +// }); +// API::error(function(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $e) { +// return Response::make( +// ['error' => !config('app.debug') || empty($e->getMessage()) ? 'Access denied' : $e->getMessage()], +// 404); +// }); +// API::error(function(Exception\ValidationException $e) { +// return Response::make( +// [ +// 'error' => $e->getMessage(), +// 'errors' => $e->errors +// ], +// 500); +// }); +// +// API::error(function(\Exception $e) { +// return Response::make( +// ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"], +// 500); +// }); } } |