| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace addons\baidupush\library;
- use addons\baidupush\library\push\Driver;
- /**
- * Push操作类
- */
- class Push
- {
- /**
- * @var array Push的实例
- */
- public static $instance = [];
- /**
- * @var object 操作句柄
- */
- public static $handler;
- /**
- * 连接Push驱动
- * @access public
- * @param array $options 配置数组
- * @param bool|string $name Push连接标识 true 强制重新初始化
- * @return Driver
- */
- public static function connect(array $options = [], $name = false)
- {
- $type = !empty($options['type']) ? $options['type'] : 'normal';
- $config = get_addon_config('baidupush');
- $type = strtolower($type);
- $options = array_merge($options, isset($config[$type]) ? $config[$type] : []);
- if (false === $name) {
- $name = md5(serialize($options));
- }
- if (true === $name || !isset(self::$instance[$name])) {
- $class = false === strpos($type, '\\') ?
- '\\addons\\baidupush\\library\\push\\driver\\' . ucwords($type) :
- $type;
- if (true === $name) {
- return new $class($options);
- }
- self::$instance[$name] = new $class($options);
- }
- return self::$instance[$name];
- }
- /**
- * 自动初始化Push
- * @access public
- * @param array $options 配置数组
- * @return Driver
- */
- public static function init(array $options = [])
- {
- if (is_null(self::$handler)) {
- self::$handler = self::connect($options);
- }
- return self::$handler;
- }
- /**
- * 推送实时链接
- * @access public
- * @param array $urls URL数组
- * @return bool
- */
- public static function realtime($urls)
- {
- return self::init()->realtime($urls);
- }
- /**
- * 推送历史链接
- * @access public
- * @param array $urls URL数组
- * @return bool
- */
- public static function history($urls)
- {
- return self::init()->history($urls);
- }
- /**
- * 删除链接
- * @access public
- * @param array $urls URL数组
- * @return mixed
- */
- public static function delete($urls)
- {
- return self::init()->delete($urls);
- }
- }
|