Created
June 29, 2013 18:28
-
-
Save tournasdim/5892149 to your computer and use it in GitHub Desktop.
A Laravel ServiceProvider example (Laravel 4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Tournasdim\Getgravatar; | |
use Illuminate\Support\ServiceProvider; | |
class GravatarServiceProvider 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('tournasdim/getgravatar'); | |
} | |
/** | |
* Register the service provider. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app['gravatar'] = $this->app->share(function($app) | |
{ | |
return new Gravatar; | |
}); | |
// Shortcut , so devs don't need to add an Alias in config/app.php | |
$this->app->booting(function() | |
{ | |
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); | |
$loader->alias('Gravatar', 'Tournasdim\Getgravatar\Facades\Gravatar'); | |
}); | |
} | |
/** | |
* Get the services provided by the provider. | |
* | |
* @return array | |
*/ | |
public function provides() | |
{ | |
return array('gravatar'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment