/**
  * @param array|object $data
  * @param string $dtoClassName
  * @param string $outputFormat
  * @return array
  */
 public function serialize($data, $dtoClassName, $outputFormat = 'json')
 {
     // TODO: check if $data is object or array
     $itemArray = [];
     foreach ($data as $item) {
         $dto = $this->shifter->toDto($item, new $dtoClassName());
         $serializedData = $this->serializer->serialize($dto, $outputFormat);
         $itemArray[] = (array) json_decode($serializedData);
     }
     return $itemArray;
 }
Beispiel #2
0
 public function testToDto()
 {
     $email = '*****@*****.**';
     $phone = '80631257866';
     $domainObject = new User();
     $domainObject->setFirstName('test');
     $domainObject->setSecondName('test');
     $domainObject->setEmail($email);
     $domainObject->setPhone($phone);
     $domainObject->setPassword('test');
     $domainObject->setPlainPassword('4242');
     $domainObject->setUsername('Angelina');
     $shifter = new Shifter();
     $result = $shifter->toDto($domainObject, new UserDto());
     $this->assertEquals($email, $result->email);
     $this->assertEquals($phone, $result->phone);
     $this->assertObjectNotHasAttribute('username', $result);
     $this->assertObjectNotHasAttribute('plainPassword', $result);
 }