src/DpZFExtensions/Validator/TExchangeState.php
public function exchangeArray(array $state) {
		if ($this instanceof IValueObject && $this->isExchanged())
			throw new Exception("Cannot change ValueObjects. Create new object instead");
		if ($this instanceof IValidatorAware && !is_null($this->getValidator()) &&
			!$this->getValidator()->isValid($state)) {
			$stateRep = array();
			foreach ($state as $key => $val)
				$stateRep[] = $key.' => '.
					(is_object($val)?'[Object]':(is_resource($val)?'[Resource]':var_export($val,true)));
			throw new InvalidStateException("ExchangeArray called with an invalid state: ".
				             var_export($this->getValidator()->getMessages(),true)."\n\n(".implode(',',$stateRep).')');
		}
		$toSet = $this->getStateVarsWithAll();
		foreach ($this->getStateVO() as $voIndex)
			if (isset($state[$voIndex])) {
				$vo = $state[$voIndex];
				if ($vo instanceof IExchangeState)
					$state = array_merge($state,$vo->getArrayCopy());
			}

		foreach ($toSet as $var) {
			if (isset($state[$var])) {
				$value = $state[$var];
				if ($this instanceof IValueObject && $value instanceof IFreezable) $value->freeze();
				// @TODO Add fields of ValueObjects to motherObject
				$this->{self::_privatizeField($var)} = $value;
			}
			else
				$this->{self::_privatizeField($var)} = null;
		}
		if ($this instanceof IValueObject)
			$this->markExchanged();
	}
public function exchangeArray(array $state) {
		if ($this instanceof IValueObject && $this->isExchanged())
			throw new Exception("Cannot change ValueObjects. Create new object instead");
		if ($this instanceof IValidatorAware && !is_null($this->getValidator()) &&
			!$this->getValidator()->isValid($state)) {
			$stateRep = array();
			foreach ($state as $key => $val)
				$stateRep[] = $key.' => '.
					(is_object($val)?'[Object]':(is_resource($val)?'[Resource]':var_export($val,true)));
			throw new InvalidStateException("ExchangeArray called with an invalid state: ".
				             var_export($this->getValidator()->getMessages(),true)."\n\n(".implode(',',$stateRep).')');
		}
		$toSet = $this->getStateVarsWithAll();
		foreach ($this->getStateVO() as $voIndex)
			if (isset($state[$voIndex])) {
				$vo = $state[$voIndex];
				if ($vo instanceof IExchangeState)
					$state = array_merge($state,$vo->getArrayCopy());
			}

		foreach ($toSet as $var) {
			if (isset($state[$var])) {
				$value = $state[$var];
				if ($this instanceof IValueObject && $value instanceof IFreezable) $value->freeze();
				// @TODO Add fields of ValueObjects to motherObject
				$this->{self::_privatizeField($var)} = $value;
			}
			else
				$this->{self::_privatizeField($var)} = null;
		}
		if ($this instanceof IValueObject)
			$this->markExchanged();
	}
public function exchangeArray ( array $ state ) { if ( $ this instanceof IValueObject && $ this -> isExchanged ( ) ) throw new Exception ( "Cannot change ValueObjects. Create new object instead" ) ; if ( $ this instanceof IValidatorAware && ! is_null ( $ this -> getValidator ( ) ) && ! $ this -> getValidator ( ) -> isValid ( $ state ) ) { $ stateRep = array ( ) ; foreach ( $ state as $ key => $ val ) $ stateRep [ ] = $ key . ' => ' . ( is_object ( $ val ) ? '[Object]' : ( is_resource ( $ val ) ? '[Resource]' : var_export ( $ val , true ) ) ) ; throw new InvalidStateException ( "ExchangeArray called with an invalid state: " . var_export ( $ this -> getValidator ( ) -> getMessages ( ) , true ) . "\n\n(" . implode ( ',' , $ stateRep ) . ')' ) ; } $ toSet = $ this -> getStateVarsWithAll ( ) ; foreach ( $ this -> getStateVO ( ) as $ voIndex ) if ( isset ( $ state [ $ voIndex ] ) ) { $ vo = $ state [ $ voIndex ] ; if ( $ vo instanceof IExchangeState ) $ state = array_merge ( $ state , $ vo -> getArrayCopy ( ) ) ; } foreach ( $ toSet as $ var ) { if ( isset ( $ state [ $ var ] ) ) { $ value = $ state [ $ var ] ; if ( $ this instanceof IValueObject && $ value instanceof IFreezable ) $ value -> freeze ( ) ; // @TODO Add fields of ValueObjects to motherObject $ this -> { self :: _privatizeField ( $ var ) } = $ value ; } else $ this -> { self :: _privatizeField ( $ var ) } = null ; } if ( $ this instanceof IValueObject ) $ this -> markExchanged ( ) ; }
Implements a state into an entity

@param $state array
@throws InvalidStateException if the state is not valid
@throws \Exception
Implements a state into an entity