Initial Commit
This commit is contained in:
32
dependencies/symfony/translation/Provider/AbstractProviderFactory.php
vendored
Normal file
32
dependencies/symfony/translation/Provider/AbstractProviderFactory.php
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\IncompleteDsnException;
|
||||
abstract class AbstractProviderFactory implements \Symfony\Component\Translation\Provider\ProviderFactoryInterface
|
||||
{
|
||||
public function supports(\Symfony\Component\Translation\Provider\Dsn $dsn) : bool
|
||||
{
|
||||
return \in_array($dsn->getScheme(), $this->getSupportedSchemes(), \true);
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected abstract function getSupportedSchemes() : array;
|
||||
protected function getUser(\Symfony\Component\Translation\Provider\Dsn $dsn) : string
|
||||
{
|
||||
return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.', $dsn->getScheme() . '://' . $dsn->getHost());
|
||||
}
|
||||
protected function getPassword(\Symfony\Component\Translation\Provider\Dsn $dsn) : string
|
||||
{
|
||||
return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
|
||||
}
|
||||
}
|
92
dependencies/symfony/translation/Provider/Dsn.php
vendored
Normal file
92
dependencies/symfony/translation/Provider/Dsn.php
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Exception\MissingRequiredOptionException;
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
||||
*/
|
||||
final class Dsn
|
||||
{
|
||||
private ?string $scheme;
|
||||
private ?string $host;
|
||||
private ?string $user;
|
||||
private ?string $password;
|
||||
private ?int $port;
|
||||
private ?string $path;
|
||||
private array $options = [];
|
||||
private string $originalDsn;
|
||||
public function __construct(#[\SensitiveParameter] string $dsn)
|
||||
{
|
||||
$this->originalDsn = $dsn;
|
||||
if (\false === ($parsedDsn = \parse_url($dsn))) {
|
||||
throw new InvalidArgumentException('The translation provider DSN is invalid.');
|
||||
}
|
||||
if (!isset($parsedDsn['scheme'])) {
|
||||
throw new InvalidArgumentException('The translation provider DSN must contain a scheme.');
|
||||
}
|
||||
$this->scheme = $parsedDsn['scheme'];
|
||||
if (!isset($parsedDsn['host'])) {
|
||||
throw new InvalidArgumentException('The translation provider DSN must contain a host (use "default" by default).');
|
||||
}
|
||||
$this->host = $parsedDsn['host'];
|
||||
$this->user = '' !== ($parsedDsn['user'] ?? '') ? \urldecode($parsedDsn['user']) : null;
|
||||
$this->password = '' !== ($parsedDsn['pass'] ?? '') ? \urldecode($parsedDsn['pass']) : null;
|
||||
$this->port = $parsedDsn['port'] ?? null;
|
||||
$this->path = $parsedDsn['path'] ?? null;
|
||||
\parse_str($parsedDsn['query'] ?? '', $this->options);
|
||||
}
|
||||
public function getScheme() : string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
public function getHost() : string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
public function getUser() : ?string
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
public function getPassword() : ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
public function getPort(int $default = null) : ?int
|
||||
{
|
||||
return $this->port ?? $default;
|
||||
}
|
||||
public function getOption(string $key, mixed $default = null) : mixed
|
||||
{
|
||||
return $this->options[$key] ?? $default;
|
||||
}
|
||||
public function getRequiredOption(string $key) : mixed
|
||||
{
|
||||
if (!\array_key_exists($key, $this->options) || '' === \trim($this->options[$key])) {
|
||||
throw new MissingRequiredOptionException($key);
|
||||
}
|
||||
return $this->options[$key];
|
||||
}
|
||||
public function getOptions() : array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
public function getPath() : ?string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
public function getOriginalDsn() : string
|
||||
{
|
||||
return $this->originalDsn;
|
||||
}
|
||||
}
|
53
dependencies/symfony/translation/Provider/FilteringProvider.php
vendored
Normal file
53
dependencies/symfony/translation/Provider/FilteringProvider.php
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\TranslatorBag;
|
||||
use Symfony\Component\Translation\TranslatorBagInterface;
|
||||
/**
|
||||
* Filters domains and locales between the Translator config values and those specific to each provider.
|
||||
*
|
||||
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
||||
*/
|
||||
class FilteringProvider implements \Symfony\Component\Translation\Provider\ProviderInterface
|
||||
{
|
||||
private \Symfony\Component\Translation\Provider\ProviderInterface $provider;
|
||||
private array $locales;
|
||||
private array $domains;
|
||||
public function __construct(\Symfony\Component\Translation\Provider\ProviderInterface $provider, array $locales, array $domains = [])
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->locales = $locales;
|
||||
$this->domains = $domains;
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
return (string) $this->provider;
|
||||
}
|
||||
public function write(TranslatorBagInterface $translatorBag) : void
|
||||
{
|
||||
$this->provider->write($translatorBag);
|
||||
}
|
||||
public function read(array $domains, array $locales) : TranslatorBag
|
||||
{
|
||||
$domains = !$this->domains ? $domains : \array_intersect($this->domains, $domains);
|
||||
$locales = \array_intersect($this->locales, $locales);
|
||||
return $this->provider->read($domains, $locales);
|
||||
}
|
||||
public function delete(TranslatorBagInterface $translatorBag) : void
|
||||
{
|
||||
$this->provider->delete($translatorBag);
|
||||
}
|
||||
public function getDomains() : array
|
||||
{
|
||||
return $this->domains;
|
||||
}
|
||||
}
|
34
dependencies/symfony/translation/Provider/NullProvider.php
vendored
Normal file
34
dependencies/symfony/translation/Provider/NullProvider.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\TranslatorBag;
|
||||
use Symfony\Component\Translation\TranslatorBagInterface;
|
||||
/**
|
||||
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
||||
*/
|
||||
class NullProvider implements \Symfony\Component\Translation\Provider\ProviderInterface
|
||||
{
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
public function write(TranslatorBagInterface $translatorBag, bool $override = \false) : void
|
||||
{
|
||||
}
|
||||
public function read(array $domains, array $locales) : TranslatorBag
|
||||
{
|
||||
return new TranslatorBag();
|
||||
}
|
||||
public function delete(TranslatorBagInterface $translatorBag) : void
|
||||
{
|
||||
}
|
||||
}
|
30
dependencies/symfony/translation/Provider/NullProviderFactory.php
vendored
Normal file
30
dependencies/symfony/translation/Provider/NullProviderFactory.php
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
|
||||
/**
|
||||
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
||||
*/
|
||||
final class NullProviderFactory extends \Symfony\Component\Translation\Provider\AbstractProviderFactory
|
||||
{
|
||||
public function create(\Symfony\Component\Translation\Provider\Dsn $dsn) : \Symfony\Component\Translation\Provider\ProviderInterface
|
||||
{
|
||||
if ('null' === $dsn->getScheme()) {
|
||||
return new \Symfony\Component\Translation\Provider\NullProvider();
|
||||
}
|
||||
throw new UnsupportedSchemeException($dsn, 'null', $this->getSupportedSchemes());
|
||||
}
|
||||
protected function getSupportedSchemes() : array
|
||||
{
|
||||
return ['null'];
|
||||
}
|
||||
}
|
23
dependencies/symfony/translation/Provider/ProviderFactoryInterface.php
vendored
Normal file
23
dependencies/symfony/translation/Provider/ProviderFactoryInterface.php
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\IncompleteDsnException;
|
||||
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
|
||||
interface ProviderFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @throws UnsupportedSchemeException
|
||||
* @throws IncompleteDsnException
|
||||
*/
|
||||
public function create(\Symfony\Component\Translation\Provider\Dsn $dsn) : \Symfony\Component\Translation\Provider\ProviderInterface;
|
||||
public function supports(\Symfony\Component\Translation\Provider\Dsn $dsn) : bool;
|
||||
}
|
27
dependencies/symfony/translation/Provider/ProviderInterface.php
vendored
Normal file
27
dependencies/symfony/translation/Provider/ProviderInterface.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\TranslatorBag;
|
||||
use Symfony\Component\Translation\TranslatorBagInterface;
|
||||
interface ProviderInterface
|
||||
{
|
||||
public function __toString() : string;
|
||||
/**
|
||||
* Translations available in the TranslatorBag only must be created.
|
||||
* Translations available in both the TranslatorBag and on the provider
|
||||
* must be overwritten.
|
||||
* Translations available on the provider only must be kept.
|
||||
*/
|
||||
public function write(TranslatorBagInterface $translatorBag) : void;
|
||||
public function read(array $domains, array $locales) : TranslatorBag;
|
||||
public function delete(TranslatorBagInterface $translatorBag) : void;
|
||||
}
|
49
dependencies/symfony/translation/Provider/TranslationProviderCollection.php
vendored
Normal file
49
dependencies/symfony/translation/Provider/TranslationProviderCollection.php
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
/**
|
||||
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
||||
*/
|
||||
final class TranslationProviderCollection
|
||||
{
|
||||
/**
|
||||
* @var array<string, ProviderInterface>
|
||||
*/
|
||||
private $providers;
|
||||
/**
|
||||
* @param array<string, ProviderInterface> $providers
|
||||
*/
|
||||
public function __construct(iterable $providers)
|
||||
{
|
||||
$this->providers = \is_array($providers) ? $providers : \iterator_to_array($providers);
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
return '[' . \implode(',', \array_keys($this->providers)) . ']';
|
||||
}
|
||||
public function has(string $name) : bool
|
||||
{
|
||||
return isset($this->providers[$name]);
|
||||
}
|
||||
public function get(string $name) : \Symfony\Component\Translation\Provider\ProviderInterface
|
||||
{
|
||||
if (!$this->has($name)) {
|
||||
throw new InvalidArgumentException(\sprintf('Provider "%s" not found. Available: "%s".', $name, (string) $this));
|
||||
}
|
||||
return $this->providers[$name];
|
||||
}
|
||||
public function keys() : array
|
||||
{
|
||||
return \array_keys($this->providers);
|
||||
}
|
||||
}
|
46
dependencies/symfony/translation/Provider/TranslationProviderCollectionFactory.php
vendored
Normal file
46
dependencies/symfony/translation/Provider/TranslationProviderCollectionFactory.php
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Component\Translation\Provider;
|
||||
|
||||
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
|
||||
/**
|
||||
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
||||
*/
|
||||
class TranslationProviderCollectionFactory
|
||||
{
|
||||
private iterable $factories;
|
||||
private array $enabledLocales;
|
||||
/**
|
||||
* @param iterable<mixed, ProviderFactoryInterface> $factories
|
||||
*/
|
||||
public function __construct(iterable $factories, array $enabledLocales)
|
||||
{
|
||||
$this->factories = $factories;
|
||||
$this->enabledLocales = $enabledLocales;
|
||||
}
|
||||
public function fromConfig(array $config) : \Symfony\Component\Translation\Provider\TranslationProviderCollection
|
||||
{
|
||||
$providers = [];
|
||||
foreach ($config as $name => $currentConfig) {
|
||||
$providers[$name] = $this->fromDsnObject(new \Symfony\Component\Translation\Provider\Dsn($currentConfig['dsn']), !$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'], !$currentConfig['domains'] ? [] : $currentConfig['domains']);
|
||||
}
|
||||
return new \Symfony\Component\Translation\Provider\TranslationProviderCollection($providers);
|
||||
}
|
||||
public function fromDsnObject(\Symfony\Component\Translation\Provider\Dsn $dsn, array $locales, array $domains = []) : \Symfony\Component\Translation\Provider\ProviderInterface
|
||||
{
|
||||
foreach ($this->factories as $factory) {
|
||||
if ($factory->supports($dsn)) {
|
||||
return new \Symfony\Component\Translation\Provider\FilteringProvider($factory->create($dsn), $locales, $domains);
|
||||
}
|
||||
}
|
||||
throw new UnsupportedSchemeException($dsn);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user