/** * Transforms a array (address) to an object (deliveryAddress). * * @param array $address * @return deliveryAddress|null */ public function reverseTransform($address) { if (!array_key_exists("exist", $address) or $address["exist"] == "create_new") { return $address["new"]->setUser($this->user); } $deliveryAddress = $this->om->getRepository('ChewbaccaOrdersBundle:DeliveryAddress')->findOneBy(array('id' => $address["exist"], 'user' => $this->user->getId())); if (null === $deliveryAddress) { throw new TransformationFailedException(sprintf('An DeliveryAddress with id "%s" does not exist!', $address["exist"])); } return $deliveryAddress; }
/** * Transforms a array (phone) to an object (userPhone). * * @param array $phone * @return userPhone|null */ public function reverseTransform($phone) { if (!array_key_exists("exist", $phone) or $phone["exist"] == "create_new") { if (!$phone["new"]) { $phone["new"] = new UserPhone(); } return $phone["new"]->setUser($this->user); } $userPhone = $this->om->getRepository('ChewbaccaUserBundle:UserPhone')->findOneBy(array('id' => $phone["exist"], 'user' => $this->user->getId())); if (null === $userPhone) { throw new TransformationFailedException(sprintf('An userPhone with id "%s" does not exist!', $phone["exist"])); } return $userPhone; }