public function testEvents() { $input = $this->getJSON(); $json = Decode::json($input)->on(\Serializers\Events::JSON_MSDATE_MATCH, function ($date) { list(, $timestamp, , ) = $date; return date('d.m.Y H:i:s', $timestamp); })->on(Serializers\Events::JSON_BIGINT, function ($json) { # -- don't do anything return $json; }); $compared = $this->arraysAreEqual(array('foo' => 'bar', 'small' => 123456, 'large' => 2.0000000000001E+20, 'text' => 'Example ratio 1000000000000000:1', 'date' => '05.03.2015 12:52:57'), $json->toArray()); $this->assertEquals($compared, true); }
/** * Method for converting JSON to PHP array or object data type * * @param bool $toArray - force assoc array * * @return null|array|object * * @throws RuntimeException * * @since 1.0 */ protected function toPrimitive($toArray = false) { if (!$this->isValid()) { throw new RuntimeException('Provided XML is not valid.'); } $xml = new SimpleXMLElement($this->data, LIBXML_NOCDATA); $json = Encode::toJson($xml)->on(Events::JSON_SERIALIZE, array($this, 'serialize')); $method = $toArray === true ? 'toArray' : 'toObject'; return Decode::json($json->load())->{$method}(); }