mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[SF7][Money] Remove unneeded templating helpers
This commit is contained in:
parent
e7fb7249e7
commit
e924ebd015
11 changed files with 16 additions and 329 deletions
|
|
@ -180,7 +180,16 @@
|
|||
`Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository` to
|
||||
`Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductAssociationRepository`
|
||||
|
||||
# Password Encoder & Salt
|
||||
* The following helper classes and interfaces have been removed:
|
||||
|
||||
Money:
|
||||
|
||||
* `Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelper`
|
||||
* `Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelperInterface`
|
||||
* `Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelper`
|
||||
* `Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelperInterface`
|
||||
|
||||
## Password Encoder & Salt
|
||||
The encoder and salt has been removed from the User entities. It will use the password hasher configured on Symfony security configuration.
|
||||
|
||||
This "encoder" is configured via the [Symfony security password hasher](https://symfony.com/doc/current/security/passwords.html#configuring-a-password-hasher).
|
||||
|
|
|
|||
|
|
@ -22,13 +22,8 @@
|
|||
<service id="sylius.money_formatter" class="Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatter" />
|
||||
<service id="Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface" alias="sylius.money_formatter" />
|
||||
|
||||
<service id="sylius.templating.helper.format_money" class="Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelper" lazy="true">
|
||||
<argument type="service" id="sylius.money_formatter" />
|
||||
<tag name="templating.helper" alias="sylius_format_money" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.twig.extension.money" class="Sylius\Bundle\MoneyBundle\Twig\FormatMoneyExtension" public="false">
|
||||
<argument type="service" id="sylius.templating.helper.format_money" />
|
||||
<argument type="service" id="sylius.money_formatter" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
</services>
|
||||
|
|
|
|||
|
|
@ -15,13 +15,8 @@
|
|||
<services>
|
||||
<defaults public="true" />
|
||||
|
||||
<service id="sylius.templating.helper.convert_money" class="Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelper" lazy="true">
|
||||
<argument type="service" id="sylius.currency_converter" />
|
||||
<tag name="templating.helper" alias="sylius_convert_money" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.twig.extension.convert_amount" class="Sylius\Bundle\MoneyBundle\Twig\ConvertMoneyExtension" public="false">
|
||||
<argument type="service" id="sylius.templating.helper.convert_money" />
|
||||
<argument type="service" id="sylius.currency_converter" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
</services>
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Component\Currency\Converter\CurrencyConverter;
|
||||
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The "%s" class is deprecated, use "%s" instead.',
|
||||
ConvertMoneyHelper::class,
|
||||
CurrencyConverter::class,
|
||||
);
|
||||
|
||||
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. Use {@see \Sylius\Component\Currency\Converter\CurrencyConverter} instead. */
|
||||
class ConvertMoneyHelper implements ConvertMoneyHelperInterface
|
||||
{
|
||||
private string $charset = 'UTF-8';
|
||||
|
||||
public function __construct(private CurrencyConverterInterface $currencyConverter)
|
||||
{
|
||||
}
|
||||
|
||||
public function convertAmount(int $amount, ?string $sourceCurrencyCode, ?string $targetCurrencyCode): string
|
||||
{
|
||||
return (string) $this->currencyConverter->convert($amount, $sourceCurrencyCode, $targetCurrencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default charset.
|
||||
*/
|
||||
public function setCharset(string $charset): void
|
||||
{
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default charset.
|
||||
*/
|
||||
public function getCharset(): string
|
||||
{
|
||||
return $this->charset;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'sylius_money_converter';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The "%s" interface is deprecated, use "%s" instead.',
|
||||
ConvertMoneyHelperInterface::class,
|
||||
CurrencyConverterInterface::class,
|
||||
);
|
||||
|
||||
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. Use {@see \Sylius\Component\Currency\Converter\CurrencyConverterInterface} instead. */
|
||||
interface ConvertMoneyHelperInterface
|
||||
{
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function convertAmount(int $amount, ?string $sourceCurrencyCode, ?string $targetCurrencyCode): string;
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatter;
|
||||
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The "%s" class is deprecated, use "%s" instead.',
|
||||
FormatMoneyHelper::class,
|
||||
MoneyFormatter::class,
|
||||
);
|
||||
|
||||
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. Use {@see \Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatter} instead. */
|
||||
class FormatMoneyHelper implements FormatMoneyHelperInterface
|
||||
{
|
||||
private string $charset = 'UTF-8';
|
||||
|
||||
public function __construct(private MoneyFormatterInterface $moneyFormatter)
|
||||
{
|
||||
}
|
||||
|
||||
public function formatAmount(int $amount, string $currencyCode, string $localeCode): string
|
||||
{
|
||||
return $this->moneyFormatter->format($amount, $currencyCode, $localeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default charset.
|
||||
*/
|
||||
public function setCharset(string $charset): void
|
||||
{
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default charset.
|
||||
*/
|
||||
public function getCharset(): string
|
||||
{
|
||||
return $this->charset;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'sylius_format_money';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The "%s" interface is deprecated, use "%s" instead.',
|
||||
FormatMoneyHelperInterface::class,
|
||||
MoneyFormatterInterface::class,
|
||||
);
|
||||
|
||||
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. Use {@see \Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface} instead. */
|
||||
interface FormatMoneyHelperInterface
|
||||
{
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function formatAmount(int $amount, string $currencyCode, string $localeCode): string;
|
||||
}
|
||||
|
|
@ -13,43 +13,20 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\MoneyBundle\Twig;
|
||||
|
||||
use Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelperInterface;
|
||||
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
final class ConvertMoneyExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(private ConvertMoneyHelperInterface|CurrencyConverterInterface $helper)
|
||||
public function __construct(private CurrencyConverterInterface $currencyConverter)
|
||||
{
|
||||
if ($this->helper instanceof ConvertMoneyHelperInterface) {
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'Passing an instance of %s as constructor argument for %s is deprecated and will be prohibited in Sylius 2.0. Pass an instance of %s instead.',
|
||||
ConvertMoneyHelperInterface::class,
|
||||
self::class,
|
||||
CurrencyConverterInterface::class,
|
||||
);
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The argument name $helper is deprecated and will be renamed to $currencyConverter in Sylius 2.0.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
if ($this->helper instanceof CurrencyConverterInterface) {
|
||||
return [
|
||||
new TwigFilter('sylius_convert_money', [$this->helper, 'convert']),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
new TwigFilter('sylius_convert_money', [$this->helper, 'convertAmount']),
|
||||
new TwigFilter('sylius_convert_money', [$this->currencyConverter, 'convert']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,43 +14,19 @@ declare(strict_types=1);
|
|||
namespace Sylius\Bundle\MoneyBundle\Twig;
|
||||
|
||||
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
|
||||
use Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelperInterface;
|
||||
use Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelperInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
final class FormatMoneyExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(private FormatMoneyHelperInterface|MoneyFormatterInterface $helper)
|
||||
public function __construct(private MoneyFormatterInterface $moneyFormatter)
|
||||
{
|
||||
if ($this->helper instanceof ConvertMoneyHelperInterface) {
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'Passing an instance of %s as constructor argument for %s is deprecated and will be prohibited in Sylius 2.0. Pass an instance of %s instead.',
|
||||
FormatMoneyHelperInterface::class,
|
||||
self::class,
|
||||
MoneyFormatterInterface::class,
|
||||
);
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/money-bundle',
|
||||
'1.14',
|
||||
'The argument name $helper is deprecated and will be renamed to $moneyFormatter in Sylius 2.0.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
if ($this->helper instanceof MoneyFormatterInterface) {
|
||||
return [
|
||||
new TwigFilter('sylius_format_money', [$this->helper, 'format']),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
new TwigFilter('sylius_format_money', [$this->helper, 'formatAmount']),
|
||||
new TwigFilter('sylius_format_money', [$this->moneyFormatter, 'format']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\MoneyBundle\Templating\Helper\ConvertMoneyHelperInterface;
|
||||
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
|
||||
|
||||
final class ConvertMoneyHelperSpec extends ObjectBehavior
|
||||
{
|
||||
function let(CurrencyConverterInterface $currencyConverter): void
|
||||
{
|
||||
$this->beConstructedWith($currencyConverter);
|
||||
}
|
||||
|
||||
function it_is_a_convert_money_price_helper(): void
|
||||
{
|
||||
$this->shouldImplement(ConvertMoneyHelperInterface::class);
|
||||
}
|
||||
|
||||
function it_converts_and_formats_money_using_default_locale_if_not_given(
|
||||
CurrencyConverterInterface $currencyConverter,
|
||||
): void {
|
||||
$currencyConverter->convert(500, 'USD', 'CAD')->willReturn(250);
|
||||
|
||||
$this->convertAmount(500, 'USD', 'CAD')->shouldReturn('250');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\MoneyBundle\Templating\Helper;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
|
||||
use Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelperInterface;
|
||||
|
||||
final class FormatMoneyHelperSpec extends ObjectBehavior
|
||||
{
|
||||
function let(MoneyFormatterInterface $moneyFormatter): void
|
||||
{
|
||||
$this->beConstructedWith($moneyFormatter);
|
||||
}
|
||||
|
||||
function it_implements_format_money_helper_interface(): void
|
||||
{
|
||||
$this->shouldImplement(FormatMoneyHelperInterface::class);
|
||||
}
|
||||
|
||||
function it_formats_money_using_given_currency_and_locale(MoneyFormatterInterface $moneyFormatter): void
|
||||
{
|
||||
$moneyFormatter->format(2500, 'EUR', 'fr_FR')->willReturn('€25.00');
|
||||
|
||||
$this->formatAmount(2500, 'EUR', 'fr_FR')->shouldReturn('€25.00');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue