Skip to content

Commit

Permalink
clean up service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
anlutro committed Jun 26, 2015
1 parent fb1514f commit f256d8c
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/Laravel/BulkSmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@ class BulkSmsServiceProvider extends ServiceProvider
*/
protected $defer = false;

/**
* Whether the Laravel version is 5.x or not.
*
* @var boolean
*/
protected $l5;

/**
* Register the service on the IoC container.
*
* @return void
*/
public function register()
{
$this->app['bulksms'] = $this->app->share(
function ($app) {
if (version_compare(Application::VERSION, '5.0', '>=')) {
$username = $app['config']->get('bulk-sms.username');
$password = $app['config']->get('bulk-sms.password');
$baseurl = $app['config']->get('bulk-sms.baseurl');
} else {
$username = $app['config']->get('bulk-sms::username');
$password = $app['config']->get('bulk-sms::password');
$baseurl = $app['config']->get('bulk-sms::baseurl');
}
$l5 = $this->l5 = version_compare(Application::VERSION, '5.0', '>=');

$this->app['bulksms'] = $this->app->share(function ($app) use($l5) {
$delim = $l5 ? '.' : '::';
$config = $app['config'];
$username = $config->get("bulk-sms{$delim}username");
$password = $config->get("bulk-sms{$delim}password");
$baseurl = $config->get("bulk-sms{$delim}baseurl");

$curl = isset($app['curl']) ? $app['curl'] : null;

if (isset($app['curl'])) {
return new BulkSmsService($username, $password, $baseurl, $app['curl']);
} else {
return new BulkSmsService($username, $password, $baseurl, null);
}
}
);
return new BulkSmsService($username, $password, $baseurl, $curl);
});

if (version_compare(Application::VERSION, '5.0', '>=')) {
if ($l5) {
$dir = dirname(dirname(__DIR__)).'/resources';
$this->mergeConfigFrom($dir.'/config.php', 'bulk-sms');
}
Expand All @@ -67,7 +68,7 @@ public function boot()
{
$dir = dirname(dirname(__DIR__)).'/resources';

if (version_compare(Application::VERSION, '5.0', '>=')) {
if ($this->l5) {
$this->publishes([
$dir.'/config.php' => config_path('bulk-sms.php')
], 'config');
Expand Down

0 comments on commit f256d8c

Please sign in to comment.