| 1 |
<?php |
| 2 |
|
| 3 |
namespace RabbitLoader\SDK; |
| 4 |
|
| 5 |
class Util |
| 6 |
{ |
| 7 |
//count of headers sent so far by RabbitLoader |
| 8 |
private static $sentCount = 0; |
| 9 |
|
| 10 |
public static function getRequestMethod() |
| 11 |
{ |
| 12 |
return empty($_SERVER['REQUEST_METHOD']) ? '' : strtolower($_SERVER['REQUEST_METHOD']); |
| 13 |
} |
| 14 |
|
| 15 |
public static function sendHeader($header, $replace) |
| 16 |
{ |
| 17 |
if (!empty($header) && (self::$sentCount < 50) && !headers_sent()) { |
| 18 |
header(substr($header, 0, 150), $replace); |
| 19 |
self::$sentCount++; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public static function append(&$body, $element) |
| 24 |
{ |
| 25 |
$replaced = 0; |
| 26 |
$body = str_ireplace('</head>', $element . '</head>', $body, $replaced); |
| 27 |
if (!$replaced) { |
| 28 |
$body = str_ireplace('</body>', $element . '</body>', $body, $replaced); |
| 29 |
} |
| 30 |
if (!$replaced) { |
| 31 |
$body = str_ireplace('</html>', $element . '</html>', $body, $replaced); |
| 32 |
} |
| 33 |
return $replaced > 0; |
| 34 |
} |
| 35 |
} |
| 36 |
|