/** * Morph the given content into CBOR. * * @param mixed $content * @return string */ protected function morphToCbor($content) { if ($content instanceof CborableInterface) { return $content->toCbor(); } return Cbor::encode($content); }
/** * Sets data of the response. * * @param array $data * @return CborResponse */ public function setData($data = array()) { $this->data = $data instanceof CborableInterface ? $data->toCbor() : Cbor::encode($data); return $this->update(); }
function testEncodeObject() { // Make a nested array $nArray = array('NKey' => 'NVal'); $array = array('Key1' => 'Val1', 'Key2' => $nArray); // Make a nested object out of the array $nObject = (object) $nArray; $object = (object) $array; $object->Key2 = $nObject; // Encode the object and the map $encodedObject = Cbor::encode($object); $encodedArray = Cbor::encode($array); $this->assertEquals($encodedArray, $encodedObject); }