trim()->split(','); $table = new Swoole\Table($size, 0.25); foreach ($_fields as $f) { $_f = swoole_string($f)->trim()->split(':'); $name = $_f->get(0)->trim()->toString(); $type = $_f->get(1)->trim(); switch ($type) { case 'i': case 'int': $table->column($name, Swoole\Table::TYPE_INT); break; case 'f': case 'float': $table->column($name, Swoole\Table::TYPE_FLOAT); break; case 's': case 'string': if ($_f->count() < 3) { throw new RuntimeException('need to give string length'); } $length = intval($_f->get(2)->trim()->toString()); if ($length <= 0) { throw new RuntimeException("invalid string length[{$length}]"); } $table->column($name, Swoole\Table::TYPE_STRING, $length); break; default: throw new RuntimeException("unknown field type[{$type}]"); break; } } if (!$table->create()) { throw new RuntimeException('failed to create table'); } return $table; } function swoole_array_list(...$arrray): Swoole\ArrayObject { return new Swoole\ArrayObject($arrray); } function swoole_array_default_value(array $array, $key, $default_value = null) { return array_key_exists($key, $array) ? $array[$key] : $default_value; } if (!function_exists('array_key_last')) { function array_key_last(array $array) { if (!empty($array)) { return key(array_slice($array, -1, 1, true)); } return null; } } if (!function_exists('array_key_first')) { function array_key_first(array $array) { foreach ($array as $key => $unused) { return $key; } return null; } }