Location: PHPKode > projects > Blackwolf CMF > projectBlackWolf/lib/Module.class.php
<?php
/* Please see the README and LICENSE files. */

/**
 * A module is a collection of data and tools to modify that data.
 * This class represents a specific module
 */
class Module implements ArrayAccess {
    protected $models;
    
    public function __construct(){
        $this->clean();
    }
    
    /**
     * Add a specified model to the modules internal storage
     * 
     * @param String model The model to add
     * @param String name The name of the model
     */
    public function add_model($model,$name=NULL) {
        $this->models[$name==NULL?$model->name:$name] = $model;
    }
    
    /**
     * Restore the module to it's initial state
     */
    public function clean(){
        $this->models = array();
    }
    
    /**
     * Execute a specific command on the module
     * 
     * @param Module_Command cmd The command to execute
     */
    public function exe($cmd){
        if(!Permission_Subsystem::can_exec_cmd($cmd)){
            return false;
        }
        if($cmd instanceof Module_Command){
            $this->update_from($cmd->run($this));
        }
    }
    
    /**
     * Update from the command
     * 
     * @param Data_Module $module The "from"
     */
    protected function update_from($module){
        var_dump($module);
        if(!($module instanceof $this)){return false;}
        $this->models = array_unique(
                                array_merge(array_values($module),
                                $this->models));
    }

    public function offsetExists($offset) {
        return isset($this->models[$offset]);
    }

    public function offsetGet($offset) {
        return $this->offsetExists($offset) ? $this->models[$offset] : false;
    }

    public function offsetSet($offset, $value) {
        if(!($value instanceof Data_Model)){return false;}
        $this->models[$offset] = $value;
    }

    public function offsetUnset($offset) {
        if($this->offsetExists($offset)){
            unset($this->models[$offset]);
        }
    }
}

?>
Return current item: Blackwolf CMF