Skip to content

Commit

Permalink
TE-9834: Dynamic multi-store: global objects cleanup for Yves (#2061)
Browse files Browse the repository at this point in the history
TE-9834 Dynamic Store Configuration (Cleanup + Deprecation)
  • Loading branch information
Dmytro Dymarchuk authored Oct 29, 2021
1 parent 96a5a4b commit ceed587
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 25 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"spryker/container": "^1.0.0",
"spryker/event-dispatcher-extension": "^1.0.0",
"spryker/kernel": "^3.48.0",
"spryker/locale": "^3.8.0",
"spryker/storage": "^3.4.0",
"spryker/symfony": "^3.5.0",
"spryker/twig": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 SprykerShop\Yves\ShopApplication\Dependency\Client;

class ShopApplicationToLocaleClientBridge implements ShopApplicationToLocaleClientInterface
{
/**
* @var \Spryker\Client\Locale\LocaleClientInterface
*/
protected $localeClient;

/**
* @param \Spryker\Client\Locale\LocaleClientInterface $localeClient
*/
public function __construct($localeClient)
{
$this->localeClient = $localeClient;
}

/**
* @return string
*/
public function getCurrentLocale()
{
return $this->localeClient->getCurrentLocale();
}

/**
* @return array<string>
*/
public function getLocales(): array
{
return $this->localeClient->getLocales();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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 SprykerShop\Yves\ShopApplication\Dependency\Client;

interface ShopApplicationToLocaleClientInterface
{
/**
* @return string
*/
public function getCurrentLocale();

/**
* @return array<string>
*/
public function getLocales(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ protected function setControllerResolver()
*/
protected function setLocale()
{
$store = Store::getInstance();
$store->setCurrentLocale(current($store->getLocales()));
$this->application[self::LOCALE] = $store->getCurrentLocale();
$localeClient = $this->getFactory()->getLocaleClient();
$this->application[self::LOCALE] = $localeClient->getCurrentLocale();

$requestUri = $this->getRequestUri();

if ($requestUri) {
$pathElements = explode('/', trim($requestUri, '/'));
$identifier = $pathElements[0];
if ($identifier !== false && array_key_exists($identifier, $store->getLocales())) {
$store->setCurrentLocale($store->getLocales()[$identifier]);
$this->application[self::LOCALE] = $store->getCurrentLocale();
ApplicationEnvironment::initializeLocale($store->getCurrentLocale());
$locales = $localeClient->getLocales();
if ($identifier !== false && array_key_exists($identifier, $locales)) {
$currentLocale = $locales[$identifier];
$this->application[self::LOCALE] = $currentLocale;
ApplicationEnvironment::initializeLocale($currentLocale);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
namespace SprykerShop\Yves\ShopApplication;

use Spryker\Shared\Kernel\Container\GlobalContainer;
use Spryker\Shared\Kernel\Store;
use Spryker\Yves\Kernel\AbstractBundleDependencyProvider;
use Spryker\Yves\Kernel\Container;
use Spryker\Yves\Kernel\Plugin\Pimple;
use SprykerShop\Yves\ShopApplication\Dependency\Client\ShopApplicationToLocaleClientBridge;
use SprykerShop\Yves\ShopApplication\Dependency\Client\ShopApplicationToLocaleClientInterface;
use SprykerShop\Yves\ShopApplication\Dependency\Service\ShopApplicationToUtilTextServiceBridge;

/**
Expand Down Expand Up @@ -51,22 +52,22 @@ class ShopApplicationDependencyProvider extends AbstractBundleDependencyProvider
/**
* @var string
*/
public const STORE = 'STORE';
public const PLUGINS_FILTER_CONTROLLER_EVENT_SUBSCRIBER = 'PLUGINS_FILTER_CONTROLLER_EVENT_SUBSCRIBER';

/**
* @var string
*/
public const PLUGINS_FILTER_CONTROLLER_EVENT_SUBSCRIBER = 'PLUGINS_FILTER_CONTROLLER_EVENT_SUBSCRIBER';
public const PLUGINS_APPLICATION = 'PLUGINS_APPLICATION';

/**
* @var string
*/
public const PLUGINS_APPLICATION = 'PLUGINS_APPLICATION';
public const PLUGINS_WIDGET_CACHE_KEY_GENERATOR_STRATEGY = 'PLUGINS_WIDGET_CACHE_KEY_GENERATOR_STRATEGY';

/**
* @var string
*/
public const PLUGINS_WIDGET_CACHE_KEY_GENERATOR_STRATEGY = 'PLUGINS_WIDGET_CACHE_KEY_GENERATOR_STRATEGY';
public const CLIENT_LOCALE = 'CLIENT_LOCALE';

/**
* @param \Spryker\Yves\Kernel\Container $container
Expand All @@ -78,8 +79,8 @@ public function provideDependencies(Container $container)
$container = $this->addGlobalContainer($container);
$container = $this->addApplicationPlugin($container);
$container = $this->addGlobalWidgets($container);
$container = $this->addStore($container);
$container = $this->addUtilTextService($container);
$container = $this->addLocaleClient($container);
$container = $this->addFilterControllerEventSubscriberPlugins($container);
$container = $this->addApplicationPlugins($container);
$container = $this->addWidgetCacheKeyGeneratorStrategyPlugins($container);
Expand Down Expand Up @@ -124,10 +125,10 @@ protected function addApplicationPlugin(Container $container)
*
* @return \Spryker\Yves\Kernel\Container
*/
protected function addStore(Container $container)
protected function addUtilTextService(Container $container)
{
$container->set(static::STORE, function () {
return Store::getInstance();
$container->set(static::SERVICE_UTIL_TEXT, function (Container $container) {
return new ShopApplicationToUtilTextServiceBridge($container->getLocator()->utilText()->service());
});

return $container;
Expand All @@ -138,10 +139,10 @@ protected function addStore(Container $container)
*
* @return \Spryker\Yves\Kernel\Container
*/
protected function addUtilTextService(Container $container)
protected function addLocaleClient(Container $container): Container
{
$container->set(static::SERVICE_UTIL_TEXT, function (Container $container) {
return new ShopApplicationToUtilTextServiceBridge($container->getLocator()->utilText()->service());
$container->set(static::CLIENT_LOCALE, function (Container $container): ShopApplicationToLocaleClientInterface {
return new ShopApplicationToLocaleClientBridge($container->getLocator()->locale()->client());
});

return $container;
Expand Down
13 changes: 7 additions & 6 deletions src/SprykerShop/Yves/ShopApplication/ShopApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Spryker\Yves\Kernel\Widget\WidgetContainerInterface;
use Spryker\Yves\Kernel\Widget\WidgetContainerRegistry;
use Spryker\Yves\Kernel\Widget\WidgetFactory as LegacyWidgetFactory;
use SprykerShop\Yves\ShopApplication\Dependency\Client\ShopApplicationToLocaleClientInterface;
use SprykerShop\Yves\ShopApplication\Dependency\Service\ShopApplicationToUtilTextServiceInterface;
use SprykerShop\Yves\ShopApplication\Plugin\ShopApplicationTwigExtensionPlugin;
use SprykerShop\Yves\ShopApplication\Subscriber\ShopApplicationTwigEventSubscriber;
Expand Down Expand Up @@ -171,19 +172,19 @@ public function getGlobalContainer(): ContainerInterface
}

/**
* @return \Spryker\Shared\Kernel\Store
* @return \SprykerShop\Yves\ShopApplication\Dependency\Service\ShopApplicationToUtilTextServiceInterface
*/
public function getStore()
public function getUtilTextService(): ShopApplicationToUtilTextServiceInterface
{
return $this->getProvidedDependency(ShopApplicationDependencyProvider::STORE);
return $this->getProvidedDependency(ShopApplicationDependencyProvider::SERVICE_UTIL_TEXT);
}

/**
* @return \SprykerShop\Yves\ShopApplication\Dependency\Service\ShopApplicationToUtilTextServiceInterface
* @return \SprykerShop\Yves\ShopApplication\Dependency\Client\ShopApplicationToLocaleClientInterface
*/
public function getUtilTextService(): ShopApplicationToUtilTextServiceInterface
public function getLocaleClient(): ShopApplicationToLocaleClientInterface
{
return $this->getProvidedDependency(ShopApplicationDependencyProvider::SERVICE_UTIL_TEXT);
return $this->getProvidedDependency(ShopApplicationDependencyProvider::CLIENT_LOCALE);
}

/**
Expand Down

0 comments on commit ceed587

Please sign in to comment.