Skip to content

Commit

Permalink
add default value to envS function
Browse files Browse the repository at this point in the history
  • Loading branch information
SublimeAmine committed Feb 14, 2018
1 parent 98a5337 commit 3e2681a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

if (!function_exists('envS')) {

function envS($name)
{
function envS($name, $default = '') {
$value = getenv($name);

//If we hev a value return it
Expand All @@ -17,24 +17,25 @@ function envS($name)
curl_setopt($request, CURLOPT_HTTPHEADER, ['X-Vault-Token: ' . $token]);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);

//get response
$response = curl_exec($request);

//close session
curl_close($request);

//parse response
if ($response === false) {
return false;
return strlen($default) == 0 ? false : $default;
}

$r = json_decode($response, true);

if (isset($r['data']['value'])) {
return (string) $r['data']['value'];
}
return false;
}

return strlen($default) == 0 ? false : $default;
}

}

0 comments on commit 3e2681a

Please sign in to comment.