Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
89.47% covered (warning)
89.47%
17 / 19
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Logview
89.47% covered (warning)
89.47%
17 / 19
50.00% covered (danger)
50.00%
1 / 2
4.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
88.89% covered (warning)
88.89%
16 / 18
0.00% covered (danger)
0.00%
0 / 1
3.01
1<?php
2
3declare(strict_types=1);
4
5namespace App\Controller\System;
6
7use App\Controller\BaseController;
8use App\Service\DeployLogParser;
9use Symfony\Bundle\FrameworkBundle\Console\Application;
10use Symfony\Component\Console\Input\ArrayInput;
11use Symfony\Component\Console\Output\BufferedOutput;
12use Symfony\Component\DependencyInjection\Attribute\Autowire;
13use Symfony\Component\Filesystem\Exception\IOException;
14use Symfony\Component\Filesystem\Filesystem;
15use Symfony\Component\HttpFoundation\Response;
16use Symfony\Component\HttpKernel\KernelInterface;
17use Symfony\Component\Routing\Attribute\Route;
18use Symfony\Component\Security\Http\Attribute\IsGranted;
19
20#[Route('/system/logview', name: 'system_logview', methods: ['GET'])]
21#[IsGranted('ROLE_ADMIN')]
22class Logview extends BaseController
23{
24    public function __construct(
25        private readonly KernelInterface $kernel,
26        private readonly DeployLogParser $logParser,
27    ) {}
28
29    public function __invoke(
30        #[Autowire('%kernel.project_dir%')] string $projectDir
31    ): Response {
32        $filesystem = new Filesystem();
33        $filename = $projectDir.'/var/log/deploy.log';
34        $entries = [];
35        $error = '';
36
37        try {
38            if ($filesystem->exists($filename)) {
39                $entries = $this->logParser->parse($filesystem->readFile($filename));
40            } else {
41                $error = 'No log file found!';
42            }
43        } catch (IOException $ioException) {
44            $this->addFlash('danger', $ioException->getMessage());
45        }
46
47        $output = new BufferedOutput();
48
49        $application = new Application($this->kernel);
50        $application->setAutoExit(false);
51        $application->run(new ArrayInput(['command' => 'about']), $output);
52
53        return $this->render('system/logview.html.twig', [
54            'project_dir' => $projectDir,
55            'logEntries' => array_reverse($entries),
56            'error' => $error,
57        ]);
58    }
59}