Manager.php 702 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace EasySwoole\Pool;
  3. use EasySwoole\Component\Singleton;
  4. class Manager
  5. {
  6. use Singleton;
  7. protected $container = [];
  8. function register(AbstractPool $pool,string $name = null):Manager
  9. {
  10. if($name === null){
  11. $name = get_class($pool);
  12. }
  13. $this->container[$name] = $pool;
  14. return $this;
  15. }
  16. function get(string $name):?AbstractPool
  17. {
  18. if(isset($this->container[$name])){
  19. return $this->container[$name];
  20. }
  21. return null;
  22. }
  23. function resetAll()
  24. {
  25. /** @var AbstractPool $item */
  26. foreach ($this->container as $item){
  27. $item->destroy();
  28. }
  29. }
  30. }