updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -21,21 +21,21 @@ use Symfony\Component\Translation\Exception\InvalidArgumentException;
abstract class AbstractFileExtractor
{
/**
* @param string|array $resource Files, a file or a directory
* @param string|iterable $resource Files, a file or a directory
*
* @return array
* @return iterable
*/
protected function extractFiles($resource)
{
if (\is_array($resource) || $resource instanceof \Traversable) {
$files = array();
if (is_iterable($resource)) {
$files = [];
foreach ($resource as $file) {
if ($this->canBeExtracted($file)) {
$files[] = $this->toSplFileInfo($file);
}
}
} elseif (is_file($resource)) {
$files = $this->canBeExtracted($resource) ? array($this->toSplFileInfo($resource)) : array();
$files = $this->canBeExtracted($resource) ? [$this->toSplFileInfo($resource)] : [];
} else {
$files = $this->extractFromDirectory($resource);
}
@@ -74,7 +74,7 @@ abstract class AbstractFileExtractor
/**
* @param string|array $resource Files, a file or a directory
*
* @return array files to be extracted
* @return iterable files to be extracted
*/
abstract protected function extractFromDirectory($resource);
}

View File

@@ -25,13 +25,12 @@ class ChainExtractor implements ExtractorInterface
*
* @var ExtractorInterface[]
*/
private $extractors = array();
private $extractors = [];
/**
* Adds a loader to the translation extractor.
*
* @param string $format The format of the loader
* @param ExtractorInterface $extractor The loader
* @param string $format The format of the loader
*/
public function addExtractor($format, ExtractorInterface $extractor)
{

View File

@@ -24,8 +24,7 @@ interface ExtractorInterface
/**
* Extracts translation messages from files, a file or a directory to the catalogue.
*
* @param string|array $resource Files, a file or a directory
* @param MessageCatalogue $catalogue The catalogue
* @param string|iterable<string> $resource Files, a file or a directory
*/
public function extract($resource, MessageCatalogue $catalogue);

View File

@@ -21,9 +21,9 @@ use Symfony\Component\Translation\MessageCatalogue;
*/
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
const MESSAGE_TOKEN = 300;
const METHOD_ARGUMENTS_TOKEN = 1000;
const DOMAIN_TOKEN = 1001;
public const MESSAGE_TOKEN = 300;
public const METHOD_ARGUMENTS_TOKEN = 1000;
public const DOMAIN_TOKEN = 1001;
/**
* Prefix for new found message.
@@ -37,8 +37,8 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
*
* @var array
*/
protected $sequences = array(
array(
protected $sequences = [
[
'->',
'trans',
'(',
@@ -47,8 +47,8 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
self::METHOD_ARGUMENTS_TOKEN,
',',
self::DOMAIN_TOKEN,
),
array(
],
[
'->',
'transChoice',
'(',
@@ -59,20 +59,20 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
self::METHOD_ARGUMENTS_TOKEN,
',',
self::DOMAIN_TOKEN,
),
array(
],
[
'->',
'trans',
'(',
self::MESSAGE_TOKEN,
),
array(
],
[
'->',
'transChoice',
'(',
self::MESSAGE_TOKEN,
),
);
],
];
/**
* {@inheritdoc}
@@ -81,9 +81,8 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
$files = $this->extractFiles($resource);
foreach ($files as $file) {
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog, $file);
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
}
@@ -101,7 +100,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
*
* @param mixed $token
*
* @return string
* @return string|null
*/
protected function normalizeToken($token)
{
@@ -119,7 +118,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
for (; $tokenIterator->valid(); $tokenIterator->next()) {
$t = $tokenIterator->current();
if (T_WHITESPACE !== $t[0]) {
if (\T_WHITESPACE !== $t[0]) {
break;
}
}
@@ -154,43 +153,71 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
$message = '';
$docToken = '';
$docPart = '';
for (; $tokenIterator->valid(); $tokenIterator->next()) {
$t = $tokenIterator->current();
if ('.' === $t) {
// Concatenate with next token
continue;
}
if (!isset($t[1])) {
break;
}
switch ($t[0]) {
case T_START_HEREDOC:
case \T_START_HEREDOC:
$docToken = $t[1];
break;
case T_ENCAPSED_AND_WHITESPACE:
case T_CONSTANT_ENCAPSED_STRING:
$message .= $t[1];
case \T_ENCAPSED_AND_WHITESPACE:
case \T_CONSTANT_ENCAPSED_STRING:
if ('' === $docToken) {
$message .= PhpStringTokenParser::parse($t[1]);
} else {
$docPart = $t[1];
}
break;
case \T_END_HEREDOC:
if ($indentation = strspn($t[1], ' ')) {
$docPartWithLineBreaks = $docPart;
$docPart = '';
foreach (preg_split('~(\r\n|\n|\r)~', $docPartWithLineBreaks, -1, \PREG_SPLIT_DELIM_CAPTURE) as $str) {
if (\in_array($str, ["\r\n", "\n", "\r"], true)) {
$docPart .= $str;
} else {
$docPart .= substr($str, $indentation);
}
}
}
$message .= PhpStringTokenParser::parseDocString($docToken, $docPart);
$docToken = '';
$docPart = '';
break;
case \T_WHITESPACE:
break;
case T_END_HEREDOC:
return PhpStringTokenParser::parseDocString($docToken, $message);
default:
break 2;
}
}
if ($message) {
$message = PhpStringTokenParser::parse($message);
}
return $message;
}
/**
* Extracts trans message from PHP tokens.
*
* @param array $tokens
* @param MessageCatalogue $catalog
* @param array $tokens
* @param string $filename
*/
protected function parseTokens($tokens, MessageCatalogue $catalog)
protected function parseTokens($tokens, MessageCatalogue $catalog/* , string $filename */)
{
if (\func_num_args() < 3 && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
@trigger_error(sprintf('The "%s()" method will have a new "string $filename" argument in version 5.0, not defining it is deprecated since Symfony 4.3.', __METHOD__), \E_USER_DEPRECATED);
}
$filename = 2 < \func_num_args() ? func_get_arg(2) : '';
$tokenIterator = new \ArrayIterator($tokens);
for ($key = 0; $key < $tokenIterator->count(); ++$key) {
@@ -214,7 +241,10 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
$this->skipMethodArgument($tokenIterator);
} elseif (self::DOMAIN_TOKEN === $item) {
$domain = $this->getValue($tokenIterator);
$domainToken = $this->getValue($tokenIterator);
if ('' !== $domainToken) {
$domain = $domainToken;
}
break;
} else {
@@ -224,6 +254,10 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
if ($message) {
$catalog->set($message, $this->prefix.$message, $domain);
$metadata = $catalog->getMetadata($message, $domain) ?? [];
$normalizedFilename = preg_replace('{[\\\\/]+}', '/', $filename);
$metadata['sources'][] = $normalizedFilename.':'.$tokens[$key][2];
$catalog->setMetadata($message, $metadata, $domain);
break;
}
}
@@ -239,13 +273,11 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
*/
protected function canBeExtracted($file)
{
return $this->isFile($file) && 'php' === pathinfo($file, PATHINFO_EXTENSION);
return $this->isFile($file) && 'php' === pathinfo($file, \PATHINFO_EXTENSION);
}
/**
* @param string|array $directory
*
* @return array
* {@inheritdoc}
*/
protected function extractFromDirectory($directory)
{

View File

@@ -49,7 +49,7 @@ namespace Symfony\Component\Translation\Extractor;
class PhpStringTokenParser
{
protected static $replacements = array(
protected static $replacements = [
'\\' => '\\',
'$' => '$',
'n' => "\n",
@@ -58,7 +58,7 @@ class PhpStringTokenParser
'f' => "\f",
'v' => "\v",
'e' => "\x1B",
);
];
/**
* Parses a string token.
@@ -76,8 +76,8 @@ class PhpStringTokenParser
if ('\'' === $str[$bLength]) {
return str_replace(
array('\\\\', '\\\''),
array('\\', '\''),
['\\\\', '\\\''],
['\\', '\''],
substr($str, $bLength + 1, -1)
);
} else {
@@ -101,12 +101,12 @@ class PhpStringTokenParser
return preg_replace_callback(
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~',
array(__CLASS__, 'parseCallback'),
[__CLASS__, 'parseCallback'],
$str
);
}
private static function parseCallback($matches)
private static function parseCallback(array $matches): string
{
$str = $matches[1];
@@ -133,7 +133,7 @@ class PhpStringTokenParser
$str = preg_replace('~(\r\n|\n|\r)$~', '', $str);
// nowdoc string
if (false !== strpos($startToken, '\'')) {
if (str_contains($startToken, '\'')) {
return $str;
}