updated-packages
This commit is contained in:
60
vendor/symfony/translation/MessageCatalogue.php
vendored
60
vendor/symfony/translation/MessageCatalogue.php
vendored
@@ -19,19 +19,22 @@ use Symfony\Component\Translation\Exception\LogicException;
|
||||
*/
|
||||
class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterface
|
||||
{
|
||||
private $messages = array();
|
||||
private $metadata = array();
|
||||
private $resources = array();
|
||||
private $messages = [];
|
||||
private $metadata = [];
|
||||
private $resources = [];
|
||||
private $locale;
|
||||
private $fallbackCatalogue;
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @param string $locale The locale
|
||||
* @param array $messages An array of messages classified by domain
|
||||
* @param array $messages An array of messages classified by domain
|
||||
*/
|
||||
public function __construct(?string $locale, array $messages = array())
|
||||
public function __construct(?string $locale, array $messages = [])
|
||||
{
|
||||
if (null === $locale) {
|
||||
@trigger_error(sprintf('Passing "null" to the first argument of the "%s" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.', __METHOD__), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->locale = $locale;
|
||||
$this->messages = $messages;
|
||||
}
|
||||
@@ -49,12 +52,11 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
*/
|
||||
public function getDomains()
|
||||
{
|
||||
$domains = array();
|
||||
$suffixLength = \strlen(self::INTL_DOMAIN_SUFFIX);
|
||||
$domains = [];
|
||||
|
||||
foreach ($this->messages as $domain => $messages) {
|
||||
if (\strlen($domain) > $suffixLength && false !== $i = strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
|
||||
$domain = substr($domain, 0, $i);
|
||||
if (str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) {
|
||||
$domain = substr($domain, 0, -\strlen(self::INTL_DOMAIN_SUFFIX));
|
||||
}
|
||||
$domains[$domain] = $domain;
|
||||
}
|
||||
@@ -68,18 +70,22 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
public function all($domain = null)
|
||||
{
|
||||
if (null !== $domain) {
|
||||
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? array()) + ($this->messages[$domain] ?? array());
|
||||
// skip messages merge if intl-icu requested explicitly
|
||||
if (str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) {
|
||||
return $this->messages[$domain] ?? [];
|
||||
}
|
||||
|
||||
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []);
|
||||
}
|
||||
|
||||
$allMessages = array();
|
||||
$suffixLength = \strlen(self::INTL_DOMAIN_SUFFIX);
|
||||
$allMessages = [];
|
||||
|
||||
foreach ($this->messages as $domain => $messages) {
|
||||
if (\strlen($domain) > $suffixLength && false !== $i = strpos($domain, self::INTL_DOMAIN_SUFFIX, -$suffixLength)) {
|
||||
$domain = substr($domain, 0, $i);
|
||||
$allMessages[$domain] = $messages + ($allMessages[$domain] ?? array());
|
||||
if (str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) {
|
||||
$domain = substr($domain, 0, -\strlen(self::INTL_DOMAIN_SUFFIX));
|
||||
$allMessages[$domain] = $messages + ($allMessages[$domain] ?? []);
|
||||
} else {
|
||||
$allMessages[$domain] = ($allMessages[$domain] ?? array()) + $messages;
|
||||
$allMessages[$domain] = ($allMessages[$domain] ?? []) + $messages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +97,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
*/
|
||||
public function set($id, $translation, $domain = 'messages')
|
||||
{
|
||||
$this->add(array($id => $translation), $domain);
|
||||
$this->add([$id => $translation], $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,10 +159,14 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
*/
|
||||
public function add($messages, $domain = 'messages')
|
||||
{
|
||||
if (!isset($this->messages[$domain])) {
|
||||
$this->messages[$domain] = $messages;
|
||||
} else {
|
||||
$this->messages[$domain] = array_replace($this->messages[$domain], $messages);
|
||||
$altDomain = str_ends_with($domain, self::INTL_DOMAIN_SUFFIX) ? substr($domain, 0, -\strlen(self::INTL_DOMAIN_SUFFIX)) : $domain.self::INTL_DOMAIN_SUFFIX;
|
||||
foreach ($messages as $id => $message) {
|
||||
unset($this->messages[$altDomain][$id]);
|
||||
$this->messages[$domain][$id] = $message;
|
||||
}
|
||||
|
||||
if ([] === ($this->messages[$altDomain] ?? null)) {
|
||||
unset($this->messages[$altDomain]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +176,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
public function addCatalogue(MessageCatalogueInterface $catalogue)
|
||||
{
|
||||
if ($catalogue->getLocale() !== $this->locale) {
|
||||
throw new LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
|
||||
throw new LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s".', $catalogue->getLocale(), $this->locale));
|
||||
}
|
||||
|
||||
foreach ($catalogue->all() as $domain => $messages) {
|
||||
@@ -261,6 +271,8 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
return $this->metadata[$domain][$key];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +289,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
public function deleteMetadata($key = '', $domain = 'messages')
|
||||
{
|
||||
if ('' == $domain) {
|
||||
$this->metadata = array();
|
||||
$this->metadata = [];
|
||||
} elseif ('' == $key) {
|
||||
unset($this->metadata[$domain]);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user