Created
May 13, 2015 12:02
-
-
Save rizqidjamaluddin/c7d7b104e6a4a40e3e13 to your computer and use it in GitHub Desktop.
Laravel API gateway classes with a service provider and config file
This file contains 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 return [ | |
'key' => 'apikeygoeshere' | |
]; |
This file contains 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 | |
class SomeDistantApiGateway { | |
public function __construct($apiKey) { | |
$this->apiKey = $apiKey; | |
} | |
public function getSomeData() { | |
// whatever API request over guzzle or something | |
} | |
} |
This file contains 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 | |
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