public static function fire($name, $data = array()) { $event = new WF_Event($name, $data); if (isset(self::$handlers[$name])) { foreach (self::$handlers[$name] as $callback) { try { call_user_func($callback, $event); } catch (Exception $e) { $logger = WF_Registry::get('logger'); if ($logger) { $logger->warn("call " . WF_Util::getFuncName($callback) . " failed\n"); } } } } }
/** * mutexLoad 加锁后加载数据并设置缓存, 如果加锁失败则返回false * * @param mixed $params * @param mixed $func * @param mixed $args * @param array $options * @access public * @return void */ public function mutexLoad($params, $func, $args, $options = array()) { extract($params); if ($this->lock($mutex_key, $mutex_lifetime)) { //请求不成功,或者没有数据,则返回false //@todo,这种判断是否合理 $ret = call_user_func_array($func, $args); if ($ret === null || $ret === false) { $func_name = WF_Util::getFuncName($func); $this->logger->warn("call func {$func_name} in mutexLoad failed"); return false; } $value = array('data' => $ret, 'expire' => time() + $data_lifetime); $value_str = json_encode($value); $this->logger->debug("set {$key} {$lifetime} {$value_str}"); $this->cache->set($key, $value_str, $lifetime); $this->unlock($mutex_key); return $value; } else { return false; } }