/** * Set request that MAC needs to be calculated on * @param AbstractRequest $request * @return $this * @throws \Upg\Library\Serializer\Exception\VisitorCouldNotBeFound */ public function setRequest(AbstractRequest $request) { $data = array(); /**Serialize the any sub objects**/ foreach ($request->getSerializerData() as $key => $value) { if ($this->needsToBeSerialized($value)) { $data[$key] = $this->serializer->serialize($value); } else { $data[$key] = $value; } } $this->setCalculationArray($data); return $this; }
protected function checkSerializeArray($data, Serializer $serializer) { $replace = array(); foreach ($data as $key => $value) { if ($this->checkIfWalkerIsNeeded($value)) { $data[$key] = $serializer->serialize($value); } } return $data; }
protected function checkSerializeArray($data, Serializer $serializer) { $replace = array(); foreach ($data as $key => $value) { if ($value instanceof FileInterface) { $data[$key] = 'FILE::' . $value->getPath(); $this->fileFields[] = $key; } elseif ($this->checkIfWalkerIsNeeded($value)) { $data[$key] = $serializer->serialize($value); } } return $data; }
/** * Test if an exception gets raised if a walker could not be found */ public function testSerializerCouldNotFindVisitor() { try { $serializer = new Serializer(); $serializer->serialize(new NonRecursiveJsonRequest()); $this->fail("No exception was raised"); } catch (AbstractException $e) { $this->assertInstanceOf('Upg\\Library\\Serializer\\Exception\\VisitorCouldNotBeFound', $e, "Incorrect Exception type raised"); } catch (\Exception $e) { $instance = get_class($e); $this->fail("A non library serializer exception was raised instance is {$instance}, got: {$e->getMessage()}"); } }