$value) { $this->$name = $value; } } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamic methods * * @param string $name * @param array $args */ public function __call($name, array $args) { if(is_callable($this->$name)) { //Add $this object to args array_push($args, $this); //Call the dynamic function return call_user_func_array($this->$name, $args); } } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamically set static methods * * @param string $name * @param array $args */ public static function __callStatic($name, array $args) { if(is_callable(self::$name)) { return call_user_func_array(self::$name, $args); } } // -------------------------------------------------------------------------- /** * Prints out the contents of the object when used as a string * * @return string */ public function __toString() { if(ENVIRONMENT == 'DEVELOPMENT') { $args = func_get_args(); $method = ( ! empty($args)) ? $args[0] : "print_r"; $data = (isset($args[1])) ? $args[1] : array(); if(empty($data)) { $data =& $this; } $output = '
';
			
			if($method == "var_dump")
			{
				ob_start();
				var_dump($data);
				$output .= ob_get_contents();
				ob_end_clean();
			}
			else if($method == "var_export")
			{
				ob_start();
				var_export($data);
				$output .= ob_get_contents();
				ob_end_clean();
			}	
			else
			{
				$output .= print_r($data, TRUE);
			}
		
			return $output . '
'; } else { return ''; } } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamic class loading * * @param string $name */ public function __get($name) { $path = MM_SYS_PATH."{$name}.php"; $class = "{$name}"; if(class_exists($class, FALSE)) { if( ! isset($this->$name)) { $this->$name = new $class; return; } } load_file($name, 'sys'); if(class_exists($class, FALSE)) { $this->$name = new $class; } } // -------------------------------------------------------------------------- /** * PHP magic method that is called when an object is treated as a function */ public static function __invoke() { $class = __CLASS__; return new $class; } } // -------------------------------------------------------------------------- // ! MiniMVC // -------------------------------------------------------------------------- /** * Base class for the framework * * @package miniMVC * @subpackage System */ class miniMVC extends ArrayObject { use JSObject; /** * Singleton object * * @var miniMVC */ private static $instance; /** * Constructor - Any classes loaded here become subclasses of miniMVC * * @param array $members */ public function __construct(array $members=array()) { // Allow the class to be used like an array parent::__construct($members, STD_PROP_LIST | ARRAY_AS_PROPS); self::$instance =& $this; } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamic methods * * @param string $name * @param array $args */ public function __call($name, $args) { // Allow array operations on the object if (substr($name, 0, 6) === 'array_' && is_callable($name)) { $args = array_merge($this->getArrayCopy(), $args); return call_user_func_array($name, $args); } // Call dynamic methods if (is_callable(self::$instance->$name)) { // Add $this object to args array_push($args, $this); // Call the dynamic function return call_user_func_array(self::$instance->$name, $args); } } // -------------------------------------------------------------------------- /** * Magic function called when cloning an object */ public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); } // -------------------------------------------------------------------------- /** * PHP magic method that is called when an object is treated as a function */ public static function __invoke() { return self::get_instance(); } // -------------------------------------------------------------------------- /** * Singleton getter function * * @return miniMVC object */ public static function &get_instance() { if ( ! isset(self::$instance)) { self::$instance = new miniMVC; } $self =& self::$instance; return $self; } // -------------------------------------------------------------------------- /** * Method to load classes into the singleton * * @param string $name * @param string $type * @return void */ public function load_class($name, $type='class') { switch($type) { default: $path = MM_APP_PATH . "classes/{$name}.php"; break; case "sys": $path = MM_SYS_PATH . "{$name}.php"; break; } // In a subdirectory? No problem if(strpos("/", $name) !== FALSE) { $n = explode("/", $name); $name = $n[count($n) -1]; } $class = "{$name}"; if(class_exists($class, FALSE)) { if ( ! isset($this->$name)) { $this->$name = new $class; return; } } if(is_file($path)) { require_once($path); if(class_exists($class, FALSE)) { if ( ! isset($this->$name)) { $this->$name = new $class; return; } } } } // -------------------------------------------------------------------------- /** * Convenience function to remove an object from the singleton * * @param string $name */ public function unload($name) { if(isset($this->$name)) { unset($this->$name); } } // -------------------------------------------------------------------------- /** * Convenience function to load config files * * @param string $name */ public function load_config($name) { $path = MM_APP_PATH . "config/{$name}.php"; if(is_file($path)) { require_once($path); } } } // -------------------------------------------------------------------------- // ! MM_Controller // -------------------------------------------------------------------------- /** * Base Controller Class * * @package miniMVC * @subpackage System */ class MM_Controller extends miniMVC { /** * Instance of Output class * * @var Output */ public $output; /** * Instance of Page class * * @var Page */ public $page; /** * Create the controller object * * @return void */ public function __construct() { parent::__construct(); $this->output = new MM_Output(); $this->page = new MM_Page(); } // -------------------------------------------------------------------------- /** * Function for loading a model into the current class * * @param string $file * @param array $args * @return void */ public function load_model($file, $args=array()) { $path = ""; // The module is the lower of the class name // need to figure out a way to allow multiple controllers // in one module $module = strtolower(get_class($this)); $not_modules = array('miniMVC', 'page', 'db', 'output'); // If it's a module, look in the module view folder if( ! in_array($module, $not_modules)) { $path = MM_MOD_PATH . "{$module}/models/{$file}.php"; } if(is_file($path)) { require_once($path); } if( ! empty($args)) { $this->$file = new $file($args); } else { $this->$file = new $file; } } // -------------------------------------------------------------------------- /** * Function for loading a view * * @param string $file * @param array $data * @param bool $return * @return mixed */ public function load_view($file, array $data=array(), $return=FALSE) { $path = ""; // The module is the lower of the class name // need to figure out a way to allow multiple controllers // in one module $module = strtolower(get_class($this)); $not_modules = array('miniMVC', 'page', 'db', 'output'); // If it's a module, look in the module view folder if( ! in_array($module, $not_modules)) { $path = MM_MOD_PATH . "{$module}/views/{$file}.php"; } // If it's not a module, or doesn't exist in the module view folder // look in the app view folder if( ! is_file($path)) { $path = MM_APP_PATH . "views/{$file}.php"; } // Contain the content for buffering ob_start(); // Extract the data array extract($data); // Include the file include($path); $buffer = ob_get_contents(); ob_end_clean(); if($return == TRUE) { return $buffer; } else { $this->output->append_output($buffer); } } } // -------------------------------------------------------------------------- // ! MM_Model // -------------------------------------------------------------------------- /** * Base Model Class * * @package miniMVC * @subpackage System */ class MM_Model extends miniMVC { /** * Initialize the model class * * @return void */ public function __construct() { parent::__construct(); } // -------------------------------------------------------------------------- /** * Adds the database class to the current model class * * @param string $name * @return void */ public function load_db($name="default") { $this->db =& db::get_instance($name); } } // End of miniMVC.php