Parse value with specific definition in $attrs

@param string $key key
@param mixed $value value

@throws Exception\InvalidDataTypeException
@return mixed
199371
public function parseValue($key, $value)
    {
        $attrs = $this->getAttrs();

        if (!isset($attrs[$key]) && is_object($value)) {
            // Handle dates
            if (!$value instanceof \MongoDate
                && !$value instanceof \MongoId
                && !$value instanceof \MongoDBRef) {

                if ($value instanceof \DateTime) {
                    $value = new \MongoDate($value->getTimestamp());
                } else if (method_exists($value, 'toArray')) {
                    $value = (array) $value->toArray();
                } elseif (method_exists($value, 'to_array')) {
                    $value = (array) $value->to_array();
                }else{
                    //ingore this object when saving
                    $this->ignoreData[$key] = $value;
                }
            }
        } elseif (isset($attrs[$key]) && isset($attrs[$key]['type'])) {


            switch ($attrs[$key]['type']) {
                case self::DATA_TYPE_INT:
                case self::DATA_TYPE_INTEGER:
                    $value = (integer) $value;
                    break;
                case self::DATA_TYPE_STR:
                case self::DATA_TYPE_STRING:
                    $value = (string) $value;
                    break;
                case self::DATA_TYPE_FLT:
                case self::DATA_TYPE_FLOAT:
                case self::DATA_TYPE_DBL;
                case self::DATA_TYPE_DOUBLE:
                    $value = (float) $value;
                    break;
                case self::DATA_TYPE_TIMESTAMP:
                    if (! ($value instanceof \MongoTimestamp)) {
                        try {
                            $value = new \MongoTimestamp($value);
                        } catch (\Exception $e) {
                            echo 'bbb';exit();
                            throw new InvalidDataTypeException('$key cannot be parsed by \MongoTimestamp', $e->getCode(), $e);
                        }
                    }
                    break;
                case self::DATA_TYPE_DATE:
                    if (! ($value instanceof \MongoDate)) {
                        try {
                            if (!$value instanceof \MongoDate) {
                                if (is_numeric($value)) {
                                    $value = '@'.$value;
                                }
                                if (!$value instanceof \DateTime) {
                                    $value = new \DateTime($value);
                                }
                                $value = new \MongoDate($value->getTimestamp());
                            }
                        } catch (\Exception $e) {
                            throw new InvalidDataTypeException('$key cannot be parsed by \DateTime', $e->getCode(), $e);
                        }
                    }
                    break;
                case self::DATA_TYPE_BOOL:
                case self::DATA_TYPE_BOOLEAN:
                    $value = (boolean) $value;
                    break;
                case self::DATA_TYPE_OBJ:
                case self::DATA_TYPE_OBJECT:
                    if (!empty($value) && !is_array($value) && !is_object($value)) {
                        throw new InvalidDataTypeException("[$key] is not an object");
                    }
                    $value = (object) $value;
                    break;
                case self::DATA_TYPE_ARRAY:
                    if (!empty($value) && !is_array($value)) {
                        throw new InvalidDataTypeException("[$key] is not an array");
                    }
                    $value = (array) $value;
                    break;
                case self::DATA_TYPE_EMBED:
                case self::DATA_TYPE_EMBEDS:
                case self::DATA_TYPE_MIXED:
                case self::DATA_TYPE_REFERENCE:
                case self::DATA_TYPE_REFERENCES:
                    break;
                default:
                    throw new InvalidDataTypeException("{$attrs[$key]['type']} is not a valid type");
                    break;
            }
        }

        return $value;
    }
235215
public function setAttribute($key, $value)
    {
        $key = snake_case($key);
        $value = empty($value) ? null : $value;
        $value = is_string($value)? trim($value) : $value;
        return parent::setAttribute($key, $value);
    }
595019
private function mapAttributes(\DOMNode $node, $key, $value)
    {
        if (null !== $attrName = $this->getAttributeName($key)) {
            foreach ((array)$value as $attrKey => $attrValue) {
                $node->setAttribute($attrKey, $this->getAttributeValue($attrValue, $attrKey));
            }


            return true;
        }

        if (is_scalar($value) && $this->isMappedAttribute($node->nodeName, $key) && $this->isValidNodeName($key)) {
            $node->setAttribute($key, $this->getAttributeValue($value, $key));

            return true;
        }

        return false;
    }
119764
protected function parse($attribute, $value)
    {
        if (is_object($value)) {
            $class = '\\Pokemon\\Models\\' . ucfirst(Inflector::singularize($attribute));
            if (class_exists($class)) {
                /** @var Model $model */
                $model = new $class;
                $model->fill($value);
                $value = $model;
            }
        }

        return $value;
    }
1124316
public function setAttr($attr, $value) {
		$this->_attrs[$attr] = trim($value);
		$this->_tagCached    = null;
		
		return $this;
	}
430353
protected function cast_attribute( $key, $value ) {
		if ( is_null( $value ) ) {
			return $value;
		}

		switch ( $this->get_cast_type( $key ) ) {
			case 'int':
			case 'integer':
				return (int) $value;
			case 'real':
			case 'float':
			case 'double':
				return (float) $value;
			case 'string':
				return (string) $value;
			case 'array':
				return (array) $value;
			case 'bool':
			case 'boolean':
				return (bool) $value;
			default:
				return $value;
		}
	}
449580
public function setAttribute(string $key, $value): DataObjectInterface
    {
        $this->checkAttributeAssignable($key);

        $this->attributes[$key] = $value;

        return $this;
    }
1050642
public function make(string $key = null, string $value = null): \BearFramework\App\DataItem
    {
        if ($this->newDataItemCache === null) {
            $this->newDataItemCache = new \BearFramework\App\DataItem();
        }
        $object = clone($this->newDataItemCache);
        if ($key !== null) {
            if (!$this->validate($key)) {
                throw new \InvalidArgumentException('The key provided (' . $key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".');
            }
            $object->key = $key;
        }
        if ($value !== null) {
            $object->value = $value;
        }
        return $object;
    }
689408
public function addData($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $v) {
                $this->data[$k] = $v;
            }
        }
        else if (is_string($key)) {
            $this->data[$key] = $value;
        }
        else {
            throw new \InvalidArgumentException(
                "invalid value provided for 'key'; expecting a key as a ".
                "string or an associative array"
            );
        }
        return $this;
    }
1215362
public function attrSet($name, $value)
    {
        $idx = $this->attrIndex($name);
        $attrData = [ $name, $value ];

        if ($idx < 0) {
            $this->attrPush($attrData);
        } else {
            $this->attrs[$idx] = $attrData;
        }
    }
1064259
public function assign($name, $value = null)
    {
        if (is_string($name)) {
            return $this->data[$name] = $value;
        }

        if (is_array($name)) {
            return $this->assignFromArray($name);
        }

        throw new \InvalidArgumentException("Invalid data type for key, '" .gettype($name) . "' given.");
    }
1367713
public function withAttribute(string $key, $value): ElementInterface
    {
        if ($key === 'value' && is_array($value)) {
            $this->withData($value);
        }

        parent::withAttribute($key, $value);

        return $this;
    }
354759
public function setValue($data, $keys, $value)
    {
        if ($this->isKeysEmpty($keys)) {
            return $data;
        }
        if (!is_array($keys)) {
            $keys = [$keys];
        }

        $accessor = new Accessor($data);
        $depth    = 0;
        $keyCount = count($keys);
        foreach ($keys as $key) {
            if ($depth + 1 === $keyCount) {
                if ($accessor->set($key, $value) === false) {
                    throw new InvalidArgumentException(sprintf(
                        'Did not set path %s in structure %s',
                        json_encode($keys),
                        json_encode($data)
                    ));
                }
            } elseif ($accessor->to($key) === false) {
                throw new InvalidArgumentException(sprintf(
                    'Did not find path %s in structure %s',
                    json_encode($keys),
                    json_encode($data)
                ));
            }

            ++$depth;
        }

        return $accessor->getData();
    }
767302
public function attr($key, $value = null, $force = false)
    {
        $attrs = $this->ctx->attrs ?: ($this->ctx->attrs = []);
        if (func_num_args() === 1) {
            return isset($attrs[$key]) ? $attrs[$key] : null;
        }

        $this->ctx->attrs[$key] = !array_key_exists($key, $attrs) || $force ? $value : $attrs[$key];

        return $this;
    }
311489
public function setAttribute($attr, $value)
    {

        $attr = strtolower($attr);

        if(is_null($value)) {
            unset($this->attributes[$attr]);
        }
        else {
            $this->attributes[$attr] = $value;
        }

        return $this;

    }
299766
public function attr($name, $value = null)
    {
        if (func_num_args() < 2) {
            return @$this->attributes[$name];
        } else {
            if (is_null($value)) {
                unset($this->attributes[$name]);
            } else {
                $this->attributes[$name] = $value;
            }
            return $this;
        }
    }
546703
protected function castAttribute($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }

        switch ($this->getCastType($key)) {
            case 'int':
            case 'integer':
                return (int)$value;
            case 'real':
            case 'float':
            case 'double':
                return (float)$value;
            case 'string':
                return (string)$value;
            case 'bool':
            case 'boolean':
                return filter_var($value, FILTER_VALIDATE_BOOLEAN);
            case 'object':
                return is_array($value)
                    ? json_decode(json_encode($value))
                    : json_decode($value);
            case 'array':
            case 'json':
                return json_decode($value, true);
            case 'date':
            case 'datetime':
                return $this->asDateTime($value);
            case 'timestamp':
                return $this->asTimeStamp($value);
            default:
                return $value;
        }
    }