protected function _set($data = null, $offset = null, $options = []) {
		if ($schema = $this->schema()) {
			$model = $this->_model;
			$pathKey = $this->_pathKey;
			$options =  compact('model', 'pathKey') + $options;
			$data = !is_object($data) ? $schema->cast($this, $offset, $data, $options) : $data;
			$key = $model && $data instanceof Document ? $model::key($data) : $offset;
		} else {
			$key = $offset;
		}
		if (is_array($key)) {
			$key = count($key) === 1 ? current($key) : null;
		}
		if (is_object($key)) {
			$key = (string) $key;
		}
		if (is_object($data) && method_exists($data, 'assignTo')) {
			$data->assignTo($this);
		}
		$key !== null ? $this->_data[$key] = $data : $this->_data[] = $data;
		if (isset($options['original']) && $options['original']) {
			$key !== null ? $this->_original[$key] = $data : $this->_original[] = $data;
		}
		return $data;
	}
protected function _set($data = null, $offset = null, $options = []) {
		if ($schema = $this->schema()) {
			$model = $this->_model;
			$pathKey = $this->_pathKey;
			$options =  compact('model', 'pathKey') + $options;
			$data = !is_object($data) ? $schema->cast($this, $offset, $data, $options) : $data;
			$key = $model && $data instanceof Document ? $model::key($data) : $offset;
		} else {
			$key = $offset;
		}
		if (is_array($key)) {
			$key = count($key) === 1 ? current($key) : null;
		}
		if (is_object($key)) {
			$key = (string) $key;
		}
		if (is_object($data) && method_exists($data, 'assignTo')) {
			$data->assignTo($this);
		}
		$key !== null ? $this->_data[$key] = $data : $this->_data[] = $data;
		if (isset($options['original']) && $options['original']) {
			$key !== null ? $this->_original[$key] = $data : $this->_original[] = $data;
		}
		return $data;
	}
protected function _set ( $ data = null , $ offset = null , $ options = [ ] ) { if ( $ schema = $ this -> schema ( ) ) { $ model = $ this -> _model ; $ pathKey = $ this -> _pathKey ; $ options = compact ( 'model' , 'pathKey' ) + $ options ; $ data = ! is_object ( $ data ) ? $ schema -> cast ( $ this , $ offset , $ data , $ options ) : $ data ; $ key = $ model && $ data instanceof Document ? $ model :: key ( $ data ) : $ offset ; } else { $ key = $ offset ; } if ( is_array ( $ key ) ) { $ key = count ( $ key ) === 1 ? current ( $ key ) : null ; } if ( is_object ( $ key ) ) { $ key = ( string ) $ key ; } if ( is_object ( $ data ) && method_exists ( $ data , 'assignTo' ) ) { $ data -> assignTo ( $ this ) ; } $ key !== null ? $ this -> _data [ $ key ] = $ data : $ this -> _data [ ] = $ data ; if ( isset ( $ options [ 'original' ] ) && $ options [ 'original' ] ) { $ key !== null ? $ this -> _original [ $ key ] = $ data : $ this -> _original [ ] = $ data ; } return $ data ; }
Helper method to normalize and set data.

@param mixed $data
@param null|integer|string $offset
@param array $options
@return mixed The (potentially) cast data.
Helper method to normalize and set data .