public function testStringToBool1() { $this->assertEquals(string_to_bool('true'), true); $this->assertEquals(string_to_bool('false'), false); }
}; }; $pull = function ($f) { return function ($t) use($f) { return $t->{$f}; }; }; function string_to_bool($s) { return in_array(strtolower($s), array('true', 't')); } $process_index = function ($table, $suffix = 'idx') use($stringify, $lookup, $pull) { return function ($index) use($stringify, $table, $lookup, $pull, $suffix) { $attr = $index->attributes(); $i = new Index(); $i->unique = string_to_bool((string) $attr['unique']); $i->type = (string) $attr['type']; $i->fields = array_map($lookup($table->fields), sxml_map($stringify, $index->xpath('dimension'))); $i->name = $table->name . '_' . join('_', array_map($pull('name'), $i->fields)) . '_' . $suffix; return $i; }; }; $process_table = function ($table) use($process_field, $process_index) { $attr = $table->attributes(); $t = new Table(); $t->name = (string) $attr['name']; $t->fields = sxml_map($process_field, $table->fields->children()); $t->primary_key = sxml_map($process_index($t, 'pk'), $table->xpath('indices/primary')); $t->primary_key = reset($t->primary_key); $t->indices = sxml_map($process_index($t), $table->xpath('indices/index')); return $t;