This method is reloaded for on-set validation and sanitizing
@param string $key
@param mixed $val
@throws \Runn\Core\Exceptions
490767
protected function innerSet($key, $val)
    {
        $setMethod = 'set' . ucfirst($key);
        if ( !in_array($key, $this->notsetters()) && method_exists($this, $setMethod) ) {
            $this->$setMethod($val);
        } else {

            $validateMethod = 'validate' . ucfirst($key);

            if (method_exists($this, $validateMethod)) {

                $errors = new Exceptions();

                try {
                    $validateResult = $this->$validateMethod($val);
                    if (false === $validateResult) {
                        return;
                    }
                    if ($validateResult instanceof \Generator) {
                        foreach ($validateResult as $error) {
                            if ($error instanceof \Throwable) {
                                $errors->add($error);
                            }
                        }
                    }
                } catch (\Throwable $e) {
                    $errors->add($e);
                }

                if (!$errors->empty()) {
                    throw $errors;
                }

            }

            $sanitizeMethod = 'sanitize' . ucfirst($key);
            if (method_exists($this, $sanitizeMethod)) {
                $val = $this->$sanitizeMethod($val);
            }

            if (null === $key) {
                $this->__data[] = $val;
            } else {
                $this->__data[$key] = $val;
            }
        }
    }
1144920
public function setDefaultData($key, $val = null)
    {
        if(is_array($key))
        {
            foreach($key as $k=>$v)
            {
                $this->setDefaultData($k, $v);
            }
        }
        else
        {
            $this->defaultData[$key] = $val;
        }

        return $this;
    }
867181
protected function form($key, $val)
    {
        $type = null;
        $type = strtolower(__FUNCTION__);

        $this->attributes[self::$formHolder[self::$formName]][$key] =
            "<$type name='".self::$formName."' ".$this->attributes($val).'>'.PHP_EOL;
    }
839071
function update( $key, $val = false ) {
			if ( ! is_array( $key ) ) {
				$key = array( $key => $val );
			}

			$is_updated = false;

			foreach ( $key as $k => $v ) {
				if ( $this->{$k} === $v ) {
					continue;
				}

				if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
				       ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
				     $this->{$k} == $v
				) {
					continue;
				}

				// Update value.
				$this->{$k} = $v;

				$is_updated = true;
			}

			$this->_is_updated = $is_updated;

			return $is_updated;
		}
1078004
protected function validateKey(/*# string */ &$key)
    {
        // validate key
        if (is_string($key)) {
            $key = trim($key);
            return;
        }

        // throw exception
        throw new InvalidArgumentException(
            Message::get(Message::CACHE_INVALID_KEY, $key),
            Message::CACHE_INVALID_KEY
        );
    }
610212
public function addMapOption($key, $val)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Setting key must be a string.'
            );
        }

        // Make sure default options are loaded.
        if ($this->mapOptions === null) {
            $this->mapOptions();
        }

        $this->mapOptions[$key] = $val;

        if ($key === 'api_key') {
            $this->setApiKey($val);
        }

        return $this;
    }
396412
public function _setInit($key = null, $val = null)
    {
        if (is_null($key)) {
            $this->_init = array();
        } elseif (is_null($val)) {
            unset($this->_init[$key]);
        } else {
            switch ($key) {
            case 'capability':
                if ($ci = $this->getParam('capability_ignore')) {
                    $ignored = array();

                    foreach ($ci as $val2) {
                        $c = explode('=', $val2);

                        if ($val->query($c[0], isset($c[1]) ? $c[1] : null)) {
                            $ignored[] = $val2;
                            $val->remove($c[0], isset($c[1]) ? $c[1] : null);
                        }
                    }

                    if ($this->_debug->debug && !empty($ignored)) {
                        $this->_debug->info(sprintf(
                            'CONFIG: IGNORING these IMAP capabilities: %s',
                            implode(', ', $ignored)
                        ));
                    }
                }

                $val->attach($this);
                break;
            }

            /* Nothing has changed. */
            if (isset($this->_init[$key]) && ($this->_init[$key] === $val)) {
                return;
            }

            $this->_init[$key] = $val;
        }

        $this->changed = true;
    }
485551
public static function setEnv($key, $val)
    {
        if (self::getLoader()->overloader == false) {
            if(self::getEnv($key)) {
                return;
            }
        }
        putenv("{$key}={$val}");
        $_ENV[$key] = $val;
        $_SERVER[$key] = $val;
    }
515105
public function addSelectizeOption($key, $val)
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(
                'Setting key must be a string.'
            );
        }

        // Make sure default options are loaded.
        if ($this->selectizeOptions === null) {
            $this->selectizeOptions();
        }

        $this->selectizeOptions[$key] = $val;

        return $this;
    }
1202588
public function set($key, $value)
    {
        if (!$key)
        {
            throw new Exception('key may not be null.');
        }
        if (is_array($value))
        {
            throw new Exception('Must use setArray() or setAssociativeArray() for this value.');
        }
        $this->_performOperation($key, new SetOperation($value));
    }
1035849
function set($key, $val) {
		if ($key == '_id' && $this->dbsType == 'sql')
			$key = $this->primary;
		$fields = $this->fieldConf;
		unset($this->fieldsCache[$key]);
		// pre-process if field config available
		if (!empty($fields) && isset($fields[$key]) && is_array($fields[$key])) {
			// handle relations
			if (isset($fields[$key]['belongs-to-one'])) {
				// one-to-many, one-to-one
				if (is_null($val))
					$val = NULL;
				elseif (is_object($val) &&
					!($this->dbsType=='mongo' && (
						($this->db->legacy() && $val instanceof \MongoId) ||
						(!$this->db->legacy() && $val instanceof \MongoDB\BSON\ObjectId)))) {
					// fetch fkey from mapper
					if (!$val instanceof Cortex || $val->dry())
						trigger_error(self::E_INVALID_RELATION_OBJECT,E_USER_ERROR);
					else {
						$relConf = $fields[$key]['belongs-to-one'];
						$rel_field = (is_array($relConf) ? $relConf[1] : '_id');
						$val = $val->get($rel_field,true);
					}
				} elseif ($this->dbsType == 'mongo' && (($this->db->legacy() && !$val instanceof \MongoId)
						|| (!$this->db->legacy() && !$val instanceof \MongoDB\BSON\ObjectId)))
					$val = $this->db->legacy() ? new \MongoId($val) : new \MongoDB\BSON\ObjectId($val);
			} elseif (isset($fields[$key]['has-one'])){
				$relConf = $fields[$key]['has-one'];
				if (is_null($val)) {
					$val = $this->get($key);
					$val->set($relConf[1],NULL);
				} else {
					if (!$val instanceof Cortex) {
						$rel = $this->getRelInstance($relConf[0],null,$key);
						$rel->load(array('_id = ?', $val));
						$val = $rel;
					}
					$val->set($relConf[1], $this->_id);
				}
				$this->saveCsd[$key] = $val;
				return $val;
			} elseif (isset($fields[$key]['belongs-to-many'])) {
				// many-to-many, unidirectional
				$fields[$key]['type'] = self::DT_JSON;
				$relConf = $fields[$key]['belongs-to-many'];
				$rel_field = (is_array($relConf) ? $relConf[1] : '_id');
				$val = $this->getForeignKeysArray($val, $rel_field, $key);
			}
			elseif (isset($fields[$key]['has-many'])) {
				$relConf = $fields[$key]['has-many'];
				// many-to-many, bidirectional
				// many-to-one, inverse
				if ($relConf['hasRel'] == 'has-many'
					|| $relConf['hasRel'] == 'belongs-to-one') {
					// custom setter
					$val = $this->emit('set_'.$key, $val);
					$val = $this->getForeignKeysArray($val,'_id',$key);
					if (empty($val) && is_array($val))
						$val=new CortexCollection();
					$this->saveCsd[$key] = $val; // array of keys
					$this->fieldsCache[$key] = $val;
					return $val;
				}
			}
			// add nullable polyfill
			if ($val === NULL && ($this->dbsType == 'jig' || $this->dbsType == 'mongo')
				&& array_key_exists('nullable', $fields[$key]) && $fields[$key]['nullable'] === false)
				trigger_error(sprintf(self::E_NULLABLE_COLLISION,$key),E_USER_ERROR);
			// MongoId shorthand
			if ($this->dbsType == 'mongo' && (($this->db->legacy() && !$val instanceof \MongoId)
					|| (!$this->db->legacy() && !$val instanceof \MongoDB\BSON\ObjectId))) {
				if ($key == '_id')
					$val = $this->db->legacy() ? new \MongoId($val) : new \MongoDB\BSON\ObjectId($val);
				elseif (preg_match('/INT/i',$fields[$key]['type'])
					&& !isset($fields[$key]['relType']))
					$val = (int) $val;
			}
			// cast boolean
			if (preg_match('/BOOL/i',$fields[$key]['type'])) {
				$val = !$val || $val==='false' ? false : (bool) $val;
				if ($this->dbsType == 'sql')
					$val = (int) $val;
			}
			// custom setter
			$val = $this->emit('set_'.$key, $val);
			// clean datetime
			if (isset($fields[$key]['type']) && empty($val) &&
				in_array($fields[$key]['type'], [Schema::DT_DATE,Schema::DT_DATETIME])
			)
				$val=NULL;
			// convert array content
			if (is_array($val) && $this->dbsType == 'sql') {
				if ($fields[$key]['type']==self::DT_SERIALIZED)
					$val=serialize($val);
				elseif ($fields[$key]['type']==self::DT_JSON)
					$val=json_encode($val);
				else
					trigger_error(sprintf(self::E_ARRAY_DATATYPE,$key),E_USER_ERROR);
			}
		} else {
			// custom setter
			$val = $this->emit('set_'.$key, $val);
		}
		// fluid SQL
		if ($this->fluid && $this->dbsType == 'sql') {
			$schema = new Schema($this->db);
			$table = $schema->alterTable($this->table);
			// add missing field
			if (!in_array($key,$table->getCols())) {
				// determine data type
				if (isset($this->fieldConf[$key]) && isset($this->fieldConf[$key]['type']))
					$type = $this->fieldConf[$key]['type'];
				elseif (is_int($val)) $type = $schema::DT_INT;
				elseif (is_double($val)) $type = $schema::DT_DOUBLE;
				elseif (is_float($val)) $type = $schema::DT_FLOAT;
				elseif (is_bool($val)) $type = $schema::DT_BOOLEAN;
				elseif (strlen($val)>10 && strtotime($val)) $type = $schema::DT_DATETIME;
				elseif (date('Y-m-d H:i:s', strtotime($val)) == $val) $type = $schema::DT_DATETIME;
				elseif (date('Y-m-d', strtotime($val)) == $val) $type = $schema::DT_DATE;
				elseif (\UTF::instance()->strlen($val)<=255) $type = $schema::DT_VARCHAR256;
				else $type = $schema::DT_TEXT;
				$table->addColumn($key)->type($type);
				$table->build();
				// update mapper fields
				$newField = $table->getCols(true);
				$newField = $newField[$key];
				$fields = $this->mapper->schema();
				$fields[$key] = $newField + array('value'=>NULL,'initial'=>NULL,'changed'=>NULL);
				$this->mapper->schema($fields);
			}
		}
		return $this->mapper->set($key, $val);
	}
458478
static public function set(&$arr, $key, $val)
    {
        $arr instanceof \ArrayAccess || is_array($arr) or \PhpBoot\abort(new \InvalidArgumentException('the first param require array or object of ArrayAccess'));
        $keys = explode('.', $key);
        $keys = array_reverse($keys);
        $cur = &$arr;
        while($p = array_pop($keys)){
            $cur instanceof \ArrayAccess || is_array($cur) or \PhpBoot\abort(new \InvalidArgumentException('array or object of ArrayAccess required'));
            if(!isset($cur[$p])){
                if(count($keys) == 0){
                    $cur[$p] = $val;
                }else{
                    $cur[$p] = [];
                }
            }else{
                if(count($keys) == 0){
                    $cur[$p] = $val;
                }
            }
            $cur = &$cur[$p];
        }
    }
944932
public function config($key, $val = null, $default = null)
    {
        if ($val == null) {
            return Config::get($key, $default);
        } else {
            Config::set($key, $val);
        }
    }
1206537
public function set($key, $val, $ttl = null)
    {
        $this->throwInvalidStringArgumentException($key);

        $this->cache[$key] = $val;

        return true;
    }
469911
public static function set($name, $val)
    {

        if (!is_string($name)) {
            throw new \Exception('Cache key must be a string.');
        }

        // Connect if not connected
        if (self::$config['memcached']['enabled']) {
            self::memcachedConnect();
        }

        if (is_null($val)) {
            // If $val is null, remove from cache
            unset(self::$cache[$name]);

            // Remove from memcached
            if (self::$config['memcached']['enabled']) {
                self::$memcached->delete($name);
            }
        } else {
            // Store in php-memory cache
            self::$cache[$name] = $val;

            // Store in memcached
            if (self::$config['memcached']['enabled']) {
                self::$memcached->set($name, $val);
            }
        }
    }
1277692
final public function config(string $key, $val) {
		if ($this->request_initted)
			return $this;
		switch ($key) {
			case 'home':
				$this->config_home($val);
				return $this;
			case 'host':
				$this->config_host($val);
				return $this;
			case 'shutdown':
				$this->auto_shutdown = (bool)$val;
				return $this;
			case 'logger':
				if ($val instanceof Logger) {
					self::$logger = $val;
					self::$logger->debug('Router: started.');
				}
				return $this;
		}
		self::$logger->warning(
			"Router: invalid configuration key: '$key'.");
		return $this;
	}
275881
function set($key,$val) {
		if (array_key_exists($key,$this->fields)) {
			$val=is_null($val) && $this->fields[$key]['nullable']?
				NULL:$this->db->value($this->fields[$key]['pdo_type'],$val);
			if ($this->fields[$key]['initial']!==$val ||
				$this->fields[$key]['default']!==$val && is_null($val))
				$this->fields[$key]['changed']=TRUE;
			return $this->fields[$key]['value']=$val;
		}
		// Adjust result on existing expressions
		if (isset($this->adhoc[$key]))
			$this->adhoc[$key]['value']=$val;
		elseif (is_string($val))
			// Parenthesize expression in case it's a subquery
			$this->adhoc[$key]=['expr'=>'('.$val.')','value'=>NULL];
		else
			$this->props[$key]=$val;
		return $val;
	}