10000 Move command to TwigBundle and apply review suggestions · symfony/symfony@8b04176 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b04176

Browse files
committed
Move command to TwigBundle and apply review suggestions
1 parent dcbbf77 commit 8b04176

File tree

17 files changed

+265
-245
lines changed

17 files changed

+265
-245
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CHANGELOG
3030
* Add support for configuring multiple serializer instances via the configuration
3131
* Add support for `SYMFONY_TRUSTED_PROXIES`, `SYMFONY_TRUSTED_HEADERS`, `SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER` and `SYMFONY_TRUSTED_HOSTS` env vars
3232
* Add `--no-fill` option to `translation:extract` command
33-
* Add `error:dump-pages` command
3433

3534
7.1
3635
---

src/Symfony/Bundle/FrameworkBundle/Command/ErrorDumpPagesCommand.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public function load(array $configs, ContainerBuilder $container): void
236236
$loader->load('web.php');
237237
$loader->load('services.php');
238238
$loader->load('fragment_renderer.php');
239-
$loader->load('error.php');
240239
$loader->load('error_renderer.php');
241240

242241
if (!ContainerBuilder::willBeAvailable('symfony/clock', ClockInterface::class, ['symfony/framework-bundle'])) {

src/Symfony/Bundle/FrameworkBundle/Error/PagesDumper.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Symfony\Bundle\FrameworkBundle\Command\ContainerDebugCommand;
2626
use Symfony\Bundle\FrameworkBundle\Command\ContainerLintCommand;
2727
use Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand;
28-
use Symfony\Bundle\FrameworkBundle\Command\ErrorDumpPagesCommand;
2928
use Symfony\Bundle\FrameworkBundle\Command\EventDispatcherDebugCommand;
3029
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
3130
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
@@ -152,12 +151,6 @@
152151
])
153152
->tag('console.command')
154153

155-
->set('console.command.error_dump_pages', ErrorDumpPagesCommand::class)
156-
->args([
157-
service('error.pages_dumper'),
158-
])
159-
->tag('console.command')
160-
161154
->set('console.command.event_dispatcher_debug', EventDispatcherDebugCommand::class)
162155
->args([
163156
tagged_locator('event_dispatcher.dispatcher', 'name'),

src/Symfony/Bundle/FrameworkBundle/Resources/config/error.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/Error/PagesDumperTest.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"symfony/uid": "^6.4|^7.0",
7474
"symfony/web-link": "^6.4|^7.0",
7575
"symfony/webhook": "^7.2",
76-
"symfony/webpack-encore-bundle": "^1.0|^2.0",
7776
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
7877
"twig/twig": "^3.12"
7978
},

src/Symfony/Bundle/TwigBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add `error:dump` command
8+
49
7.1
510
---
611

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\TwigBundle\Command;
13+
14+
use Symfony\Bridge\Twig\ErrorRenderer\TwigErrorRenderer;
15+
use Symfony\Component\Console\Attribute\AsCommand;
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Symfony\Component\Filesystem\Filesystem;
21+
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\HttpKernel\Exception\HttpException;
23+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
24+
25+
/**
26+
* Dump error pages to plain HTML files that can be directly served by a web server.
27+
*
28+
* @author Loïck Piera <pyrech@gmail.com>
29+
*
30+
* @final
31+
*/
32+
#[AsCommand(
33+
name: 'error:dump',
34+
description: 'Dump error pages to plain HTML files that can be directly served by a web server',
35+
)]
36+
class ErrorDumpCommand extends Command
37+
{
38+
public function __construct(
39+
private readonly string $path,
40+
/** @var list<int> */
41+
private readonly array $statusCodes,
42+
private readonly Filesystem $filesystem,
43+
private readonly TwigErrorRenderer $twigErrorRenderer,
44+
private readonly ?EntrypointLookupInterface $entrypointLookup = null,
45+
) {
46+
parent::__construct();
47+
}
48+
49+
protected function execute(InputInterface $input, OutputInterface $output): int
50+
{
51+
$io = new SymfonyStyle($input, $output);
52+
$io->title('Dumping error pages');
53+
54+
$this->dump();
55+
$io->success(\sprintf('Error pages have been dumped in "%s".', $this->path));
56+
57+
return Command::SUCCESS;
58+
}
59+
60+
public function dump(): void
61+
{
62+
$statusCodes = $this->statusCodes;
63+
64+
if (!$statusCodes) {
65+
$statusCodes = array_filter(
66+
array_keys(Response::$statusTexts),
67+
fn ($statusCode) => $statusCode >= 400
68+
);
69+
}
70+
71+
$this->filesystem->remove($this->path);
72+
73+
foreach ($statusCodes as $statusCode) {
74+
// Avoid assets to be included only on the first dumped page
75+
$this->entrypointLookup?->reset();
76+
77+
$this->filesystem->dumpFile(
78+
$this->path.\DIRECTORY_SEPARATOR.$statusCode.'.html',
79+
$this->twigErrorRenderer->render(new HttpException((int) $statusCode))->getAsString()
80+
);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)
0