/** * Returns object instance * * @return oxUtilsObject */ public static function getInstance() { // disable caching for test modules if (defined('OXID_PHP_UNIT')) { self::$_instance = null; } if (!self::$_instance instanceof UtilsObject) { $oUtilsObject = new UtilsObject(); // set the not overloaded(by modules) version early so oxnew can be used internally self::$_instance = $oUtilsObject; // null for classNameProvider because it is generated in the constructor $classNameProvider = null; $moduleVariablesCache = $oUtilsObject->oxNew('oxFileCache'); $shopIdCalculator = $oUtilsObject->oxNew('oxShopIdCalculator', $moduleVariablesCache); $subShopSpecific = $oUtilsObject->oxNew('oxSubShopSpecificFileCache', $shopIdCalculator); $moduleVariablesLocator = $oUtilsObject->oxNew('oxModuleVariablesLocator', $subShopSpecific, $shopIdCalculator); $moduleChainsGenerator = $oUtilsObject->oxNew('oxModuleChainsGenerator', $moduleVariablesLocator); //generate UtilsObject again by oxnew to allow overloading by modules self::$_instance = $oUtilsObject->oxNew('oxUtilsObject', $classNameProvider, $moduleChainsGenerator, $shopIdCalculator); } return self::$_instance; }
public function testUtilsObjectConstructedWithCEShopId() { if ($this->getTestConfig()->getShopEdition() == 'EE') { $this->markTestSkipped('This test is for Community/Professional edition only.'); } $expectedShopId = ShopIdCalculator::BASE_SHOP_ID; $utilsObject = new UtilsObject(); $realShopId = $utilsObject->getShopId(); $this->assertSame($expectedShopId, $realShopId); }
/** * Updates or adds new shop configuration parameters to DB. * Arrays must be passed not serialized, serialized values are supported just for backward compatibility. * * @param string $varType Variable Type * @param string $varName Variable name * @param mixed $varVal Variable value (can be string, integer or array) * @param string $shopId Shop ID, default is current shop * @param string $module Module name (empty for base options) */ public function saveShopConfVar($varType, $varName, $varVal, $shopId = null, $module = '') { switch ($varType) { case 'arr': case 'aarr': $value = serialize($varVal); break; case 'bool': //config param $varVal = ($varVal == 'true' || $varVal) && $varVal && strcasecmp($varVal, "false"); //db value $value = $varVal ? "1" : ""; break; case 'num': //config param $varVal = $varVal != '' ? Registry::getUtils()->string2Float($varVal) : ''; $value = $varVal; break; default: $value = $varVal; break; } if (!$shopId) { $shopId = $this->getShopId(); } // Update value only for current shop if ($shopId == $this->getShopId()) { $this->setConfigParam($varName, $varVal); } $db = oxDb::getDb(); $shopIdQuoted = $db->quote($shopId); $moduleQuoted = $db->quote($module); $varNameQuoted = $db->quote($varName); $varTypeQuoted = $db->quote($varType); $varValueQuoted = $db->quote($value); $configKeyQuoted = $db->quote($this->getConfigParam('sConfigKey')); $newOXIDdQuoted = $db->quote(UtilsObject::getInstance()->generateUID()); $query = "delete from oxconfig where oxshopid = {$shopIdQuoted} and oxvarname = {$varNameQuoted} and oxmodule = {$moduleQuoted}"; $db->execute($query); $query = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)\n values({$newOXIDdQuoted}, {$shopIdQuoted}, {$moduleQuoted}, {$varNameQuoted}, {$varTypeQuoted}, ENCODE( {$varValueQuoted}, {$configKeyQuoted}) )"; $db->execute($query); }