AfterRoute.php 699 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace demo\Middleware;
  3. use Silex\Application;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class AfterRoute {
  7. public static function next(Request $request, Response $response, Application $app) {
  8. $MESSAGE = "<p>" . $app['timer']->delay() .": in aR</p>\n";
  9. $content = $response->getContent();
  10. if ($content !== FALSE) {
  11. $content .= $MESSAGE;
  12. $response->setContent($content);
  13. }
  14. else {
  15. // Only echo info on text responses.
  16. $ct = $response->headers->get('Content-Type');
  17. if (isset($ct) && strpos($ct, 'text') !== 0) {
  18. return;
  19. }
  20. echo $MESSAGE;
  21. flush();
  22. }
  23. }
  24. }