From b5caf111928ff122e5fde344dcc6e69f3a93f38c Mon Sep 17 00:00:00 2001 From: inhere Date: Mon, 11 Nov 2019 00:09:50 +0800 Subject: [PATCH] update some info --- src/HttpClient.php | 10 ++++++ src/MemFactory.php | 75 +++++++++++++++++++++++++++++++++++++++++++++ src/MemTable.php | 4 +-- src/SwooleBench.php | 2 +- 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/src/HttpClient.php b/src/HttpClient.php index 0662c48..505fc3c 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -41,6 +41,16 @@ class HttpClient ]; /** + * Global options for request + * + * [ + * 'method' => 'GET', + * 'data' => 'string|array', + * 'headers' => [key => value], + * 'cookies' => [key => value], + * 'settings' => [key => value], + * ] + * * @var array */ private $options = []; diff --git a/src/MemFactory.php b/src/MemFactory.php index 26e42ed..93bbfc9 100644 --- a/src/MemFactory.php +++ b/src/MemFactory.php @@ -2,10 +2,85 @@ namespace Swoft\Swlib; +use InvalidArgumentException; + /** * Class MemFactory */ final class MemFactory { + /** + * @var MemTable[] + */ + private static $tables = []; + + /** + * @param string $name + * @param int $size + * @param array $columns + * + * @return MemTable + */ + public static function create(string $name, int $size = 0, array $columns = []): MemTable + { + $table = new MemTable($name, $size, $columns); + + // Save instance + self::$tables[$name] = $table; + return $table; + } + + /** + * @param string $name + * + * @return MemTable + */ + public static function get(string $name): MemTable + { + if (isset(self::$tables[$name])) { + return self::$tables[$name]; + } + + throw new InvalidArgumentException('The memory table instance is not exists'); + } + + /** + * @param string $name + * @param MemTable $table + */ + public static function set(string $name, MemTable $table): void + { + self::$tables[$name] = $table; + } + + /** + * @param string $name + * + * @return bool + */ + public static function del(string $name): bool + { + if (isset(self::$tables[$name])) { + unset(self::$tables[$name]); + return true; + } + + return false; + } + + /** + * Clear all tables + * + * @param bool $clearData + */ + public static function clear(bool $clearData = true): void + { + foreach (self::$tables as $name => $table) { + if ($clearData) { + $table->clear(); + } + unset(self::$tables[$name]); + } + } } diff --git a/src/MemTable.php b/src/MemTable.php index 34a6145..b1f1823 100644 --- a/src/MemTable.php +++ b/src/MemTable.php @@ -267,7 +267,7 @@ public function each(callable $fn): void } /** - * clear/flush table data + * Clear/flush table data */ public function clear(): void { @@ -275,7 +275,7 @@ public function clear(): void } /** - * clear/flush table data + * Clear/flush table data */ public function flush(): void { diff --git a/src/SwooleBench.php b/src/SwooleBench.php index aed0818..46dcfab 100644 --- a/src/SwooleBench.php +++ b/src/SwooleBench.php @@ -17,7 +17,7 @@ /** * Class BenchTesting * - * from https://github.com/swoole/swoole-src/blob/master/benchmark/src/Base.php + * @link https://github.com/swoole/swoole-src/blob/master/benchmark/src/Base.php */ class SwooleBench {