Forked from rizqidjamaluddin/SomeDistantApiGateway.php
Created
February 17, 2017 18:51
-
-
Save thinkstylestudio/611b7f0dc84566789cfa8b7e87f81a23 to your computer and use it in GitHub Desktop.
Laravel API gateway classes with a service provider and config file
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 return [ | |
'key' => 'apikeygoeshere' | |
]; |
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 | |
class SomeDistantApiGateway { | |
public function __construct($apiKey) { | |
$this->apiKey = $apiKey; | |
} | |
public function getSomeData() { | |
// whatever API request over guzzle or something | |
} | |
} |
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 | |
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