public function __construct() { parent::__construct(); $this->itemtype = self::ITEMCLASS; $serializer = function (&$row, &$key) { if (is_a($row, $this->itemtype)) { $row = $row->toString(); } return true; }; $deserializer = function (&$row, &$key) { if (!is_a($row, $this->itemtype)) { $temp = $this->itemtype; $row = new $temp($row, $this->root); } return true; }; $this->setRowConverter(new Serializer($serializer, $deserializer)); }
public function __construct($type) { parent::__construct(); if (!class_exists($type)) { throw new InvalidTypeException(); } $serializer = function (&$row, &$key) { if (is_object($row) && $row instanceof \PerrysLambda\IArrayable) { $row = $row->toArray(); } elseif (is_object($row)) { throw new \Exception("Row object must implement \\PerrysLambda\\IArrayable"); } elseif (!is_array()) { $row = array('row' => $row); } return true; }; $deserializer = function (&$row, &$key) use($type) { if (!is_a($row, $type)) { $row = new $type($row); } return true; }; $this->setRowConverter(new Ser($serializer, $deserializer)); }