Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2. /**
  3. * Gets the value of an environment variable. Supports boolean, empty and null.
  4. *
  5. * @param string $key
  6. * @param mixed $default
  7. * @return mixed
  8. */
  9. function env($key, $default = null)
  10. {
  11. $value = getenv($key);
  12.  
  13. if ($value === false) {
  14. return value($default);
  15. }
  16.  
  17. switch (strtolower($value)) {
  18. case 'true':
  19. case '(true)':
  20. return true;
  21.  
  22. case 'false':
  23. case '(false)':
  24. return false;
  25.  
  26. case 'empty':
  27. case '(empty)':
  28. return '';
  29.  
  30. case 'null':
  31. case '(null)':
  32. return;
  33. }
  34.  
  35. if (Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
  36. return substr($value, 1, -1);
  37. }
  38.  
  39. return $value;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement