|
4 | 4 |
|
5 | 5 | use Swoole\Table; |
6 | 6 |
|
7 | | -class SwooleTable extends Table |
8 | | -{ |
9 | | - use Concerns\EnsuresColumnSizes; |
10 | | - |
11 | | - /** |
12 | | - * The table columns. |
13 | | - * |
14 | | - * @var array |
15 | | - */ |
16 | | - protected $columns; |
17 | | - |
18 | | - /** |
19 | | - * Set the data type and size of the columns. |
20 | | - * |
21 | | - * @param string $name |
22 | | - * @param int $type |
23 | | - * @param int $size |
24 | | - * @return void |
25 | | - */ |
26 | | - public function column($name, $type, $size = 0) |
| 7 | +if (SWOOLE_VERSION_ID === 40804 || SWOOLE_VERSION_ID >= 50000) { |
| 8 | + class SwooleTable extends Table |
27 | 9 | { |
28 | | - $this->columns[$name] = [$type, $size]; |
| 10 | + use Concerns\EnsuresColumnSizes; |
29 | 11 |
|
30 | | - parent::column($name, $type, $size); |
31 | | - } |
| 12 | + /** |
| 13 | + * The table columns. |
| 14 | + * |
| 15 | + * @var array |
| 16 | + */ |
| 17 | + protected $columns; |
| 18 | + |
| 19 | + /** |
| 20 | + * Set the data type and size of the columns. |
| 21 | + * |
| 22 | + * @param string $name |
| 23 | + * @param int $type |
| 24 | + * @param int $size |
| 25 | + * @return bool |
| 26 | + */ |
| 27 | + public function column(string $name, int $type, int $size = 0): bool |
| 28 | + { |
| 29 | + $this->columns[$name] = [$type, $size]; |
| 30 | + |
| 31 | + return parent::column($name, $type, $size); |
| 32 | + } |
32 | 33 |
|
33 | | - /** |
34 | | - * Update a row of the table. |
35 | | - * |
36 | | - * @param string $key |
37 | | - * @param array $values |
38 | | - * @return void |
39 | | - */ |
40 | | - public function set($key, array $values) |
| 34 | + /** |
| 35 | + * Update a row of the table. |
| 36 | + * |
| 37 | + * @param string $key |
| 38 | + * @param array $values |
| 39 | + * @return bool |
| 40 | + */ |
| 41 | + public function set(string $key, array $values): bool |
| 42 | + { |
| 43 | + collect($values) |
| 44 | + ->each($this->ensureColumnsSize()); |
| 45 | + |
| 46 | + return parent::set($key, $values); |
| 47 | + } |
| 48 | + } |
| 49 | +} else { |
| 50 | + class SwooleTable extends Table |
41 | 51 | { |
42 | | - collect($values) |
43 | | - ->each($this->ensureColumnsSize()); |
| 52 | + use Concerns\EnsuresColumnSizes; |
| 53 | + |
| 54 | + /** |
| 55 | + * The table columns. |
| 56 | + * |
| 57 | + * @var array |
| 58 | + */ |
| 59 | + protected $columns; |
| 60 | + |
| 61 | + /** |
| 62 | + * Set the data type and size of the columns. |
| 63 | + * |
| 64 | + * @param string $name |
| 65 | + * @param int $type |
| 66 | + * @param int $size |
| 67 | + * @return void |
| 68 | + */ |
| 69 | + public function column($name, $type, $size = 0) |
| 70 | + { |
| 71 | + $this->columns[$name] = [$type, $size]; |
| 72 | + |
| 73 | + parent::column($name, $type, $size); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Update a row of the table. |
| 78 | + * |
| 79 | + * @param string $key |
| 80 | + * @param array $values |
| 81 | + * @return void |
| 82 | + */ |
| 83 | + public function set($key, array $values) |
| 84 | + { |
| 85 | + collect($values) |
| 86 | + ->each($this->ensureColumnsSize()); |
44 | 87 |
|
45 | | - parent::set($key, $values); |
| 88 | + parent::set($key, $values); |
| 89 | + } |
46 | 90 | } |
47 | 91 | } |
0 commit comments