Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
42 / 42 |
|
100.00% |
14 / 14 |
|
40.00% |
4 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AdminController | |
100.00% |
42 / 42 |
|
100.00% |
14 / 14 |
|
40.00% |
4 / 10 |
|
100.00% |
3 / 3 |
26.50 | |
100.00% |
1 / 1 |
| index | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
|
0.00% |
0 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| log | |
100.00% |
17 / 17 |
|
100.00% |
7 / 7 |
|
60.00% |
3 / 5 |
|
100.00% |
1 / 1 |
6.60 | |||
| applicationInfo | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Controller\Admin; |
| 4 | |
| 5 | use App\Application; |
| 6 | use App\Kernel; |
| 7 | use App\Security\Action; |
| 8 | use App\Security\Role; |
| 9 | use App\Service\ApplicationInfo\Output\SymfonyOutput; |
| 10 | use App\Service\ApplicationInfo\Symfony; |
| 11 | use Symfony\Component\Finder\Finder; |
| 12 | use Symfony\Component\HttpFoundation\Request; |
| 13 | use Symfony\Component\HttpFoundation\Response; |
| 14 | use Symfony\Component\Routing\Attribute\Route; |
| 15 | |
| 16 | #[Route('/admin')] |
| 17 | class AdminController extends BaseAdminController |
| 18 | { |
| 19 | #[Route('', name: 'admin_page')] |
| 20 | public function index(Request $request, Application $application): Response |
| 21 | { |
| 22 | $this->logger->debug('Debug page'); |
| 23 | $this->denyAccessUnlessGranted(Action::ADMIN_PAGE); |
| 24 | $roles = Role::getRoles(); |
| 25 | foreach ($roles as $key => $role) { |
| 26 | if (!$this->isGranted($role)) { |
| 27 | unset($roles[$key]); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return $this->render( |
| 32 | 'admin/index.html.twig', |
| 33 | [ |
| 34 | 'phpVersion' => phpversion(), |
| 35 | 'symfonyVersion' => \Symfony\Component\HttpKernel\Kernel::VERSION, |
| 36 | 'httpGinaroles' => $request->server->get('HTTP_GINAROLES', 'pas défini'), |
| 37 | 'rolesHeritage' => $roles, |
| 38 | 'user' => $application->getUser(), |
| 39 | ] |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Display log. |
| 45 | */ |
| 46 | #[Route('/log/{filename}', name: 'admin_log', methods: ['GET'])] |
| 47 | public function log(Request $request, Kernel $kernel, ?string $filename = null): Response |
| 48 | { |
| 49 | $this->logger->info('Debug log'); |
| 50 | $this->denyAccessUnlessGranted(Action::ADMIN_LOG); |
| 51 | $finder = new Finder(); |
| 52 | $finder->files()->in($kernel->getLogDir()); |
| 53 | if ($filename) { |
| 54 | $filename = preg_replace('/[^_.\\-A-Za-z0-9]+/', '', $filename); |
| 55 | if ($filename) { |
| 56 | $files = $finder->name($filename); |
| 57 | if (0 !== $files->count()) { |
| 58 | $array = iterator_to_array($files); |
| 59 | $file = reset($array); |
| 60 | if ($file) { |
| 61 | $this->logger->info('Debug affichage du log ' . $file->getFilename()); |
| 62 | |
| 63 | return $this->render('admin/log/content.html.twig', ['file' => $file]); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | $finder->name('*'); |
| 68 | } |
| 69 | $finder->sortByModifiedTime(); |
| 70 | |
| 71 | return $this->render('admin/log/list.html.twig', ['finder' => $finder]); |
| 72 | } |
| 73 | |
| 74 | #[Route('/applicationInfo', name: 'applicationInfo')] |
| 75 | public function applicationInfo(Request $request): Response |
| 76 | { |
| 77 | $this->logger->info('applicationInfo'); |
| 78 | $this->denyAccessUnlessGranted(Action::ADMIN_PAGE); |
| 79 | |
| 80 | $symfonyOutput = new SymfonyOutput(); |
| 81 | $app = new Symfony($symfonyOutput); |
| 82 | unset($app); |
| 83 | |
| 84 | return $this->render( |
| 85 | 'admin/application_info.html.twig', |
| 86 | ['html' => $symfonyOutput->getHtml()] |
| 87 | ); |
| 88 | } |
| 89 | } |