Ejemplo n.º 1
0
 public function model($route)
 {
     // Sanitize the call
     $route = str_replace('../', '', (string) $route);
     $file = DIR_APPLICATION . 'model/' . $route . '.php';
     $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $route);
     if (is_file($file)) {
         include_once $file;
         $observer = new Observer($this->registry);
         foreach (get_class_methods($class) as $method) {
             $observer->attach($method, $this->closure($this->registry, $route . '/' . $method));
         }
         $this->registry->set('model_' . str_replace('/', '_', (string) $route), $observer);
     } else {
         trigger_error('Error: Could not load model ' . $route . '!');
         exit;
     }
 }
Ejemplo n.º 2
0
    }
    public function notify()
    {
        foreach (self::$_observers as $obj) {
            $obj->update($this);
        }
    }
}
/**
 * 观察者1
 */
class Email implements Ob_standard
{
    public function update(Observer $obj)
    {
        echo '发送邮件';
    }
}
/**
 * 观察者2
 */
class Files implements Ob_standard
{
    public function update(Observer $obj)
    {
        echo '发送邮文件';
    }
}
//实验
Observer::attach(new Files());
$m = new Observer();