diff --git a/README.md b/README.md index 93854ad..5fc58f9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ bitly4laravel ============= [![Build Status](https://travis-ci.org/jelovac/bitly4laravel.png?branch=master)](https://travis-ci.org/jelovac/bitly4laravel) [![Latest Stable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/stable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Total Downloads](https://poser.pugx.org/jelovac/bitly4laravel/downloads.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Latest Unstable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/unstable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![License](https://poser.pugx.org/jelovac/bitly4laravel/license.png)](https://packagist.org/packages/jelovac/bitly4laravel) -Provides basic bitly API to use with Laravel. +Provides a Laravel package to communicate with Bit.ly API. In order to use this API you need to get [OAuth Generic Access Token](https://bitly.com/a/oauth_apps) from Bitly website. diff --git a/composer.json b/composer.json index fe29f01..bfbc29c 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "jelovac/bitly4laravel", - "description": "Provides basic bitly API to use with Laravel", + "description": "Provides a Laravel package to communicate with Bit.ly API", "authors": [ { "name": "Vladimir Jelovac", - "email": "vladimir.jelovac@jeftinodosajta.com" + "email": "jelovac@users.noreply.github.com" } ], "license": "BSD-2-Clause", diff --git a/src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php b/src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php index a92859e..de2fe72 100644 --- a/src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php +++ b/src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php @@ -11,6 +11,25 @@ class Bitly4laravelServiceProvider extends ServiceProvider { */ protected $defer = false; + /** + * Actual provider + * + * @var \Illuminate\Support\ServiceProvider + */ + protected $provider; + + /** + * Create a new service provider instance. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * @return void + */ + public function __construct($app) + { + parent::__construct($app); + $this->provider = $this->getProvider(); + } + /** * Bootstrap the application events. * @@ -18,7 +37,7 @@ class Bitly4laravelServiceProvider extends ServiceProvider { */ public function boot() { - $this->package('jelovac/bitly4laravel'); + return $this->provider->boot(); } /** @@ -28,10 +47,22 @@ public function boot() */ public function register() { - $this->app['bitly4laravel'] = $this->app->share(function($app) { - $config = $app['config']->get('bitly4laravel::config'); - return new Bitly4laravel($config); - }); + return $this->provider->register(); + } + + /** + * Return ServiceProvider according to Laravel version + * + * @return \Intervention\Image\Provider\ProviderInterface + */ + private function getProvider() + { + $app = $this->app; + $version = intval($app::VERSION); + $provider = sprintf( + '\Jelovac\Bitly4laravel\ServiceProviders\Laravel%dServiceProvider', $version + ); + return new $provider($app); } /** @@ -44,4 +75,4 @@ public function provides() return array('bitly4laravel'); } -} \ No newline at end of file +} diff --git a/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel4ServiceProvider.php b/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel4ServiceProvider.php new file mode 100644 index 0000000..5e52b32 --- /dev/null +++ b/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel4ServiceProvider.php @@ -0,0 +1,30 @@ +package('jelovac/bitly4laravel'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app['bitly4laravel'] = $this->app->share(function($app) { + $config = $app['config']->get('bitly4laravel::config'); + return new Bitly4laravel($config); + }); + } + +} diff --git a/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel5ServiceProvider.php b/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel5ServiceProvider.php new file mode 100644 index 0000000..d29db49 --- /dev/null +++ b/src/Jelovac/Bitly4laravel/ServiceProviders/Laravel5ServiceProvider.php @@ -0,0 +1,35 @@ + $this->config_path("bitly4laravel.php"), + ); + $this->publishes($paths, 'config'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $configPath = __DIR__ . '/../../config/bitly4laravel.php'; + $this->mergeConfigFrom($configPath, 'bitly4laravel'); + $this->app['bitly4laravel'] = $this->app->share(function($app) { + return new Bitly4laravel($app['config']); + }); + } + +}