Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created January 6, 2016 11:13
Show Gist options
  • Save rizqidjamaluddin/b138d894e4f6c4295189 to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/b138d894e4f6c4295189 to your computer and use it in GitHub Desktop.
SOME_API_KEY=12345
<?php
return [
'key' => env('SOME_API_KEY');
];
<?php
class SomeApiRepository {
protected $key;
function __construct ($key) {
$this->key = $key;
// add any other dependencies here, like Guzzle
}
/**
* Abstract stuff to helper protected methods as usual
*/
function getSomeInfo() {
return $this->httpFetcherDoohikie->grabSoAndSo();
}
}
<?php
class SomeApiServiceProvider extends ServiceProvider {
public function register() {
$this->app->bind(SomeApiRepository::class, function ($app) {
return new SomeApiRepository($app['config']->get('some-api-config.key'));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment