From b5f8dc10aaca9252f8f1d354bd0fc6217679e193 Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Sun, 13 Aug 2017 18:20:51 -0400 Subject: [PATCH] 5.x Updates - Better error handling - Share is depreacated, now is singleton - Updated README.md --- README.md | 26 +++++++++++---- src/Braunson/FatSecret/FatSecret.php | 9 ++---- .../FatSecret/FatSecretServiceProvider.php | 32 +++---------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 97f4087..a9872c1 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ How to Install 1. Install the `braunson/fatsecret` package ```shell - $ composer require "braunson/fatsecret:dev-master" + $ composer require "braunson/fatsecret" ``` -2. Update `app/config/app.php` to activate FatSecret package +2. Update `config/app.php` to activate FatSecret package ```php # Add `FatSecretServiceProvider` to the `providers` array @@ -34,20 +34,32 @@ How to Install Configuration ------------- -1. Go to `app/config/services.php` and add this in with your details in the provided array +1. Go to `config/services.php` and add this in with your details in the provided array ```php // API Key & Secret (http://platform.fatsecret.com) - 'fatsecret' => [ - 'key' => 'YOUR-API-KEY-HERE', - 'secret' => 'YOUR-API-SECRET-HERE', - ], + 'fatsecret' => [ + 'secret' => env('FATSECRET_SECRET'), + 'key' => env('FATSECRET_KEY'), + ], + ``` + +2. Open your `.env` file and add in + ``` + FATSECRET_SECRET=YOUR-API-SECRET + FATSECRET_KEY=YOUR-API-KEY ``` Usage ------------------------ +When you are using this package in a file, make sure to add this to the top of your file: + +```php +use Fatsecret; +``` + The FatSecret is available as `FatSecret`, for example: ```php diff --git a/src/Braunson/FatSecret/FatSecret.php b/src/Braunson/FatSecret/FatSecret.php index 98ee4ee..d5a1f74 100644 --- a/src/Braunson/FatSecret/FatSecret.php +++ b/src/Braunson/FatSecret/FatSecret.php @@ -233,12 +233,9 @@ private function GetQueryResponse($requestUrl, $postString) private function ErrorCheck($exception) { if (isset($exception['error'])) { - App::fatal(function(Exception $exception) - { - Log::error($exception['error']['message']); - }); - - App::abort(500, $exception['error']['message']); + \Log::error($exception['error']['message']); + $backtrace = debug_backtrace(); + throw new \ErrorException($exception['error']['message'], 0, $exception['error']['code'], __FILE__, $backtrace[0]['line']); } } } diff --git a/src/Braunson/FatSecret/FatSecretServiceProvider.php b/src/Braunson/FatSecret/FatSecretServiceProvider.php index ff15e01..feb1740 100644 --- a/src/Braunson/FatSecret/FatSecretServiceProvider.php +++ b/src/Braunson/FatSecret/FatSecretServiceProvider.php @@ -4,44 +4,22 @@ class FatSecretServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Bootstrap the application events. - * - * @return void - */ public function boot() { - $this->package('braunson/fat-secret'); + // } - /** - * Register the service provider. - * - * @return void - */ public function register() { - $this->app['fatsecret'] = $this->app->share(function($app) - { - return new FatSecret(\Config::get('services.fatsecret.key'), \Config::get('services.fatsecret.secret')); + $this->app->singleton(FatSecret::class, function () { + return new FatSecret(config('services.fatsecret.key'), config('services.fatsecret.secret')); }); + + $this->app->alias(FatSecret::class, 'fatsecret'); } - /** - * Get the services provided by the provider. - * - * @return array - */ public function provides() { return array('fatsecret'); } - }