Queue.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 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;
  12. use think\helper\Str;
  13. use think\queue\Connector;
  14. /**
  15. * Class Queue
  16. * @package think\queue
  17. *
  18. * @method static push($job, $data = '', $queue = null)
  19. * @method static later($delay, $job, $data = '', $queue = null)
  20. * @method static pop($queue = null)
  21. * @method static marshal()
  22. */
  23. class Queue
  24. {
  25. /** @var Connector */
  26. protected static $connector;
  27. private static function buildConnector()
  28. {
  29. $options = Config::get('queue');
  30. $type = !empty($options['connector']) ? $options['connector'] : 'Sync';
  31. if (!isset(self::$connector)) {
  32. $class = false !== strpos($type, '\\') ? $type : '\\think\\queue\\connector\\' . Str::studly($type);
  33. self::$connector = new $class($options);
  34. }
  35. return self::$connector;
  36. }
  37. public static function __callStatic($name, $arguments)
  38. {
  39. return call_user_func_array([self::buildConnector(), $name], $arguments);
  40. }
  41. }