Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created May 13, 2015 12:02
Show Gist options
  • Save rizqidjamaluddin/c7d7b104e6a4a40e3e13 to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/c7d7b104e6a4a40e3e13 to your computer and use it in GitHub Desktop.
Laravel API gateway classes with a service provider and config file
<?php return [
'key' => 'apikeygoeshere'
];
<?php
class SomeDistantApiGateway {
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
public function getSomeData() {
// whatever API request over guzzle or something
}
}
<?php
class SomeDistantApiServiceProvider extends Illuminate\Support\ServiceProvider {
public function register() {
$this->app->bind(SomeDistantApiGateway::class, function($app) {
return new SomeDistantApiGateway($app['config']->get('someApi.key'));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment