/hphp/test/slow/ir_inlining/headers.php

http://github.com/facebook/hiphop-php · PHP · 37 lines · 30 code · 7 blank · 0 comment · 0 complexity · b6bed1846c2163c5941cc630f46a4fee MD5 · raw file

  1. <?hh
  2. function mapLookup($map, $key, $default) {
  3. return $map->containsKey($key) ? $map[$key] : $default;
  4. }
  5. final class HTTPHeaders {
  6. private $headers;
  7. public function __construct() {
  8. $this->headers = Map {
  9. 'foo' => 'bar',
  10. 'baz' => 'quux',
  11. }
  12. ;
  13. }
  14. public function getAllHeaders(): Map<string,string> {
  15. return $this->headers;
  16. }
  17. public function getHeader(string $name, ?string $default = null): ?string {
  18. return mapLookup($this->getAllHeaders(), strtolower($name), $default);
  19. }
  20. }
  21. function main() {
  22. $h = new HTTPHeaders();
  23. $val = $h->getHeader('blah', 'wat');
  24. echo $val;
  25. echo "\n";
  26. }
  27. <<__EntryPoint>>
  28. function main_headers() {
  29. main();
  30. }