Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd8ca81

Browse files
committed
[CommandBasedContextChecker] adjust name to CLI
1 parent fb14627 commit fd8ca81

8 files changed

Lines changed: 27 additions & 36 deletions

File tree

src/Sylius/Bundle/CoreBundle/DependencyInjection/Compiler/TranslatableEntityLocalePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function process(ContainerBuilder $container): void
2626
$translatableEntityLocaleAssignerDefinition = new Definition(TranslatableEntityLocaleAssigner::class);
2727
$translatableEntityLocaleAssignerDefinition->addArgument(new Reference('sylius.context.locale'));
2828
$translatableEntityLocaleAssignerDefinition->addArgument(new Reference('sylius.translation_locale_provider'));
29-
$translatableEntityLocaleAssignerDefinition->addArgument(new Reference('Sylius\Component\Core\Checker\CommandBasedContextCheckerInterface'));
29+
$translatableEntityLocaleAssignerDefinition->addArgument(new Reference('Sylius\Component\Core\Checker\CLIContextCheckerInterface'));
3030

3131
$container
3232
->setDefinition('sylius.translatable_entity_locale_assigner', $translatableEntityLocaleAssignerDefinition)

src/Sylius/Bundle/CoreBundle/Resources/config/services/checkers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<argument type="service" id="sylius.payment_methods_resolver"/>
2525
</service>
2626

27-
<service id="Sylius\Component\Core\Checker\CommandBasedContextCheckerInterface" class="Sylius\Component\Core\Checker\CommandBasedContextChecker">
27+
<service id="Sylius\Component\Core\Checker\CLIContextCheckerInterface" class="Sylius\Component\Core\Checker\CLIContextChecker">
2828
<argument type="string">%kernel.environment%</argument>
2929
<argument type="collection">
3030
<argument type="string">test</argument>

src/Sylius/Component/Core/Checker/CommandBasedContextChecker.php renamed to src/Sylius/Component/Core/Checker/CLIContextChecker.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
namespace Sylius\Component\Core\Checker;
1515

16-
use Sylius\Component\Core\Context\ProcessContextInterface;
17-
18-
final class CommandBasedContextChecker implements CommandBasedContextCheckerInterface
16+
final class CLIContextChecker implements CLIContextCheckerInterface
1917
{
18+
private const CLI = 'cli';
19+
2020
public function __construct(
2121
private string $runningEnvironment,
2222
private array $restrictedEnvironments
2323
) { }
2424

25-
public function isRunningFromCommand(): bool
25+
public function isExecutedFromCLI(): bool
2626
{
27-
return !in_array($this->runningEnvironment, $this->restrictedEnvironments) && \php_sapi_name() === ProcessContextInterface::CLI;
27+
return !in_array($this->runningEnvironment, $this->restrictedEnvironments) && \php_sapi_name() === self::CLI;
2828
}
2929
}

src/Sylius/Component/Core/Checker/CommandBasedContextCheckerInterface.php renamed to src/Sylius/Component/Core/Checker/CLIContextCheckerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Sylius\Component\Core\Checker;
1515

16-
interface CommandBasedContextCheckerInterface
16+
interface CLIContextCheckerInterface
1717
{
18-
public function isRunningFromCommand(): bool;
18+
public function isExecutedFromCLI(): bool;
1919
}

src/Sylius/Component/Core/Context/ProcessContextInterface.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Sylius/Component/Core/Translation/TranslatableEntityLocaleAssigner.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Sylius\Component\Core\Translation;
1515

16-
use Sylius\Component\Core\Checker\CommandBasedContextCheckerInterface;
16+
use Sylius\Component\Core\Checker\CLIContextCheckerInterface;
1717
use Sylius\Component\Locale\Context\LocaleContextInterface;
1818
use Sylius\Component\Locale\Context\LocaleNotFoundException;
1919
use Sylius\Component\Resource\Model\TranslatableInterface;
@@ -25,7 +25,7 @@ final class TranslatableEntityLocaleAssigner implements TranslatableEntityLocale
2525
public function __construct(
2626
private LocaleContextInterface $localeContext,
2727
private TranslationLocaleProviderInterface $translationLocaleProvider,
28-
private ?CommandBasedContextCheckerInterface $commandBasedChecker = null
28+
private ?CLIContextCheckerInterface $commandBasedChecker = null
2929
) {
3030
if ($this->commandBasedChecker === null) {
3131
@trigger_error(
@@ -38,10 +38,10 @@ public function __construct(
3838
public function assignLocale(TranslatableInterface $translatableEntity): void
3939
{
4040
$fallbackLocale = $this->translationLocaleProvider->getDefaultLocaleCode();
41+
$translatableEntity->setFallbackLocale($fallbackLocale);
4142

42-
if ($this->commandBasedChecker !== null && $this->commandBasedChecker->isRunningFromCommand()) {
43+
if ($this->commandBasedChecker !== null && $this->commandBasedChecker->isExecutedFromCLI()) {
4344
$translatableEntity->setCurrentLocale($fallbackLocale);
44-
$translatableEntity->setFallbackLocale($fallbackLocale);
4545

4646
return;
4747
}
@@ -53,6 +53,5 @@ public function assignLocale(TranslatableInterface $translatableEntity): void
5353
}
5454

5555
$translatableEntity->setCurrentLocale($currentLocale);
56-
$translatableEntity->setFallbackLocale($fallbackLocale);
5756
}
5857
}

src/Sylius/Component/Core/spec/Checker/CommandBasedContextCheckerSpec.php renamed to src/Sylius/Component/Core/spec/Checker/CLIContextCheckerSpec.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
namespace spec\Sylius\Component\Core\Checker;
1515

1616
use PhpSpec\ObjectBehavior;
17-
use Sylius\Component\Core\Checker\CommandBasedContextCheckerInterface;
17+
use Sylius\Component\Core\Checker\CLIContextCheckerInterface;
1818

19-
final class CommandBasedContextCheckerSpec extends ObjectBehavior
19+
final class CLIContextCheckerSpec extends ObjectBehavior
2020
{
2121
function let(): void
2222
{
@@ -25,25 +25,25 @@ function let(): void
2525

2626
function it_implements_command_based_context_checker_interface(): void
2727
{
28-
$this->shouldImplement(CommandBasedContextCheckerInterface::class);
28+
$this->shouldImplement(CLIContextCheckerInterface::class);
2929
}
3030

3131
function it_returns_true_if_process_is_not_running_in_test_environment_and_from_cli(): void
3232
{
33-
$this->isRunningFromCommand()->shouldReturn(true);
33+
$this->isExecutedFromCLI()->shouldReturn(true);
3434
}
3535

3636
function it_returns_false_if_process_is_running_in_test_environment_and_from_cli(): void
3737
{
3838
$this->beConstructedWith('test', ['test', 'test_cached']);
3939

40-
$this->isRunningFromCommand()->shouldReturn(false);
40+
$this->isExecutedFromCLI()->shouldReturn(false);
4141
}
4242

4343
function it_returns_false_if_process_is_running_in_test_cached_environment_and_from_cli(): void
4444
{
4545
$this->beConstructedWith('test_cached', ['test', 'test_cached']);
4646

47-
$this->isRunningFromCommand()->shouldReturn(false);
47+
$this->isExecutedFromCLI()->shouldReturn(false);
4848
}
4949
}

src/Sylius/Component/Core/spec/Translation/TranslatableEntityLocaleAssignerSpec.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace spec\Sylius\Component\Core\Translation;
1515

1616
use PhpSpec\ObjectBehavior;
17-
use Sylius\Component\Core\Checker\CommandBasedContextChecker;
18-
use Sylius\Component\Core\Checker\CommandBasedContextCheckerInterface;
17+
use Sylius\Component\Core\Checker\CLIContextChecker;
18+
use Sylius\Component\Core\Checker\CLIContextCheckerInterface;
1919
use Sylius\Component\Locale\Context\LocaleContextInterface;
2020
use Sylius\Component\Locale\Context\LocaleNotFoundException;
2121
use Sylius\Component\Resource\Model\TranslatableInterface;
@@ -52,15 +52,15 @@ function it_assigns_locale_if_command_based_context_checker_is_not_provided(
5252
LocaleContextInterface $localeContext,
5353
TranslationLocaleProviderInterface $translationLocaleProvider,
5454
TranslatableInterface $translatableEntity,
55-
CommandBasedContextCheckerInterface $commandBasedContextChecker
55+
CLIContextCheckerInterface $commandBasedContextChecker
5656
): void {
5757
$localeContext->getLocaleCode()->willReturn('de_DE');
5858
$translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
5959

6060
$translatableEntity->setCurrentLocale('de_DE')->shouldBeCalled();
6161
$translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
6262

63-
$commandBasedContextChecker->isRunningFromCommand()->shouldNotBeCalled();
63+
$commandBasedContextChecker->isExecutedFromCLI()->shouldNotBeCalled();
6464

6565
$this->assignLocale($translatableEntity);
6666
}
@@ -69,11 +69,11 @@ function it_assigns_fallback_locale_if_running_from_command(
6969
LocaleContextInterface $localeContext,
7070
TranslationLocaleProviderInterface $translationLocaleProvider,
7171
TranslatableInterface $translatableEntity,
72-
CommandBasedContextCheckerInterface $commandBasedContextChecker
72+
CLIContextCheckerInterface $commandBasedContextChecker
7373
): void {
7474
$this->beConstructedWith($localeContext, $translationLocaleProvider, $commandBasedContextChecker);
7575

76-
$commandBasedContextChecker->isRunningFromCommand()->willReturn(true);
76+
$commandBasedContextChecker->isExecutedFromCLI()->willReturn(true);
7777

7878
$localeContext->getLocaleCode()->shouldNotBeCalled();
7979
$translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
@@ -88,7 +88,7 @@ function it_assigns_locale_if_process_is_not_running_from_cli(
8888
LocaleContextInterface $localeContext,
8989
TranslationLocaleProviderInterface $translationLocaleProvider,
9090
TranslatableInterface $translatableEntity,
91-
CommandBasedContextCheckerInterface $commandBasedContextChecker
91+
CLIContextCheckerInterface $commandBasedContextChecker
9292
): void {
9393
$this->beConstructedWith($localeContext, $translationLocaleProvider, $commandBasedContextChecker);
9494

@@ -98,7 +98,7 @@ function it_assigns_locale_if_process_is_not_running_from_cli(
9898
$translatableEntity->setCurrentLocale('de_DE')->shouldBeCalled();
9999
$translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
100100

101-
$commandBasedContextChecker->isRunningFromCommand()->willReturn(false);
101+
$commandBasedContextChecker->isExecutedFromCLI()->willReturn(false);
102102

103103
$this->assignLocale($translatableEntity);
104104
}

0 commit comments

Comments
 (0)