/
home
/
sharedstore
/
public_html
/
prestashop.sharedstore.ma
/
src
/
Adapter
/
/home/sharedstore/public_html/prestashop.sharedstore.ma/src/Adapter
mkdir
upload
Name
Size
Mode
Actions
Address/
-
0755
rm
Admin/
-
0755
rm
Assets/
-
0755
rm
Attachment/
-
0755
rm
Attribute/
-
0755
rm
AttributeGroup/
-
0755
rm
Backup/
-
0755
rm
BestSales/
-
0755
rm
Cache/
-
0755
rm
Carrier/
-
0755
rm
Cart/
-
0755
rm
CartRule/
-
0755
rm
CatalogPriceRule/
-
0755
rm
Category/
-
0755
rm
CMS/
-
0755
rm
Configuration/
-
0755
rm
Contact/
-
0755
rm
Container/
-
0755
rm
Converter/
-
0755
rm
Country/
-
0755
rm
CreditSlip/
-
0755
rm
Currency/
-
0755
rm
Customer/
-
0755
rm
Debug/
-
0755
rm
Domain/
-
0755
rm
Email/
-
0755
rm
Employee/
-
0755
rm
EntityTranslation/
-
0755
rm
Feature/
-
0755
rm
File/
-
0755
rm
Form/
-
0755
rm
Geolocation/
-
0755
rm
Grid/
-
0755
rm
Group/
-
0755
rm
Hook/
-
0755
rm
Hosting/
-
0755
rm
Image/
-
0755
rm
Import/
-
0755
rm
Invoice/
-
0755
rm
Kpi/
-
0755
rm
Language/
-
0755
rm
Localization/
-
0755
rm
Mail/
-
0755
rm
MailTemplate/
-
0755
rm
Manufacturer/
-
0755
rm
Media/
-
0755
rm
Meta/
-
0755
rm
Module/
-
0755
rm
NewProducts/
-
0755
rm
Notification/
-
0755
rm
Number/
-
0755
rm
OptionalFeatures/
-
0755
rm
Order/
-
0755
rm
OrderMessage/
-
0755
rm
OrderReturn/
-
0755
rm
OrderReturnState/
-
0755
rm
OrderState/
-
0755
rm
Pack/
-
0755
rm
PDF/
-
0755
rm
Preferences/
-
0755
rm
Presenter/
-
0755
rm
PricesDrop/
-
0755
rm
Product/
-
0755
rm
Profile/
-
0755
rm
Requirement/
-
0755
rm
Routes/
-
0755
rm
Routing/
-
0755
rm
Search/
-
0755
rm
SearchEngine/
-
0755
rm
Security/
-
0755
rm
Session/
-
0755
rm
Shop/
-
0755
rm
Smarty/
-
0755
rm
SpecificPrice/
-
0755
rm
SqlManager/
-
0755
rm
State/
-
0755
rm
Store/
-
0755
rm
Supplier/
-
0755
rm
Support/
-
0755
rm
System/
-
0755
rm
Tab/
-
0755
rm
Tax/
-
0755
rm
TaxRulesGroup/
-
0755
rm
Theme/
-
0755
rm
Title/
-
0755
rm
Translations/
-
0755
rm
Twig/
-
0755
rm
Upload/
-
0755
rm
Warehouse/
-
0755
rm
Webservice/
-
0755
rm
Zone/
-
0755
rm
AbstractObjectModelValidator.php
3719
0644
edit
dl
rm
AddressFactory.php
2051
0644
edit
dl
rm
CacheManager.php
1450
0644
edit
dl
rm
ClassLang.php
1716
0644
edit
dl
rm
CombinationDataProvider.php
8580
0644
edit
dl
rm
Configuration.php
13959
0644
edit
dl
rm
ContainerBuilder.php
8966
0644
edit
dl
rm
ContainerFinder.php
2398
0644
edit
dl
rm
ContextStateManager.php
10336
0644
edit
dl
rm
CoreException.php
1229
0644
edit
dl
rm
Database.php
2698
0644
edit
dl
rm
EntityMapper.php
5573
0644
edit
dl
rm
EntityMetaDataRetriever.php
2034
0644
edit
dl
rm
Environment.php
2670
0644
edit
dl
rm
GeneralConfiguration.php
4331
0644
edit
dl
rm
HookManager.php
3969
0644
edit
dl
rm
ImageManager.php
4320
0644
edit
dl
rm
LegacyContext.php
11008
0644
edit
dl
rm
LegacyContextLoader.php
4262
0644
edit
dl
rm
LegacyHookSubscriber.php
4780
0644
edit
dl
rm
LegacyLogger.php
4898
0644
edit
dl
rm
ObjectPresenter.php
1327
0644
edit
dl
rm
RoundingMapper.php
2523
0644
edit
dl
rm
ServiceLocator.php
2065
0644
edit
dl
rm
StockManager.php
7914
0644
edit
dl
rm
SymfonyContainer.php
1970
0644
edit
dl
rm
Tools.php
5932
0644
edit
dl
rm
Validate.php
3833
0644
edit
dl
rm
Edit:
/home/sharedstore/public_html/prestashop.sharedstore.ma/src/Adapter/ContextStateManager.php
(10336B)
<?php /** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors <contact@prestashop.com> * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Adapter; use Cart; use Context; use Country; use Currency; use Customer; use Language; use Shop; /** * Allows manipulating context state. * This was adapted for specific broken legacy use cases when the previous state of context must be restored after some actions. * * e.g. order creation from back office. * Legacy requires Context properties (currency, country etc.) instead of using cart properties * so some context props must be changed for a while and then restored to previous state. */ final class ContextStateManager { private const MANAGED_FIELDS = [ 'cart', 'country', 'currency', 'language', 'customer', 'shop', 'shopContext', ]; /** * @var LegacyContext */ private $legacyContext; /** * @var array|null */ private $contextFieldsStack = null; /** * @param LegacyContext $legacyContext */ public function __construct(LegacyContext $legacyContext) { $this->legacyContext = $legacyContext; } /** * @return Context */ public function getContext(): Context { return $this->legacyContext->getContext(); } /** * Sets context cart and saves previous value * * @param Cart|null $cart * * @return $this */ public function setCart(?Cart $cart): self { $this->saveContextField('cart'); $this->getContext()->cart = $cart; return $this; } /** * Sets context country and saves previous value * * @param Country|null $country * * @return $this */ public function setCountry(?Country $country): self { $this->saveContextField('country'); $this->getContext()->country = $country; return $this; } /** * Sets context currency and saves previous value * * @param Currency|null $currency * * @return $this */ public function setCurrency(?Currency $currency): self { $this->saveContextField('currency'); $this->getContext()->currency = $currency; return $this; } /** * Sets context language and saves previous value * * @param Language|null $language * * @return $this */ public function setLanguage(?Language $language): self { $this->saveContextField('language'); $this->getContext()->language = $language; if ($language) { $this->getContext()->getTranslator()->setLocale($language->locale); } return $this; } /** * Sets context customer and saves previous value * * @param Customer|null $customer * * @return $this */ public function setCustomer(?Customer $customer): self { $this->saveContextField('customer'); $this->getContext()->customer = $customer; return $this; } /** * Sets context shop and saves previous value * * @param Shop $shop * * @return $this * * @throws \PrestaShopException */ public function setShop(Shop $shop): self { $this->saveContextField('shop'); $this->getContext()->shop = $shop; Shop::setContext(Shop::CONTEXT_SHOP, $shop->id); return $this; } /** * Sets context shop and saves previous value * * @param int $shopContext * @param int|null $shopContextId * * @return $this * * @throws \PrestaShopException */ public function setShopContext(int $shopContext, ?int $shopContextId = null): self { $this->saveContextField('shopContext'); if ($shopContext === Shop::CONTEXT_SHOP) { $this->getContext()->shop = new Shop($shopContextId); } Shop::setContext($shopContext, $shopContextId); return $this; } /** * Restores context to a state before changes * * @return self */ public function restorePreviousContext(): self { $stackFields = array_keys($this->contextFieldsStack[$this->getCurrentStashIndex()]); foreach ($stackFields as $fieldName) { $this->restoreContextField($fieldName); } $this->removeLastSavedContext(); return $this; } /** * Saves the current overridden fields in the context, allowing you to set new values to the * current Context. Next time you call restorePreviousContext the context will be refilled with * the values that were saved during this call. * * This is useful if several services use the ContextStateManager, this way if every service * saved the context before modifying it there is no risk of removing previous modifications * when you restore the context, because the different states have been stacked. * * @return $this */ public function saveCurrentContext(): self { // No context field has been overridden yet so no need to save/stack it if (null === $this->contextFieldsStack) { return $this; } // Saves all the fields that have not been overridden foreach (self::MANAGED_FIELDS as $contextField) { $this->saveContextField($contextField); } // Add a new empty layer $this->contextFieldsStack[] = []; return $this; } /** * Return the stack of modified fields * If it's null, no context field has been overridden * * @return array|null */ public function getContextFieldsStack(): ?array { return $this->contextFieldsStack; } /** * Save context field into local array * * @param string $fieldName */ private function saveContextField(string $fieldName) { $currentStashIndex = $this->getCurrentStashIndex(); // NOTE: array_key_exists important here, isset cannot be used because it would not detect if null is stored if (!array_key_exists($fieldName, $this->contextFieldsStack[$currentStashIndex])) { switch ($fieldName) { case 'shop': case 'shopContext': $this->contextFieldsStack[$currentStashIndex]['shop'] = $this->getContext()->shop; $this->contextFieldsStack[$currentStashIndex]['shopContext'] = Shop::getContext(); break; default: $this->contextFieldsStack[$currentStashIndex][$fieldName] = $this->getContext()->$fieldName; } } } /** * Restores context saved value, and remove save value from local array * * @param string $fieldName */ private function restoreContextField(string $fieldName): void { $currentStashIndex = $this->getCurrentStashIndex(); // NOTE: array_key_exists important here, isset cannot be used because it would not detect if null is stored if (array_key_exists($fieldName, $this->contextFieldsStack[$currentStashIndex])) { if ('shop' === $fieldName) { $this->restoreShopContext($currentStashIndex); } if ('language' === $fieldName && $this->contextFieldsStack[$currentStashIndex][$fieldName] instanceof Language) { $this->getContext()->getTranslator()->setLocale($this->contextFieldsStack[$currentStashIndex][$fieldName]->locale); } $this->getContext()->$fieldName = $this->contextFieldsStack[$currentStashIndex][$fieldName]; unset($this->contextFieldsStack[$currentStashIndex][$fieldName]); } } /** * Returns the index of the current stack * * @return int */ private function getCurrentStashIndex(): int { // If this is the first time the index is needed we need to init the stack if (null === $this->contextFieldsStack) { $this->contextFieldsStack = [[]]; } return array_key_last($this->contextFieldsStack); } /** * Restore the ShopContext, this is used when Shop has been overridden, we need to * restore context->shop of course But also the static fields in Shop class * * @param int $currentStashIndex */ private function restoreShopContext(int $currentStashIndex): void { $shop = $this->contextFieldsStack[$currentStashIndex]['shop']; $shopId = $shop instanceof Shop ? $shop->id : null; $shopContext = $this->contextFieldsStack[$currentStashIndex]['shopContext']; if (null !== $shopContext) { Shop::setContext($shopContext, $shopId); } unset($this->contextFieldsStack[$currentStashIndex]['shopContext']); } /** * Removes the last saved stashed context, in case this method is called too many times * we always keep one layer available */ private function removeLastSavedContext(): void { array_pop($this->contextFieldsStack); // When all layers have been popped we restore the initial null value if (empty($this->contextFieldsStack)) { $this->contextFieldsStack = null; } } }
Save
cmd:
run