Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eca2f8e

Browse filesBrowse files
Nyholmnicolas-grekas
authored andcommitted
Moved PhpExtractor and PhpStringTokenParser to Translation component
1 parent a442e37 commit eca2f8e
Copy full SHA for eca2f8e

File tree

Expand file treeCollapse file tree

13 files changed

+585
-374
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+585
-374
lines changed

‎UPGRADE-3.4.md

Copy file name to clipboardExpand all lines: UPGRADE-3.4.md
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ FrameworkBundle
204204
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
205205
and `YamlLintCommand` classes have been marked as final
206206

207+
* The `Symfony\Bundle\FrameworkBundle\Translation\PhpExtractor`
208+
class has been deprecated and will be removed in 4.0. Use the
209+
`Symfony\Component\Translation\Extractor\PhpExtractor` class instead.
210+
211+
* The `Symfony\Bundle\FrameworkBundle\Translation\PhpStringTokenParser`
212+
class has been deprecated and will be removed in 4.0. Use the
213+
`Symfony\Component\Translation\Extractor\PhpStringTokenParser` class instead.
214+
207215
HttpFoundation
208216
--------------
209217

@@ -280,8 +288,8 @@ Profiler
280288
Security
281289
--------
282290

283-
* Deprecated the HTTP digest authentication: `NonceExpiredException`,
284-
`DigestAuthenticationListener` and `DigestAuthenticationEntryPoint` will be
291+
* Deprecated the HTTP digest authentication: `NonceExpiredException`,
292+
`DigestAuthenticationListener` and `DigestAuthenticationEntryPoint` will be
285293
removed in 4.0. Use another authentication system like `http_basic` instead.
286294

287295
SecurityBundle
@@ -305,7 +313,7 @@ SecurityBundle
305313
* Added `logout_on_user_change` to the firewall options. This config item will
306314
trigger a logout when the user has changed. Should be set to true to avoid
307315
deprecations in the configuration.
308-
316+
309317
* Deprecated the HTTP digest authentication: `HttpDigestFactory` will be removed in 4.0.
310318
Use another authentication system like `http_basic` instead.
311319

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ FrameworkBundle
494494
`Symfony\Component\Translation\TranslatorInterface` as
495495
first argument.
496496

497+
* The `Symfony\Bundle\FrameworkBundle\Translation\PhpExtractor`
498+
class has been deprecated and will be removed in 4.0. Use the
499+
`Symfony\Component\Translation\Extractor\PhpExtractor` class instead.
500+
501+
* The `Symfony\Bundle\FrameworkBundle\Translation\PhpStringTokenParser`
502+
class has been deprecated and will be removed in 4.0. Use the
503+
`Symfony\Component\Translation\Extractor\PhpStringTokenParser` class instead.
504+
497505
HttpFoundation
498506
--------------
499507

@@ -525,9 +533,9 @@ HttpFoundation
525533
* The ability to check only for cacheable HTTP methods using `Request::isMethodSafe()` is
526534
not supported anymore, use `Request::isMethodCacheable()` instead.
527535

528-
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`,
536+
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`,
529537
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy`,
530-
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` and
538+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` and
531539
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy` classes have been removed.
532540

533541
* `NativeSessionStorage::setSaveHandler()` now requires an instance of `\SessionHandlerInterface` as argument.
@@ -682,7 +690,7 @@ SecurityBundle
682690

683691
* The firewall option `logout_on_user_change` is now always true, which will
684692
trigger a logout if the user changes between requests.
685-
693+
686694
* Removed the HTTP digest authentication system. The `HttpDigestFactory` class
687695
has been removed. Use another authentication system like `http_basic` instead.
688696

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ CHANGELOG
105105
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead
106106
* Deprecated `ConstraintValidatorFactory`, use
107107
`Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
108+
* Deprecated `PhpStringTokenParser`, use
109+
`Symfony\Component\Translation\Extractor\PhpStringTokenParser` instead.
110+
* Deprecated `PhpExtractor`, use
111+
`Symfony\Component\Translation\Extractor\PhpExtractor` instead.
108112

109113
3.2.0
110114
-----

‎src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Symfony\Bundle\FrameworkBundle\Translation\PhpExtractor;
1616
use Symfony\Component\Translation\MessageCatalogue;
1717

18+
/**
19+
* @group legacy
20+
*/
1821
class PhpExtractorTest extends TestCase
1922
{
2023
/**

‎src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php
+5-242Lines changed: 5 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -11,250 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Translation;
1313

14-
use Symfony\Component\Finder\Finder;
15-
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
16-
use Symfony\Component\Translation\MessageCatalogue;
17-
use Symfony\Component\Translation\Extractor\ExtractorInterface;
14+
use Symfony\Component\Translation\Extractor\PhpExtractor as NewPhpExtractor;
15+
16+
@trigger_error(sprintf('The class "%s" is deprecated since version 3.4 and will be removed in 4.0. Use "%s" instead. ', PhpExtractor::class, NewPhpExtractor::class), E_USER_DEPRECATED);
1817

1918
/**
20-
* PhpExtractor extracts translation messages from a PHP template.
21-
*
22-
* @author Michel Salib <michelsalib@hotmail.com>
19+
* @deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\Translation\Extractor\PhpExtractor instead
2320
*/
24-
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
21+
class PhpExtractor extends NewPhpExtractor
2522
{
26-
const MESSAGE_TOKEN = 300;
27-
const METHOD_ARGUMENTS_TOKEN = 1000;
28-
const DOMAIN_TOKEN = 1001;
29-
30-
/**
31-
* Prefix for new found message.
32-
*
33-
* @var string
34-
*/
35-
private $prefix = '';
36-
37-
/**
38-
* The sequence that captures translation messages.
39-
*
40-
* @var array
41-
*/
42-
protected $sequences = array(
43-
array(
44-
'->',
45-
'trans',
46-
'(',
47-
self::MESSAGE_TOKEN,
48-
',',
49-
self::METHOD_ARGUMENTS_TOKEN,
50-
',',
51-
self::DOMAIN_TOKEN,
52-
),
53-
array(
54-
'->',
55-
'transChoice',
56-
'(',
57-
self::MESSAGE_TOKEN,
58-
',',
59-
self::METHOD_ARGUMENTS_TOKEN,
60-
',',
61-
self::METHOD_ARGUMENTS_TOKEN,
62-
',',
63-
self::DOMAIN_TOKEN,
64-
),
65-
array(
66-
'->',
67-
'trans',
68-
'(',
69-
self::MESSAGE_TOKEN,
70-
),
71-
array(
72-
'->',
73-
'transChoice',
74-
'(',
75-
self::MESSAGE_TOKEN,
76-
),
77-
);
78-
79-
/**
80-
* {@inheritdoc}
81-
*/
82-
public function extract($resource, MessageCatalogue $catalog)
83-
{
84-
$files = $this->extractFiles($resource);
85-
foreach ($files as $file) {
86-
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
87-
88-
if (\PHP_VERSION_ID >= 70000) {
89-
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
90-
gc_mem_caches();
91-
}
92-
}
93-
}
94-
95-
/**
96-
* {@inheritdoc}
97-
*/
98-
public function setPrefix($prefix)
99-
{
100-
$this->prefix = $prefix;
101-
}
102-
103-
/**
104-
* Normalizes a token.
105-
*
106-
* @param mixed $token
107-
*
108-
* @return string
109-
*/
110-
protected function normalizeToken($token)
111-
{
112-
if (isset($token[1]) && 'b"' !== $token) {
113-
return $token[1];
114-
}
115-
116-
return $token;
117-
}
118-
119-
/**
120-
* Seeks to a non-whitespace token.
121-
*/
122-
private function seekToNextRelevantToken(\Iterator $tokenIterator)
123-
{
124-
for (; $tokenIterator->valid(); $tokenIterator->next()) {
125-
$t = $tokenIterator->current();
126-
if (T_WHITESPACE !== $t[0]) {
127-
break;
128-
}
129-
}
130-
}
131-
132-
private function skipMethodArgument(\Iterator $tokenIterator)
133-
{
134-
$openBraces = 0;
135-
136-
for (; $tokenIterator->valid(); $tokenIterator->next()) {
137-
$t = $tokenIterator->current();
138-
139-
if ('[' === $t[0] || '(' === $t[0]) {
140-
++$openBraces;
141-
}
142-
143-
if (']' === $t[0] || ')' === $t[0]) {
144-
--$openBraces;
145-
}
146-
147-
if ((0 === $openBraces && ',' === $t[0]) || (-1 === $openBraces && ')' === $t[0])) {
148-
break;
149-
}
150-
}
151-
}
152-
153-
/**
154-
* Extracts the message from the iterator while the tokens
155-
* match allowed message tokens.
156-
*/
157-
private function getValue(\Iterator $tokenIterator)
158-
{
159-
$message = '';
160-
$docToken = '';
161-
162-
for (; $tokenIterator->valid(); $tokenIterator->next()) {
163-
$t = $tokenIterator->current();
164-
if (!isset($t[1])) {
165-
break;
166-
}
167-
168-
switch ($t[0]) {
169-
case T_START_HEREDOC:
170-
$docToken = $t[1];
171-
break;
172-
case T_ENCAPSED_AND_WHITESPACE:
173-
case T_CONSTANT_ENCAPSED_STRING:
174-
$message .= $t[1];
175-
break;
176-
case T_END_HEREDOC:
177-
return PhpStringTokenParser::parseDocString($docToken, $message);
178-
default:
179-
break 2;
180-
}
181-
}
182-
183-
if ($message) {
184-
$message = PhpStringTokenParser::parse($message);
185-
}
186-
187-
return $message;
188-
}
189-
190-
/**
191-
* Extracts trans message from PHP tokens.
192-
*
193-
* @param array $tokens
194-
* @param MessageCatalogue $catalog
195-
*/
196-
protected function parseTokens($tokens, MessageCatalogue $catalog)
197-
{
198-
$tokenIterator = new \ArrayIterator($tokens);
199-
200-
for ($key = 0; $key < $tokenIterator->count(); ++$key) {
201-
foreach ($this->sequences as $sequence) {
202-
$message = '';
203-
$domain = 'messages';
204-
$tokenIterator->seek($key);
205-
206-
foreach ($sequence as $sequenceKey => $item) {
207-
$this->seekToNextRelevantToken($tokenIterator);
208-
209-
if ($this->normalizeToken($tokenIterator->current()) === $item) {
210-
$tokenIterator->next();
211-
continue;
212-
} elseif (self::MESSAGE_TOKEN === $item) {
213-
$message = $this->getValue($tokenIterator);
214-
215-
if (count($sequence) === ($sequenceKey + 1)) {
216-
break;
217-
}
218-
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
219-
$this->skipMethodArgument($tokenIterator);
220-
} elseif (self::DOMAIN_TOKEN === $item) {
221-
$domain = $this->getValue($tokenIterator);
222-
223-
break;
224-
} else {
225-
break;
226-
}
227-
}
228-
229-
if ($message) {
230-
$catalog->set($message, $this->prefix.$message, $domain);
231-
break;
232-
}
233-
}
234-
}
235-
}
236-
237-
/**
238-
* @param string $file
239-
*
240-
* @return bool
241-
*
242-
* @throws \InvalidArgumentException
243-
*/
244-
protected function canBeExtracted($file)
245-
{
246-
return $this->isFile($file) && 'php' === pathinfo($file, PATHINFO_EXTENSION);
247-
}
248-
249-
/**
250-
* @param string|array $directory
251-
*
252-
* @return array
253-
*/
254-
protected function extractFromDirectory($directory)
255-
{
256-
$finder = new Finder();
257-
258-
return $finder->files()->name('*.php')->in($directory);
259-
}
26023
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.