Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spryker/kernel
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.76.0
Choose a base ref
...
head repository: spryker/kernel
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.77.0
Choose a head ref
  • 1 commit
  • 17 files changed
  • 1 contributor

Commits on Feb 27, 2025

  1. CC-34502: Order Amendment Finalisation (Order replacement) (#11306)

    Order Amendment Finalisation (Order replacement)
    dmiseev authored Feb 27, 2025
    Copy the full SHA
    170ce4c View commit details
25 changes: 24 additions & 1 deletion src/Spryker/Client/Kernel/AbstractFactory.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,24 @@ abstract class AbstractFactory
use BundleConfigResolverAwareTrait;
use ContainerMocker;

/**
* Specification:
* - Defines the default behavior of service loading.
* - The service is resolved immediately as part of fetching.
*
* @var string
*/
public const LOADING_EAGER = 'LOADING_EAGER';

/**
* Specification:
* - Defines the optional behavior of service loading.
* - The service is resolved later, when it is actually needed.
*
* @var string
*/
public const LOADING_LAZY = 'LOADING_LAZY';

/**
* @var array<\Spryker\Client\Kernel\Container>
*/
@@ -36,19 +54,24 @@ public function setContainer(Container $container)

/**
* @param string $key
* @param string $fetch The `LOADING_LAZY` behavior returns the service as closure for later resolving.
*
* @throws \Spryker\Client\Kernel\Exception\Container\ContainerKeyNotFoundException
*
* @return mixed
*/
protected function getProvidedDependency($key)
protected function getProvidedDependency($key, $fetch = self::LOADING_EAGER)
{
$container = $this->getContainer();

if ($container->has($key) === false) {
throw new ContainerKeyNotFoundException($this, $key);
}

if ($fetch === static::LOADING_LAZY) {
return fn () => $container->get($key);
}

return $container->get($key);
}

25 changes: 24 additions & 1 deletion src/Spryker/Glue/Kernel/AbstractFactory.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,24 @@ abstract class AbstractFactory
use ClientResolverAwareTrait;
use ContainerMocker;

/**
* Specification:
* - Defines the default behavior of service loading.
* - The service is resolved immediately as part of fetching.
*
* @var string
*/
public const LOADING_EAGER = 'LOADING_EAGER';

/**
* Specification:
* - Defines the optional behavior of service loading.
* - The service is resolved later, when it is actually needed.
*
* @var string
*/
public const LOADING_LAZY = 'LOADING_LAZY';

/**
* @uses \Spryker\Glue\GlueApplication\Plugin\Application\GlueApplicationApplicationPlugin::SERVICE_RESOURCE_BUILDER
*
@@ -71,19 +89,24 @@ protected function createContainerGlobals()

/**
* @param string $key
* @param string $fetch The `LOADING_LAZY` behavior returns the service as closure for later resolving.
*
* @throws \Spryker\Glue\Kernel\Exception\Container\ContainerKeyNotFoundException
*
* @return mixed
*/
protected function getProvidedDependency($key)
protected function getProvidedDependency($key, $fetch = self::LOADING_EAGER)
{
$container = $this->getContainer();

if ($container->has($key) === false) {
throw new ContainerKeyNotFoundException($this, $key);
}

if ($fetch === static::LOADING_LAZY) {
return fn () => $container->get($key);
}

return $container->get($key);
}

25 changes: 24 additions & 1 deletion src/Spryker/Service/Kernel/AbstractServiceFactory.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,24 @@ class AbstractServiceFactory
use BundleConfigResolverAwareTrait;
use ContainerMocker;

/**
* Specification:
* - Defines the default behavior of service loading.
* - The service is resolved immediately as part of fetching.
*
* @var string
*/
public const LOADING_EAGER = 'LOADING_EAGER';

/**
* Specification:
* - Defines the optional behavior of service loading.
* - The service is resolved later, when it is actually needed.
*
* @var string
*/
public const LOADING_LAZY = 'LOADING_LAZY';

/**
* @var array<\Spryker\Service\Kernel\Container>
*/
@@ -35,19 +53,24 @@ public function setContainer(Container $container)

/**
* @param string $key
* @param string $fetch The `LOADING_LAZY` behavior returns the service as closure for later resolving.
*
* @throws \Spryker\Service\Kernel\Exception\Container\ContainerKeyNotFoundException
*
* @return mixed
*/
public function getProvidedDependency($key)
public function getProvidedDependency($key, $fetch = self::LOADING_EAGER)
{
$container = $this->getContainer();

if ($container->has($key) === false) {
throw new ContainerKeyNotFoundException($this, $key);
}

if ($fetch === static::LOADING_LAZY) {
return fn () => $container->get($key);
}

return $container->get($key);
}

94 changes: 94 additions & 0 deletions src/Spryker/Shared/Kernel/StrategyResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Shared\Kernel;

use InvalidArgumentException;

/**
* Specification:
* - The strategy resolver enables the usage of different strategies based on a context selector.
* - The strategies must be of the same type (`S`). The type is defined by the template.
*
* Example:
* ```
* $resolver = new StrategyResolver<ActualStrategyInterface>([ 'context1' => new ActualStrategy1(), 'context2' => fn() => new ActualStrategy2() ]);
* $strategy = $resolver->get('context2'); // returns $ActualStrategy2 : ActualStrategyInterface
* ```
*
* @template S
* @implements \Spryker\Shared\Kernel\StrategyResolverInterface<S>
*/
class StrategyResolver implements StrategyResolverInterface
{
/**
* Specification:
* - The configuration array has the contexts as keys and the corresponding strategy as value.
* - The configuration array values may be callables that return the actual strategy.
* - The configuration array values must be of type S or callable that returns S.
*
* Examples:
* ```
* $strategyConfiguration1 = [ 'context1' => [ new Strategy1() ], 'context2' => fn() => [ new Strategy2() ] ];
* $strategyConfiguration2 = [ 'context1' => new Strategy1(), 'context2' => fn() => new Strategy2() ];
* ```
*
* @var array<string, callable():S | S>
*/
protected array $configuration;

/**
* Specification:
* - The fallback context is used if the searched context is not found in the configuration.
*
* @var string|null
*/
protected ?string $fallbackContext;

/**
* Specification:
* - The configuration array has the contexts as keys and the corresponding strategy as value.
* - The configuration array values may be callables that return the actual strategy.
* - The configuration array values must be of type S or callable that returns S.
*
* Examples:
* ```
* $strategyConfiguration1 = [ 'context1' => [ new Strategy1() ], 'context2' => fn() => [ new Strategy2() ] ];
* $strategyConfiguration2 = [ 'context1' => new Strategy1(), 'context2' => fn() => new Strategy2() ];
* ```
*
* @param array<string, callable():S | S> $strategyConfiguration
* @param string|null $fallbackContext The resolution uses the fallback context if the searched context is not found in the configuration.
*/
public function __construct(array $strategyConfiguration, ?string $fallbackContext = null)
{
$this->configuration = $strategyConfiguration;
$this->fallbackContext = $fallbackContext;
}

/**
* {@inheritDoc}
*
* @param string|null $contextSelector
*
* @throws \InvalidArgumentException
*
* @return S
*/
public function get(?string $contextSelector)
{
$strategy = $this->configuration[$contextSelector]
?? $this->configuration[$this->fallbackContext]
?? throw new InvalidArgumentException("Neither context selector '$contextSelector' nor fallback context '$this->fallbackContext' was found in configuration.");

if (is_callable($strategy)) {
$strategy = $strategy();
}

return $strategy;
}
}
27 changes: 27 additions & 0 deletions src/Spryker/Shared/Kernel/StrategyResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Shared\Kernel;

/**
* @template S
*/
interface StrategyResolverInterface
{
/**
* Specification:
* - If the context selector is not found, the fallback context is used.
* - If the fallback context is not set either, an exception is thrown.
*
* @param string|null $contextSelector
*
* @throws \InvalidArgumentException
*
* @return S
*/
public function get(?string $contextSelector);
}
25 changes: 24 additions & 1 deletion src/Spryker/Yves/Kernel/AbstractFactory.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,24 @@ abstract class AbstractFactory implements FactoryInterface
use BundleConfigResolverAwareTrait;
use ContainerMocker;

/**
* Specification:
* - Defines the default behavior of service loading.
* - The service is resolved immediately as part of fetching.
*
* @var string
*/
public const LOADING_EAGER = 'LOADING_EAGER';

/**
* Specification:
* - Defines the optional behavior of service loading.
* - The service is resolved later, when it is actually needed.
*
* @var string
*/
public const LOADING_LAZY = 'LOADING_LAZY';

/**
* @var \Spryker\Client\Kernel\AbstractClient
*/
@@ -92,19 +110,24 @@ protected function createClientResolver()

/**
* @param string $key
* @param string $fetch The `LOADING_LAZY` behavior returns the service as closure for later resolving.
*
* @throws \Spryker\Yves\Kernel\Exception\Container\ContainerKeyNotFoundException
*
* @return mixed
*/
protected function getProvidedDependency($key)
protected function getProvidedDependency($key, $fetch = self::LOADING_EAGER)
{
$container = $this->getContainer();

if ($container->has($key) === false) {
throw new ContainerKeyNotFoundException($this, $key);
}

if ($fetch === static::LOADING_LAZY) {
return fn () => $container->get($key);
}

return $container->get($key);
}

Original file line number Diff line number Diff line change
@@ -19,6 +19,24 @@ trait BundleDependencyProviderResolverAwareTrait
{
use ContainerMocker;

/**
* Specification:
* - Defines the default behavior of service loading.
* - The service is resolved immediately as part of fetching.
*
* @var string
*/
public const LOADING_EAGER = 'LOADING_EAGER';

/**
* Specification:
* - Defines the optional behavior of service loading.
* - The service is resolved later, when it is actually needed.
*
* @var string
*/
public const LOADING_LAZY = 'LOADING_LAZY';

/**
* @var array<\Spryker\Zed\Kernel\Container>
*/
@@ -38,19 +56,24 @@ public function setContainer(Container $container)

/**
* @param string $key
* @param string $fetch The `LOADING_LAZY` behavior returns the service as closure for later resolving.
*
* @throws \Spryker\Zed\Kernel\Exception\Container\ContainerKeyNotFoundException
*
* @return mixed
*/
public function getProvidedDependency($key)
public function getProvidedDependency($key, $fetch = self::LOADING_EAGER)
{
$container = $this->getContainer();

if ($container->has($key) === false) {
throw new ContainerKeyNotFoundException($this, $key);
}

if ($fetch === static::LOADING_LAZY) {
return fn () => $container->get($key);
}

return $container->get($key);
}

Loading