<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Description of login_subject
 *
 * @author Igor Ratsun
 */
class login_subject  implements SplSubject {
    
    public $user_name = '';
    public $is_logged = FALSE;
    
    private $observers = array();
    
    public function __construct() {
        $arg_list = func_get_args();
        foreach ($arg_list as $item) {
            if ($item instanceof SplObserver) {
                $this->attach($item);
            }
        }
    }

    public function attach(SplObserver $obs) {
        $id = spl_object_hash($obs);
        $this->observers[$id] = $obs;
    }

    public function detach(SplObserver $obs) {
        $id = spl_object_hash($obs);
        unset($this->observers[$id]);
    }

    public function notify() {
        foreach ($this->observers as $obs) {
            $obs->update($this);
        }
    }

}