/** * test basic object creation with serialized data * * @requires exampleCollection * @requires _exampleCollectionObject */ public function testCreateSerializedCollection() { $data = $this->_exampleCollection(); unset($data[7]); unset($data[8]); $serialized = Serializer::serialize($data); $collection = new Collection(['data' => $serialized, 'type' => 'serialized']); $this->assertEquals('lorem ipsum', $collection->first()); $this->assertEquals($data[1]['data_first'], $collection->getElement(1)['data_first']); }
/** * create serialized string to test * * @param mixed $first * @param mixed $second * @param bool @object * @return string */ protected function _exampleSerializedData($first, $second, $object = false) { if ($object) { return Serializer::serialize((object) $this->_getSimpleData($first, $second)); } return Serializer::serialize($this->_getSimpleData($first, $second)); }
public function testSerializeSpecificAdapter() { $value = 'test'; $adapter = new Adapter\Json(); $expected = $adapter->serialize($value); $this->assertEquals($expected, Serializer::serialize($value, array('adapter' => $adapter))); }
/** * Insert an event * * @param StreamName $streamName * @param DomainEvent $e * @return void */ protected function insertEvent(StreamName $streamName, DomainEvent $e) { $eventData = array('event_id' => $e->uuid()->toString(), 'version' => $e->version(), 'event_name' => $e->messageName(), 'event_class' => get_class($e), 'payload' => Serializer::serialize($e->payload(), $this->serializerAdapter), 'created_at' => $e->createdAt()->format(\DateTime::ISO8601)); foreach ($e->metadata() as $key => $value) { $eventData[$key] = (string) $value; } $tableGateway = $this->getTablegateway($streamName); $tableGateway->insert($eventData); }
/** * return serialized collection * * @return string */ public function serialize() { $data = null; try { $data = Serializer::serialize($this->_prepareCollection()); } catch (ExceptionInterface $exception) { $this->_addException($exception); } return $data; }
/** * recursive method to create structure xml structure of object DATA * * @param $data * @param Xml $xml * @param boolean $addCdata * @param Xml|DOMElement $parent * @return Xml */ protected function _arrayToXml($data, Xml $xml, $addCdata, $parent) { foreach ($data as $key => $value) { $key = str_replace(' ', '_', $key); $attributes = []; $data = ''; if (is_object($value)) { try { $data = Serializer::serialize($value); } catch (ExceptionInterface $exception) { $this->_addException($exception); } $value = ['@attributes' => ['serialized_object' => true], $data]; } try { $isArray = is_array($value); if ($isArray && array_key_exists('@attributes', $value)) { $attributes = $value['@attributes']; unset($value['@attributes']); } if ($isArray) { $parent = $this->_convertArrayDataToXml($value, $addCdata, $xml, $key, $parent, $attributes); continue; } $element = $this->_appendDataToNode($addCdata, $xml, $key, $value); $parent->appendChild($element); } catch (DOMException $exception) { $this->_addException($exception); } } return $xml; }
public function extract($value) { return Serializer::serialize($value); }