function buildMongoOutput($data) { return array_map(function ($x) { if ($x instanceof DateTimeImmutable) { $stamp = $x->getTimestamp(); return new MongoDate($stamp); } elseif ($x instanceof FileInfo) { throw new Exception('Unexpected file!'); } elseif (is_array($x)) { return buildMongoOutput($x); } else { return $x; } }, $data); }
function run($data, $page) { $collection = $this->getClient(); $collection->insert(buildMongoOutput($data)); return $data; }