Esempio n. 1
0
 public function testLineIterator()
 {
     $iterator = new LineIterator(new File(__DIR__ . "/../examples/testdata.txt"));
     $c = $iterator->count();
     $conv = new Converter();
     $conv->setIteratorSource($iterator, $c - 500);
     $list = new ArrayList($conv);
     $this->assertSame(500, $list->length());
     $conv2 = new Converter();
     $conv2->setIteratorSource($iterator, 0, 499);
     $list2 = new ArrayList($conv2);
     $this->assertSame(500, $list2->length());
 }
 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));
 }
Esempio n. 4
0
    if (!$row instanceof ObjectArray) {
        $json = json_decode($row, true);
        if (isset($json['sensordata']) && is_array($json['sensordata'])) {
            $row = new ObjectArray($json['sensordata']);
            $row->outdoor = new ObjectArray($json['sensordata']['outdoor']);
            $row->brightness = new ObjectArray($json['sensordata']['brightness']);
            $row->indoor = new ObjectArray($json['sensordata']['indoor']);
            return true;
        } else {
            $row = null;
        }
        return false;
    }
    return true;
};
$conv = new Converter();
$conv->setRowConverter(new Serializer($rowser, $rowdeser));
// Field converters (string to number or datetime)
$conv->setFieldConverter('timestamp', new SerDateTime("Y-m-d\\TH:i:s.uO", new \DateTimeZone("Europe/Berlin")));
// Read testdata line by line
$iterator = new LineIterator(new File(__DIR__ . "/testdata.txt"));
// Load only last 500 records
$c = $iterator->count();
$conv->setIteratorSource($iterator);
L::line("Converter created:", $watch->stop()->result());
/**
 * Create list and filter / group
 */
// Create list
$watch->start();
$list = new ArrayList($conv);