Save item collection in store
@see  \Lovata\Toolbox\Tests\Unit\CollectionTest::testSaveMethod()
@link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#saveskeysavedskey
@param string $sKey

@return $this
428666
public function save($sKey)
    {
        if (empty($sKey)) {
            return $this;
        }

        $sKey = static::class.'@'.$sKey;
        CollectionStore::instance()->save($sKey, $this);

        return $this->returnThis();
    }
166034
public function getList($sKey)
    {
        if (empty($sKey)) {
            return [];
        }

        //Get value from storage
        $arValueList = $this->get($sKey);
        if (empty($arValueList) || !is_array($arValueList)) {
            $arValueList = [];
        }

        return $arValueList;
    }
1174301
public function get($sKey = '')
    {
        if (empty($sKey)) {
            return $this->store;
        } else {
            return isset($this->store[$sKey]) ? $this->store[$sKey] : null;
        }
    }
150137
public function saveKeyValues(Entity $entity, array $keys)
    {
        $event = $this->_table->dispatchEvent('Model.beforeSaveKeyValues', compact('entity'));

        if ($event->isStopped()) {
            return $event->result;
        }

        if (!empty($event->result)) {
            $entity = $event->result;
        }

        $fields = $this->config('fields');

        if ($entity->has($fields['key']) && $entity->has($fields['value'])) {
            return true;
        }

        $mappedIds = $this->_getFieldToIdMapping($keys);

        $entities = [];
        foreach ($entity->toArray() as $key => $value) {
            if ($this->_table->hasField($key)) {
                continue;
            }

            $serialized = false;
            if (in_array($key, $this->config('serializeFields'))) {
                $value = serialize($value);
                $serialized = true;
            }

            /** @var Setting $kvEntity */
            $kvEntity = $this->_table->newEntity([
                'scope' => $this->config('scope'),
                $this->config('fields.key') => $key,
                $this->config('fields.value') => $value,
                'serialized' => $serialized
            ]);

            if (($existingId = Hash::get($mappedIds, $key)) !== null) {
                $kvEntity->id = $existingId;
            }

            $entities[] = $kvEntity;
        }

        $result = $this->_table->connection()->transactional(function () use ($entities) {
            foreach ($entities as $e) {
                $this->_table->save($e);
            }
        });

        return ($result !== false);
    }
1182671
public function run( $ckey ) {

		$meta = new Meta();

		// Filter reserved keys
		$validKey = !in_array( $ckey, [ 'data', 'attributes', 'config', 'settings', 'plugins' ] );

		if( $validKey && $meta->load( Yii::$app->request->post(), 'Meta' ) && $meta->validate() ) {

			// Save Meta
			$this->modelService->updateDataCustomObj( $this->model, $ckey, $meta );

			// Trigger Ajax Success
			return AjaxUtil::generateSuccess( Yii::$app->coreMessage->getMessage( CoreGlobal::MESSAGE_REQUEST ), $meta );
		}

		// Generate Errors
		$errors = AjaxUtil::generateErrorMessage( $meta );

		// Trigger Ajax Failure
		return AjaxUtil::generateFailure( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_REQUEST ), $errors );
	}
184299
private static KeyStore saveCertificateAsKeyStore(KeyStore existingKeyStore, boolean deleteOnExit, String keyStoreFileName, String certificationAlias, Key privateKey, char[] keyStorePassword, Certificate[] chain, X509Certificate caCert) {
        try {
            KeyStore keyStore = existingKeyStore;
            if (keyStore == null) {
                // create new key store
                keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
                keyStore.load(null, keyStorePassword);
            }

            // add certificate
            try {
                keyStore.deleteEntry(certificationAlias);
            } catch (KeyStoreException kse) {
                // ignore as may not exist in keystore yet
            }
            keyStore.setKeyEntry(certificationAlias, privateKey, keyStorePassword, chain);

            // add CA certificate
            try {
                keyStore.deleteEntry(KEY_STORE_CA_ALIAS);
            } catch (KeyStoreException kse) {
                // ignore as may not exist in keystore yet
            }
            keyStore.setCertificateEntry(KEY_STORE_CA_ALIAS, caCert);

            // save as JKS file
            String keyStoreFileAbsolutePath = new File(keyStoreFileName).getAbsolutePath();
            try (FileOutputStream fileOutputStream = new FileOutputStream(keyStoreFileAbsolutePath)) {
                keyStore.store(fileOutputStream, keyStorePassword);
                MOCK_SERVER_LOGGER.trace("Saving key store to file [" + keyStoreFileAbsolutePath + "]");
            }
            if (deleteOnExit) {
                new File(keyStoreFileAbsolutePath).deleteOnExit();
            }
            return keyStore;
        } catch (Exception e) {
            throw new RuntimeException("Exception while saving KeyStore", e);
        }
    }
754487
protected function updateMap(array &$aMap, string $sKey, array $aValues): self
    {
        if (!array_key_exists($sKey, $aMap)) {
            $aMap[$sKey] = [];
        }

        $aMap[$sKey] = array_values(
            array_unique(
                array_merge(
                    $aMap[$sKey],
                    $aValues
                )
            )
        );

        return $this;
    }
100647
public function getCacheMeta($sKey)
    {
        return isset($this->_aFileCacheMeta[$sKey]) ? $this->_aFileCacheMeta[$sKey] : false;
    }
934477
public function set($key, $data) {
        if (!is_array($key)) {
            $record = array(
                'key' => $key
            );
        } else {
            $record = $key;
        }
        $record['data'] = serialize($data);
        $options = array('upsert' => true);

        $w = $this->usesafe ? 1 : 0;
        $wc = new MongoDB\Driver\WriteConcern($w);

        $options['writeConcern'] = $wc;

        $this->delete($key);
        try {
            $this->collection->insertOne($record, $options);
        } catch (MongoDB\Exception\Exception $e) {
            return false;
        }

        return true;
    }
596041
public function removeFromList($sKey, $sValue)
    {
        if (empty($sKey) || empty($sValue)) {
            return;
        }

        //Get value from storage
        $arValueList = $this->getList($sKey);

        $iPosition = array_search($sValue, $arValueList);
        if ($iPosition === false) {
            return;
        }

        unset($arValueList[$iPosition]);
        $arValueList = array_values($arValueList);

        $this->put($sKey, $arValueList);
    }
1137895
public function save(){

            $this->parent->__set($this->key, $this->data);
            $this->parent->save();

            return $this;

        }
602355
public function delete(string $sKey): bool
    {
        if (array_key_exists($sKey, $this->aCookies) && setcookie($sKey, '', 1)) {
            unset($this->aCookies[$sKey]);
            return true;
        }

        return false;
    }
375880
protected function saveRelationsAfterHasOne($key)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($this);
        $relation = $class::getRelations()[$key];
        $column = $class::getRelationLinkName($relation);

        /** @var \T4\Orm\Model $oldSubModel */
        $oldSubModel = $this->getRelationLazy($key);

        /** @var \T4\Orm\Model $newSubModel */
        $newSubModel = $this->{$key};

        if ( !empty($oldSubModel) && (empty($newSubModel) || $newSubModel->getPk() != $oldSubModel->getPk()) ) {
            $oldSubModel->{$column} = null;
            $oldSubModel->save();
        }

        if ( !empty($newSubModel) ) {
            $newSubModel->{$column} = $this->getPk();
            $newSubModel->save();
        }
    }
1148035
public function IsReservedKey( $sKey )
	{
		$bRet	= false;

		if ( CLib::IsExistingString( $sKey, true ) )
		{
			$sKey	= strtolower( trim( $sKey ) );
			$bRet	= in_array( $sKey, self::ARR_RESERVED_KEYS );
		}

		return $bRet;
	}
594052
private function saveKeyToFile($key)
    {
        $tmpDir = sys_get_temp_dir();
        $keyPath = $tmpDir . '/' . sha1($key) . '.key';

        if (file_exists($keyPath)) {
            return 'file://' . $keyPath;
        }

        if (!touch($keyPath)) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException(sprintf('"%s" key file could not be created', $keyPath));
            // @codeCoverageIgnoreEnd
        }

        if (file_put_contents($keyPath, $key) === false) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException(sprintf('Unable to write key file to temporary directory "%s"', $tmpDir));
            // @codeCoverageIgnoreEnd
        }

        if (chmod($keyPath, 0600) === false) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException(sprintf('The key file "%s" file mode could not be changed with chmod to 600', $keyPath));
            // @codeCoverageIgnoreEnd
        }

        return 'file://' . $keyPath;
    }
1331389
public static function Get($sKey){
            $oThis = self::CreateInstanceIfNotExists();

            if($oThis->bStarted)
                return (!empty($_SESSION[$oThis->sName][$sKey])) ? $_SESSION[$oThis->sName][$sKey] : false;
            else
                return null;
        }
1228894
public static function add(string $sKey, $mValue, int $iExpire = 86400) {
		return static::conn()->add($sKey, $mValue, $iExpire);
	}