12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace demo\Middleware;
- use Silex\Application;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- class AfterAll {
- /**
- * Arguments for before() middleware are fixed, unlike those of controllers.
- *
- * @param \Symfony\Component\HttpFoundation\Request $request
- * @param \Symfony\Component\HttpFoundation\Response $response
- * @param \Silex\Application $app
- *
- * @return \Symfony\Component\HttpFoundation\Response|void
- */
- public function __invoke(Request $request, Response $response, Application $app) {
- $MESSAGE = "<p>In aAM</p>\n";
- if ($response instanceof JsonResponse) {
- $content = $response->getContent();
- $raw = json_decode($content, TRUE);
- $raw[] = $MESSAGE;
- $newContent = json_encode($raw);
- $response->setContent($newContent);
- return $response;
- }
- // Only echo info on text responses.
- $ct = $response->headers->get('Content-Type');
- if (isset($ct) && strpos($ct, 'text') !== 0) {
- return;
- }
- echo $MESSAGE;
- }
- }
|