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

/**
 * Description of login_subject
 *
 * @author Igor Ratsun
 */
class acl_rule_edit_subject  implements SplSubject {
    
    public $data = array();
    
    private $observers = array();

    public function set_data($id_acl_role = '', $id_acl_resource = '', $id_acl_action = '') {
        // Prepare data
        $id_acl_role = intval($id_acl_role);
        $id_acl_resource = intval($id_acl_resource);
        $id_acl_action = intval($id_acl_action);
        
        if (!empty($id_acl_role) && !empty($id_acl_resource) && !empty($id_acl_action)) {
            $this->data[$id_acl_role][$id_acl_resource] = $id_acl_action;
        }
    }
    
    public function get_roles_id() {
        
        return array_keys($this->data);
    }
    
    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);
        }
    }

}