original_string: public function deserialize(array $serialized): DomainEvent {
          $className = $this->classNameForEvent($serialized['eventName']);
  
          $reflect = new ReflectionClass($className);
          $const = $reflect->getConstructor();
  
          // reflect on constructor to get name / type
          $constParams = [];
          foreach ($const->getParameters() as $param) {
              $constParams[] = [
                  $param->getType()->getName(),
                  $param->getName(),
              ];
          }
  
          // get the values for the constructor fields from the serialized event
          $constParamValues = [];
          foreach ($constParams as $constParam) {
              list($type, $name) = $constParam;
              $fields = $serialized['fields'];
              if ( ! isset($fields[$name])) {
                  throw new \Exception("Cannot find serialized field {$name} for {$className}.");
              }
              $constParamValues[] = [
                  $type,
                  $name,
                  $fields[$name],
              ];
          }
  
          // reconstruct the serialized values into the correct type
         return new $className(...array_map([$this, 'deserializeField'], $constParamValues));
      }
code: public function deserialize(array $serialized): DomainEvent {
          $className = $this->classNameForEvent($serialized['eventName']);
  
          $reflect = new ReflectionClass($className);
          $const = $reflect->getConstructor();
  
          // reflect on constructor to get name / type
          $constParams = [];
          foreach ($const->getParameters() as $param) {
              $constParams[] = [
                  $param->getType()->getName(),
                  $param->getName(),
              ];
          }
  
          // get the values for the constructor fields from the serialized event
          $constParamValues = [];
          foreach ($constParams as $constParam) {
              list($type, $name) = $constParam;
              $fields = $serialized['fields'];
              if ( ! isset($fields[$name])) {
                  throw new \Exception("Cannot find serialized field {$name} for {$className}.");
              }
              $constParamValues[] = [
                  $type,
                  $name,
                  $fields[$name],
              ];
          }
  
          // reconstruct the serialized values into the correct type
         return new $className(...array_map([$this, 'deserializeField'], $constParamValues));
      }
code_tokens: public function deserialize ( array $ serialized ) : DomainEvent { $ className = $ this -> classNameForEvent ( $ serialized [ 'eventName' ] ) ; $ reflect = new ReflectionClass ( $ className ) ; $ const = $ reflect -> getConstructor ( ) ; // reflect on constructor to get name / type $ constParams = [ ] ; foreach ( $ const -> getParameters ( ) as $ param ) { $ constParams [ ] = [ $ param -> getType ( ) -> getName ( ) , $ param -> getName ( ) , ] ; } // get the values for the constructor fields from the serialized event $ constParamValues = [ ] ; foreach ( $ constParams as $ constParam ) { list ( $ type , $ name ) = $ constParam ; $ fields = $ serialized [ 'fields' ] ; if ( ! isset ( $ fields [ $ name ] ) ) { throw new \ Exception ( "Cannot find serialized field {$name} for {$className}." ) ; } $ constParamValues [ ] = [ $ type , $ name , $ fields [ $ name ] , ] ; } // reconstruct the serialized values into the correct type return new $ className ( ... array_map ( [ $ this , 'deserializeField' ] , $ constParamValues ) ) ; }
docstring: deserialize a domain event from event sourcery library
  storage conventions
  
  @param array $serialized
  @return DomainEvent
  @throws \ReflectionException
  @throws \Exception
docstring_tokens: deserialize a domain event from event sourcery library storage conventions