} return false; } /** * Removes a configuration key. * * @param string $key * * @return self */ public function remove($key) { $success = \Configuration::deleteByName( $key ); if (!$success) { throw new \Exception('Could not update configuration'); } return $this; } /** * Unset configuration value. * * @param string $key * * @return void * * @throws \Exception * * @deprecated since version 1.7.4.0 */ public function delete($key) { $this->remove($key); } /** * {@inheritdoc} */ public function getIterator() { return new \ArrayIterator($this->all()); } /** * {@inheritdoc} */ public function count() { return count($this->all()); } /** * Return if Feature feature is active or not. * * @return bool */ public function featureIsActive() { return Feature::isFeatureActive(); } /** * Return if Combination feature is active or not. * * @return bool */ public function combinationIsActive() { return Combination::isFeatureActive(); } /** * Restrict updates of a piece of configuration to a single shop. * * @param Shop $shop */ public function restrictUpdatesTo(Shop $shop) { $this->shop = $shop; } /** * Get localized configuration in all languages * * @param string $key * @param int|null $shopId * @param int|null $shopGroupId * * @return array Array of langId => localizedConfiguration */ private function getLocalized($key, ?int $shopId = null, ?int $shopGroupId = null) { $configuration = []; foreach (Language::getIDs(false, $shopId ?: false) as $langId) { $configuration[$langId] = ConfigurationLegacy::get($key, $langId, $shopGroupId, $shopId); } return $configuration; } /** * @param ShopConstraint $shopConstraint * * @return int|null */ private function getShopId(ShopConstraint $shopConstraint): ?int { return null !== $shopConstraint->getShopId() ? $shopConstraint->getShopId()->getValue() : null ; } /** * @param ShopConstraint $shopConstraint * * @return int|null */ private function getShopGroupId(ShopConstraint $shopConstraint): ?int { if (null !== $shopConstraint->getShopGroupId()) { return $shopConstraint->getShopGroupId()->getValue(); } elseif (null !== $shopConstraint->getShopId()) { $shopGroupId = Shop::getGroupFromShop((int) $shopConstraint->getShopId()->getValue(), true); // $shopGroupId can not be false, it would mean that the shop group was not found for the given shop if ($shopGroupId === false) { throw new ShopException( sprintf( 'Shop group was not found for the shop with id %d.', $shopConstraint->getShopId()->getValue() ) ); } return (int) $shopGroupId; } return null; } /** * @param string $key * @param ShopConstraint $shopConstraint */ public function deleteFromContext(string $key, ShopConstraint $shopConstraint): void { $shopId = $shopConstraint->getShopId(); $shopGroupId = $shopConstraint->getShopGroupId(); ConfigurationLegacy::deleteFromContext( $key, !empty($shopGroupId) ? $shopGroupId->getValue() : null, !empty($shopId) ? $shopId->getValue() : null ); } /** * @return ShopConstraint */ private function buildShopConstraintFromContext(): ShopConstraint { @trigger_error( 'Not specifying the optional ShopConstraint parameter is deprecated since version 1.7.8.0', E_USER_DEPRECATED ); if (Shop::getContext() === Shop::CONTEXT_SHOP) { return ShopConstraint::shop(Shop::getContextShopID()); } elseif (Shop::getContext() === Shop::CONTEXT_GROUP) { return ShopConstraint::shopGroup(Shop::getContextShopGroupID()); } return ShopConstraint::allShops(); } /** * @param string $key * @param ShopConstraint $shopConstraint * * @return mixed */ private function getStrictValue(string $key, ShopConstraint $shopConstraint) { if (null !== $shopConstraint->getShopId()) { $hasKey = ConfigurationLegacy::hasKey($key, null, null, $shopConstraint->getShopId()->getValue()); return $hasKey ? ConfigurationLegacy::get($key, null, null, $shopConstraint->getShopId()->getValue()) : null; } if (null !== $shopConstraint->getShopGroupId()) { $hasKey = ConfigurationLegacy::hasKey($key, null, $shopConstraint->getShopGroupId()->getValue()); return $hasKey ? ConfigurationLegacy::get($key, null, $shopConstraint->getShopGroupId()->getValue()) : null; } if (ConfigurationLegacy::hasKey($key)) { return ConfigurationLegacy::get($key); } return null; } }