From 35cd3fc8b3035a713ddb064697649c20324213a3 Mon Sep 17 00:00:00 2001 From: zyberspace Date: Thu, 13 Oct 2016 19:38:25 +0200 Subject: [PATCH] `InterfaceGenerator` can now read the api key from a `.apikey` file --- .gitignore | 1 + .../SteamWebApi/InterfaceGenerator.php | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8775a21..e487530 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /composer.lock +/.apikey /vendor/ /phpdoc/ /.project diff --git a/lib/Zyberspace/SteamWebApi/InterfaceGenerator.php b/lib/Zyberspace/SteamWebApi/InterfaceGenerator.php index 1a72298..e9a05c7 100644 --- a/lib/Zyberspace/SteamWebApi/InterfaceGenerator.php +++ b/lib/Zyberspace/SteamWebApi/InterfaceGenerator.php @@ -17,10 +17,26 @@ class InterfaceGenerator { + static protected function _getApiKey(Event $event) { + //Check if api key got passed as argument + $arguments = $event->getArguments(); + if (isset($arguments[0])) { + return $arguments[0]; + } + + //Check for `.apikey` file in the working directory + $composer = $event->getComposer(); + $apiKeyFile = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', '.apikey'])); + if (is_readable($apiKeyFile)) { + return trim(file_get_contents($apiKeyFile)); + } + + //No api key found, throw Exception + throw new \Exception('Please provide a valid api key. Pass it as argument or put it in the `.apikey` file.'); + } static public function generateAll(Event $event) { - $arguments = $event->getArguments(); - $client = new Client($arguments[0]); + $client = new Client(static::_getApiKey($event)); $steamWebAPIUtil = new Interfaces\ISteamWebAPIUtil($client); $interfaces = $steamWebAPIUtil->GetSupportedAPIListV1()->apilist->interfaces; @@ -122,4 +138,4 @@ public function saveToFile() echo $this->_interfaceApiDefinition->name . PHP_EOL; } -} \ No newline at end of file +}