Skip to content

Commit

Permalink
Fix type declaration error of Swoole table (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Dec 25, 2021
1 parent dc757dc commit e47bc9c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
tools: composer:v2
coverage: none

- name: Show extension info
run: |
php --ri ${{ matrix.driver }}
- name: Install dependencies
run: |
composer require laravel/framework:"^8.35" --no-update
Expand Down
112 changes: 78 additions & 34 deletions src/Tables/SwooleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,88 @@

use Swoole\Table;

class SwooleTable extends Table
{
use Concerns\EnsuresColumnSizes;

/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*
* @param string $name
* @param int $type
* @param int $size
* @return void
*/
public function column($name, $type, $size = 0)
if (SWOOLE_VERSION_ID === 40804 || SWOOLE_VERSION_ID >= 50000) {
class SwooleTable extends Table
{
$this->columns[$name] = [$type, $size];
use Concerns\EnsuresColumnSizes;

parent::column($name, $type, $size);
}
/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*
* @param string $name
* @param int $type
* @param int $size
* @return bool
*/
public function column(string $name, int $type, int $size = 0): bool
{
$this->columns[$name] = [$type, $size];

return parent::column($name, $type, $size);
}

/**
* Update a row of the table.
*
* @param string $key
* @param array $values
* @return void
*/
public function set($key, array $values)
/**
* Update a row of the table.
*
* @param string $key
* @param array $values
* @return bool
*/
public function set(string $key, array $values): bool
{
collect($values)
->each($this->ensureColumnsSize());

return parent::set($key, $values);
}
}
} else {
class SwooleTable extends Table
{
collect($values)
->each($this->ensureColumnsSize());
use Concerns\EnsuresColumnSizes;

/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*
* @param string $name
* @param int $type
* @param int $size
* @return void
*/
public function column($name, $type, $size = 0)
{
$this->columns[$name] = [$type, $size];

parent::column($name, $type, $size);
}

/**
* Update a row of the table.
*
* @param string $key
* @param array $values
* @return void
*/
public function set($key, array $values)
{
collect($values)
->each($this->ensureColumnsSize());

parent::set($key, $values);
parent::set($key, $values);
}
}
}

0 comments on commit e47bc9c

Please sign in to comment.