summaryrefslogtreecommitdiff
path: root/src/Support/Logger.php
blob: 2712a6ee45df1f6338a536bf8f470af3a4145625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace App\Support;

use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Logger implements LoggerInterface
{
  public static function logRequestToFile(Request $request): void
  {
    @mkdir(dirname(dirname(__DIR__)) . "/.cache/log", recursive: true);
    $basePath = dirname(dirname(__DIR__)) . "/.cache/log/" . str_replace("/", "_", $request->getPathInfo());

    file_put_contents(
      $basePath . "-body.json",
      json_encode(json_decode($request->getContent()), JSON_PRETTY_PRINT)
    );

    file_put_contents(
      $basePath . "-query.json",
      json_encode($request->query->all(), JSON_PRETTY_PRINT)
    );

    file_put_contents(
      $basePath . "-header.json",
      json_encode($request->headers->all(), JSON_PRETTY_PRINT)
    );
  }

  public static function logResponseToFile(Request $request, Response $response): void
  {
    $basePath = dirname(dirname(__DIR__)) . "/.cache/log/" . str_replace("/", "_", $request->getPathInfo());

    file_put_contents(
      $basePath . "-response.json",
      json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT)
    );
  }

  public function emergency($message, array $context = []): void
  {
  }

  public function alert($message, array $context = []): void
  {
  }

  public function critical($message, array $context = []): void
  {
  }

  public function error($message, array $context = []): void
  {
  }

  public function warning($message, array $context = []): void
  {
  }

  public function notice($message, array $context = []): void
  {
  }

  public function info($message, array $context = []): void
  {
  }

  public function debug($message, array $context = []): void
  {
  }

  public function log($level, $message, array $context = []): void
  {
  }
}