mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-02 21:19:58 +09:00
Update to laravel 7
This commit is contained in:
@@ -21,13 +21,13 @@ 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) {
|
||||
if (is_iterable($resource)) {
|
||||
$files = [];
|
||||
foreach ($resource as $file) {
|
||||
if ($this->canBeExtracted($file)) {
|
||||
@@ -49,13 +49,11 @@ abstract class AbstractFileExtractor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function isFile($file)
|
||||
protected function isFile(string $file)
|
||||
{
|
||||
if (!is_file($file)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
|
||||
@@ -65,16 +63,14 @@ abstract class AbstractFileExtractor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canBeExtracted($file);
|
||||
abstract protected function canBeExtracted(string $file);
|
||||
|
||||
/**
|
||||
* @param string|array $resource Files, a file or a directory
|
||||
*
|
||||
* @return array files to be extracted
|
||||
* @return iterable
|
||||
*/
|
||||
abstract protected function extractFromDirectory($resource);
|
||||
}
|
||||
|
||||
@@ -29,11 +29,8 @@ class ChainExtractor implements ExtractorInterface
|
||||
|
||||
/**
|
||||
* Adds a loader to the translation extractor.
|
||||
*
|
||||
* @param string $format The format of the loader
|
||||
* @param ExtractorInterface $extractor The loader
|
||||
*/
|
||||
public function addExtractor($format, ExtractorInterface $extractor)
|
||||
public function addExtractor(string $format, ExtractorInterface $extractor)
|
||||
{
|
||||
$this->extractors[$format] = $extractor;
|
||||
}
|
||||
@@ -41,7 +38,7 @@ class ChainExtractor implements ExtractorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
public function setPrefix(string $prefix)
|
||||
{
|
||||
foreach ($this->extractors as $extractor) {
|
||||
$extractor->setPrefix($prefix);
|
||||
|
||||
@@ -24,15 +24,12 @@ 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);
|
||||
|
||||
/**
|
||||
* Sets the prefix that should be used for new found messages.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
*/
|
||||
public function setPrefix($prefix);
|
||||
public function setPrefix(string $prefix);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,17 @@ 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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $prefix = '';
|
||||
|
||||
/**
|
||||
* The sequence that captures translation messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sequences = [
|
||||
[
|
||||
@@ -50,25 +46,83 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
],
|
||||
[
|
||||
'->',
|
||||
'transChoice',
|
||||
'trans',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
self::METHOD_ARGUMENTS_TOKEN,
|
||||
',',
|
||||
self::METHOD_ARGUMENTS_TOKEN,
|
||||
',',
|
||||
self::DOMAIN_TOKEN,
|
||||
],
|
||||
[
|
||||
'->',
|
||||
'trans',
|
||||
'new',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
[
|
||||
'->',
|
||||
'transChoice',
|
||||
'new',
|
||||
'\\',
|
||||
'Symfony',
|
||||
'\\',
|
||||
'Component',
|
||||
'\\',
|
||||
'Translation',
|
||||
'\\',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
self::METHOD_ARGUMENTS_TOKEN,
|
||||
',',
|
||||
self::DOMAIN_TOKEN,
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'\Symfony\Component\Translation\TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
self::METHOD_ARGUMENTS_TOKEN,
|
||||
',',
|
||||
self::DOMAIN_TOKEN,
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'\\',
|
||||
'Symfony',
|
||||
'\\',
|
||||
'Component',
|
||||
'\\',
|
||||
'Translation',
|
||||
'\\',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'\Symfony\Component\Translation\TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
[
|
||||
't',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
self::METHOD_ARGUMENTS_TOKEN,
|
||||
',',
|
||||
self::DOMAIN_TOKEN,
|
||||
],
|
||||
[
|
||||
't',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
@@ -90,7 +144,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
public function setPrefix(string $prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
@@ -100,7 +154,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
*
|
||||
* @param mixed $token
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
protected function normalizeToken($token)
|
||||
{
|
||||
@@ -118,7 +172,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;
|
||||
}
|
||||
}
|
||||
@@ -166,23 +220,36 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
}
|
||||
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
case \T_WHITESPACE:
|
||||
break;
|
||||
default:
|
||||
break 2;
|
||||
@@ -194,18 +261,9 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
|
||||
/**
|
||||
* Extracts trans message from PHP tokens.
|
||||
*
|
||||
* @param array $tokens
|
||||
* @param MessageCatalogue $catalog
|
||||
* @param string $filename
|
||||
*/
|
||||
protected function parseTokens($tokens, MessageCatalogue $catalog/*, string $filename*/)
|
||||
protected function parseTokens(array $tokens, MessageCatalogue $catalog, string $filename)
|
||||
{
|
||||
if (\func_num_args() < 3 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
|
||||
@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) {
|
||||
@@ -253,24 +311,24 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function canBeExtracted($file)
|
||||
protected function canBeExtracted(string $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)
|
||||
{
|
||||
if (!class_exists(Finder::class)) {
|
||||
throw new \LogicException(sprintf('You cannot use "%s" as the "symfony/finder" package is not installed. Try running "composer require symfony/finder".', static::class));
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
|
||||
return $finder->files()->name('*.php')->in($directory);
|
||||
|
||||
@@ -65,9 +65,9 @@ class PhpStringTokenParser
|
||||
*
|
||||
* @param string $str String token content
|
||||
*
|
||||
* @return string The parsed string
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($str)
|
||||
public static function parse(string $str)
|
||||
{
|
||||
$bLength = 0;
|
||||
if ('b' === $str[0]) {
|
||||
@@ -91,9 +91,9 @@ class PhpStringTokenParser
|
||||
* @param string $str String without quotes
|
||||
* @param string|null $quote Quote type
|
||||
*
|
||||
* @return string String with escape sequences parsed
|
||||
* @return string
|
||||
*/
|
||||
public static function parseEscapeSequences($str, $quote)
|
||||
public static function parseEscapeSequences(string $str, string $quote = null)
|
||||
{
|
||||
if (null !== $quote) {
|
||||
$str = str_replace('\\'.$quote, $quote, $str);
|
||||
@@ -106,7 +106,7 @@ class PhpStringTokenParser
|
||||
);
|
||||
}
|
||||
|
||||
private static function parseCallback($matches)
|
||||
private static function parseCallback(array $matches): string
|
||||
{
|
||||
$str = $matches[1];
|
||||
|
||||
@@ -125,15 +125,15 @@ class PhpStringTokenParser
|
||||
* @param string $startToken Doc string start token content (<<<SMTHG)
|
||||
* @param string $str String token content
|
||||
*
|
||||
* @return string Parsed string
|
||||
* @return string
|
||||
*/
|
||||
public static function parseDocString($startToken, $str)
|
||||
public static function parseDocString(string $startToken, string $str)
|
||||
{
|
||||
// strip last newline (thanks tokenizer for sticking it into the string!)
|
||||
$str = preg_replace('~(\r\n|\n|\r)$~', '', $str);
|
||||
|
||||
// nowdoc string
|
||||
if (false !== strpos($startToken, '\'')) {
|
||||
if (str_contains($startToken, '\'')) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user