Skip to content

Commit e8c547e

Browse files
authored
Merge branch 'php-translation:master' into handle-icu-domain
2 parents 04a1f1e + b946f06 commit e8c547e

29 files changed

+440
-312
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php: [ '7.2', '7.3', '7.4', '8.0' ]
13+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ]
1414
strategy: [ 'highest' ]
1515
sf_version: ['']
1616
include:
@@ -43,4 +43,3 @@ jobs:
4343

4444
- name: Run tests
4545
run: ./vendor/bin/simple-phpunit
46-

Changelog.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 0.12.4
6+
7+
### Fixed
8+
9+
- Fix extractor parameters #438
10+
- Make Profiler service an optional argument for SymfonyProfilerController #440
11+
- Update ExtractCommand.php #435
12+
- Fix tests on Symfony 5.3 #443
13+
- Suppress getMasterRequest() deprecation message #444
14+
- Suppress deprecations on deprecating legacy services #445
15+
- Fix PHPUnit deprecations #447
16+
- Fix broken tests #458
17+
- Register visitor tag also for TranslateAnnotationVisitor and Knp visitors #451
18+
19+
### Removed
20+
21+
- Drop SensioLabs (Symfony) insight badge #441
22+
523
## 0.12.3
624

725
### Fixed

Command/ExtractCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
140140
private function getConfiguredFinder(Configuration $config): Finder
141141
{
142142
$finder = new Finder();
143+
$finder->sortByName();
143144
$finder->in($config->getDirs());
144145

145146
foreach ($config->getExcludedDirs() as $exclude) {

Controller/EditInPlaceController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Translation\Bundle\Controller;
1313

14-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1514
use Symfony\Component\HttpFoundation\Request;
1615
use Symfony\Component\HttpFoundation\Response;
1716
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -25,7 +24,7 @@
2524
/**
2625
* @author Damien Alexandre <dalexandre@jolicode.com>
2726
*/
28-
class EditInPlaceController extends AbstractController
27+
class EditInPlaceController
2928
{
3029
private $storageManager;
3130
private $cacheClearer;

Controller/SymfonyProfilerController.php

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,40 @@
1111

1212
namespace Translation\Bundle\Controller;
1313

14-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
14+
use Symfony\Component\HttpFoundation\RedirectResponse;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1718
use Symfony\Component\HttpKernel\Profiler\Profiler;
19+
use Symfony\Component\Routing\Exception\RouteNotFoundException;
20+
use Symfony\Component\Routing\RouterInterface;
1821
use Symfony\Component\Translation\DataCollector\TranslationDataCollector;
1922
use Symfony\Component\Translation\DataCollectorTranslator;
2023
use Symfony\Component\VarDumper\Cloner\Data;
2124
use Translation\Bundle\Model\SfProfilerMessage;
2225
use Translation\Bundle\Service\StorageService;
2326
use Translation\Common\Model\MessageInterface;
27+
use Twig\Environment;
2428

2529
/**
2630
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
2731
*/
28-
class SymfonyProfilerController extends AbstractController
32+
class SymfonyProfilerController
2933
{
30-
private $storage;
34+
/**
35+
* @var Profiler An optional dependency
36+
*/
3137
private $profiler;
38+
private $storage;
39+
private $twig;
40+
private $router;
3241
private $isToolbarAllowEdit;
3342

34-
public function __construct(StorageService $storage, Profiler $profiler, bool $isToolbarAllowEdit)
43+
public function __construct(StorageService $storage, Environment $twig, RouterInterface $router, bool $isToolbarAllowEdit)
3544
{
3645
$this->storage = $storage;
37-
$this->profiler = $profiler;
46+
$this->twig = $twig;
47+
$this->router = $router;
3848
$this->isToolbarAllowEdit = $isToolbarAllowEdit;
3949
}
4050

@@ -45,18 +55,20 @@ public function editAction(Request $request, string $token): Response
4555
}
4656

4757
if (!$request->isXmlHttpRequest()) {
48-
return $this->redirectToRoute('_profiler', ['token' => $token]);
58+
return $this->redirectToProfiler($token);
4959
}
5060

5161
$message = $this->getMessage($request, $token);
5262

5363
if ($request->isMethod('GET')) {
5464
$translation = $this->storage->syncAndFetchMessage($message->getLocale(), $message->getDomain(), $message->getKey());
5565

56-
return $this->render('@Translation/SymfonyProfiler/edit.html.twig', [
66+
$content = $this->twig->render('@Translation/SymfonyProfiler/edit.html.twig', [
5767
'message' => $translation,
5868
'key' => $request->query->get('message_id'),
5969
]);
70+
71+
return new Response($content);
6072
}
6173

6274
//Assert: This is a POST request
@@ -69,7 +81,7 @@ public function editAction(Request $request, string $token): Response
6981
public function syncAction(Request $request, string $token): Response
7082
{
7183
if (!$request->isXmlHttpRequest()) {
72-
return $this->redirectToRoute('_profiler', ['token' => $token]);
84+
return $this->redirectToProfiler($token);
7385
}
7486

7587
$sfMessage = $this->getMessage($request, $token);
@@ -88,7 +100,7 @@ public function syncAction(Request $request, string $token): Response
88100
public function syncAllAction(Request $request, string $token): Response
89101
{
90102
if (!$request->isXmlHttpRequest()) {
91-
return $this->redirectToRoute('_profiler', ['token' => $token]);
103+
return $this->redirectToProfiler($token);
92104
}
93105

94106
$this->storage->sync();
@@ -104,7 +116,7 @@ public function syncAllAction(Request $request, string $token): Response
104116
public function createAssetsAction(Request $request, string $token): Response
105117
{
106118
if (!$request->isXmlHttpRequest()) {
107-
return $this->redirectToRoute('_profiler', ['token' => $token]);
119+
return $this->redirectToProfiler($token);
108120
}
109121

110122
$messages = $this->getSelectedMessages($request, $token);
@@ -123,20 +135,20 @@ public function createAssetsAction(Request $request, string $token): Response
123135

124136
private function getMessage(Request $request, string $token): SfProfilerMessage
125137
{
126-
$this->profiler->disable();
138+
$this->getProfiler()->disable();
127139

128140
$messageId = (string) $request->request->get('message_id', $request->query->get('message_id'));
129141

130142
$collectorMessages = $this->getMessages($token);
131143

132144
if (!isset($collectorMessages[$messageId])) {
133-
throw $this->createNotFoundException(\sprintf('No message with key "%s" was found.', $messageId));
145+
throw new NotFoundHttpException(\sprintf('No message with key "%s" was found.', $messageId));
134146
}
135147
$message = SfProfilerMessage::create($collectorMessages[$messageId]);
136148

137149
if (DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK === $message->getState()) {
138150
/** @var \Symfony\Component\HttpKernel\DataCollector\RequestDataCollector */
139-
$requestCollector = $this->profiler->loadProfile($token)->getCollector('request');
151+
$requestCollector = $this->getProfiler()->loadProfile($token)->getCollector('request');
140152

141153
$message
142154
->setLocale($requestCollector->getLocale())
@@ -152,7 +164,7 @@ private function getMessage(Request $request, string $token): SfProfilerMessage
152164
*/
153165
protected function getSelectedMessages(Request $request, string $token): array
154166
{
155-
$this->profiler->disable();
167+
$this->getProfiler()->disable();
156168

157169
/** @var string[] $selected */
158170
$selected = (array) $request->request->get('selected');
@@ -172,13 +184,13 @@ protected function getSelectedMessages(Request $request, string $token): array
172184

173185
private function getMessages(string $token, string $profileName = 'translation'): array
174186
{
175-
$profile = $this->profiler->loadProfile($token);
187+
$profile = $this->getProfiler()->loadProfile($token);
176188

177189
if (null === $dataCollector = $profile->getCollector($profileName)) {
178-
throw $this->createNotFoundException("No collector with name \"$profileName\" was found.");
190+
throw new NotFoundHttpException("No collector with name \"$profileName\" was found.");
179191
}
180192
if (!$dataCollector instanceof TranslationDataCollector) {
181-
throw $this->createNotFoundException("Collector with name \"$profileName\" is not an instance of TranslationDataCollector.");
193+
throw new NotFoundHttpException("Collector with name \"$profileName\" is not an instance of TranslationDataCollector.");
182194
}
183195

184196
$messages = $dataCollector->getMessages();
@@ -189,4 +201,29 @@ private function getMessages(string $token, string $profileName = 'translation')
189201

190202
return $messages;
191203
}
204+
205+
public function setProfiler(Profiler $profiler): void
206+
{
207+
$this->profiler = $profiler;
208+
}
209+
210+
private function getProfiler(): Profiler
211+
{
212+
if (!$this->profiler) {
213+
throw new \Exception('The "profiler" service is missing. Please, run "composer require symfony/web-profiler-bundle" first to use this feature.');
214+
}
215+
216+
return $this->profiler;
217+
}
218+
219+
private function redirectToProfiler(string $token): RedirectResponse
220+
{
221+
try {
222+
$targetUrl = $this->router->generate('_profiler', ['token' => $token]);
223+
224+
return new RedirectResponse($targetUrl);
225+
} catch (RouteNotFoundException $e) {
226+
throw new \Exception('Route to profiler page not found. Please, run "composer require symfony/web-profiler-bundle" first to use this feature.');
227+
}
228+
}
192229
}

Controller/WebUIController.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Translation\Bundle\Controller;
1313

14-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1514
use Symfony\Component\HttpFoundation\Request;
1615
use Symfony\Component\HttpFoundation\Response;
1716
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -29,17 +28,19 @@
2928
use Translation\Common\Exception\StorageException;
3029
use Translation\Common\Model\Message;
3130
use Translation\Common\Model\MessageInterface;
31+
use Twig\Environment;
3232

3333
/**
3434
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
3535
*/
36-
class WebUIController extends AbstractController
36+
class WebUIController
3737
{
3838
private $configurationManager;
3939
private $catalogueFetcher;
4040
private $catalogueManager;
4141
private $storageManager;
4242
private $validator;
43+
private $twig;
4344
private $locales;
4445
private $isWebUIEnabled;
4546
private $isWebUIAllowCreate;
@@ -52,6 +53,7 @@ public function __construct(
5253
CatalogueManager $catalogueManager,
5354
StorageManager $storageManager,
5455
ValidatorInterface $validator,
56+
Environment $twig,
5557
array $locales,
5658
bool $isWebUIEnabled,
5759
bool $isWebUIAllowCreate,
@@ -63,6 +65,7 @@ public function __construct(
6365
$this->catalogueManager = $catalogueManager;
6466
$this->storageManager = $storageManager;
6567
$this->validator = $validator;
68+
$this->twig = $twig;
6669
$this->locales = $locales;
6770
$this->isWebUIEnabled = $isWebUIEnabled;
6871
$this->isWebUIAllowCreate = $isWebUIAllowCreate;
@@ -107,7 +110,7 @@ public function indexAction(?string $configName = null): Response
107110
}
108111
}
109112

110-
return $this->render('@Translation/WebUI/index.html.twig', [
113+
$content = $this->twig->render('@Translation/WebUI/index.html.twig', [
111114
'catalogues' => $catalogues,
112115
'catalogueSize' => $catalogueSize,
113116
'maxDomainSize' => $maxDomainSize,
@@ -116,6 +119,8 @@ public function indexAction(?string $configName = null): Response
116119
'configName' => $config->getName(),
117120
'configNames' => $this->configurationManager->getNames(),
118121
]);
122+
123+
return new Response($content);
119124
}
120125

121126
/**
@@ -137,7 +142,7 @@ public function showAction(string $configName, string $locale, string $domain):
137142
return \strcmp($a->getKey(), $b->getKey());
138143
});
139144

140-
return $this->render('@Translation/WebUI/show.html.twig', [
145+
$content = $this->twig->render('@Translation/WebUI/show.html.twig', [
141146
'messages' => $messages,
142147
'domains' => $this->catalogueManager->getDomains(),
143148
'currentDomain' => $domain,
@@ -149,6 +154,8 @@ public function showAction(string $configName, string $locale, string $domain):
149154
'allow_delete' => $this->isWebUIAllowDelete,
150155
'file_base_path' => $this->fileBasePath,
151156
]);
157+
158+
return new Response($content);
152159
}
153160

154161
public function createAction(Request $request, string $configName, string $locale, string $domain): Response
@@ -177,9 +184,11 @@ public function createAction(Request $request, string $configName, string $local
177184
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
178185
}
179186

180-
return $this->render('@Translation/WebUI/create.html.twig', [
187+
$content = $this->twig->render('@Translation/WebUI/create.html.twig', [
181188
'message' => $message,
182189
]);
190+
191+
return new Response($content);
183192
}
184193

185194
public function editAction(Request $request, string $configName, string $locale, string $domain): Response

DependencyInjection/TranslationExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public function load(array $configs, ContainerBuilder $container): void
4747
$configuration = new Configuration($container);
4848
$config = $this->processConfiguration($configuration, $configs);
4949
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
50+
$legacyLoader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/legacy'));
5051

5152
$loader->load('services.yaml');
53+
$legacyLoader->load('services.php');
5254
$loader->load('extractors.yaml');
55+
$legacyLoader->load('extractors.php');
5356

5457
// Add major version to extractor
5558
$container->getDefinition(FormTypeChoices::class)
@@ -74,6 +77,7 @@ public function load(array $configs, ContainerBuilder $container): void
7477

7578
if ($config['edit_in_place']['enabled']) {
7679
$loader->load('edit_in_place.yaml');
80+
$legacyLoader->load('edit_in_place.php');
7781
$this->enableEditInPlace($container, $config);
7882
}
7983

@@ -89,6 +93,7 @@ public function load(array $configs, ContainerBuilder $container): void
8993
}
9094

9195
$loader->load('console.yaml');
96+
$legacyLoader->load('console.php');
9297
}
9398

9499
/**

0 commit comments

Comments
 (0)