Skip to content

Instantly share code, notes, and snippets.

@Kindari
Forked from spinegar/service_provider_correct.php
Last active December 23, 2015 12:39
Show Gist options
  • Save Kindari/6636837 to your computer and use it in GitHub Desktop.
Save Kindari/6636837 to your computer and use it in GitHub Desktop.
<?php
return array(
'provider' => 'Geocoder\Provider\FreeGeoIpProvider',
'adapter' => 'Geocoder\HttpAdapter\CurlHttpAdapter'
);
<?php
/**
* This file is part of the GeocoderLaravel library.
*
* (c) Antoine Corcy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Toin0u\Geocoder;
use Geocoder\Geocoder;
use Illuminate\Support\ServiceProvider;
/**
* Geocoder service provider
*
* @author Antoine Corcy <[email protected]>
*/
class GeocoderServiceProvider 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('toin0u/geocoder-laravel');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerAdapter();
$this->registerProvider();
$this->registerGeocoder();
}
public function registerAdapter() {
$this->app->singleton( 'geocoder.adapter',
$this->app['config']->get('geocoder-laravel::adapter', 'Geocoder\HttpAdapter\CurlHttpAdapter')
);
}
public function registerProvider() {
$this->app->singleton( 'geocoder.provider',
$this->app['config']->get('geocoder-laravel::provider', 'Geocoder\Provider\FreeGeoIpProvider')
);
}
public function registerGeocoder() {
$this->app['geocoder'] = $this->app->share(function($app) {
$geocoder = new Geocoder;
$geocoder->registerProvider($app['geocoder.provider']);
return $geocoder;
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('geocoder', 'geocoder.adapter', 'geocoder.provider');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment