Pārlūkot izejas kodu

compatible event extension with namesapce

walkor 7 gadi atpakaļ
vecāks
revīzija
04412816d3
1 mainītis faili ar 15 papildinājumiem un 5 dzēšanām
  1. 15 5
      Events/Event.php

+ 15 - 5
Events/Event.php

@@ -57,7 +57,12 @@ class Event implements EventInterface
      */
     public function __construct()
     {
-        $this->_eventBase = new \EventBase();
+        if (class_exists('\\\\EventBase')) {
+            $class_name = '\\\\EventBase';
+        } else {
+            $class_name = '\EventBase';
+        }
+        $this->_eventBase = new $class_name();
     }
    
     /**
@@ -65,11 +70,16 @@ class Event implements EventInterface
      */
     public function add($fd, $flag, $func, $args=array())
     {
+        if (class_exists('\\\\Event')) {
+            $class_name = '\\\\Event';
+        } else {
+            $class_name = '\Event';
+        }
         switch ($flag) {
             case self::EV_SIGNAL:
 
                 $fd_key = (int)$fd;
-                $event = \Event::signal($this->_eventBase, $fd, $func);
+                $event = $class_name::signal($this->_eventBase, $fd, $func);
                 if (!$event||!$event->add()) {
                     return false;
                 }
@@ -80,7 +90,7 @@ class Event implements EventInterface
             case self::EV_TIMER_ONCE:
 
                 $param = array($func, (array)$args, $flag, $fd, self::$_timerId);
-                $event = new \Event($this->_eventBase, -1, \Event::TIMEOUT|\Event::PERSIST, array($this, "timerCallback"), $param);
+                $event = new $class_name($this->_eventBase, -1, $class_name::TIMEOUT|$class_name::PERSIST, array($this, "timerCallback"), $param);
                 if (!$event||!$event->addTimer($fd)) {
                     return false;
                 }
@@ -89,8 +99,8 @@ class Event implements EventInterface
                 
             default :
                 $fd_key = (int)$fd;
-                $real_flag = $flag === self::EV_READ ? \Event::READ | \Event::PERSIST : \Event::WRITE | \Event::PERSIST;
-                $event = new \Event($this->_eventBase, $fd, $real_flag, $func, $fd);
+                $real_flag = $flag === self::EV_READ ? $class_name::READ | $class_name::PERSIST : $class_name::WRITE | $class_name::PERSIST;
+                $event = new $class_name($this->_eventBase, $fd, $real_flag, $func, $fd);
                 if (!$event||!$event->add()) {
                     return false;
                 }