Table.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\swoole;
  12. use Swoole\Table as SwooleTable;
  13. class Table
  14. {
  15. public const TYPE_INT = 1;
  16. public const TYPE_STRING = 3;
  17. public const TYPE_FLOAT = 2;
  18. /**
  19. * Registered swoole tables.
  20. *
  21. * @var array
  22. */
  23. protected $tables = [];
  24. /**
  25. * Add a swoole table to existing tables.
  26. *
  27. * @param string $name
  28. * @param SwooleTable $table
  29. *
  30. * @return Table
  31. */
  32. public function add(string $name, SwooleTable $table)
  33. {
  34. $this->tables[$name] = $table;
  35. return $this;
  36. }
  37. /**
  38. * Get a swoole table by its name from existing tables.
  39. *
  40. * @param string $name
  41. *
  42. * @return SwooleTable $table
  43. */
  44. public function get(string $name)
  45. {
  46. return $this->tables[$name] ?? null;
  47. }
  48. /**
  49. * Get all existing swoole tables.
  50. *
  51. * @return array
  52. */
  53. public function getAll()
  54. {
  55. return $this->tables;
  56. }
  57. /**
  58. * Dynamically access table.
  59. *
  60. * @param string $key
  61. *
  62. * @return SwooleTable
  63. */
  64. public function __get(string $key)
  65. {
  66. return $this->get($key);
  67. }
  68. }