&$value) { $this->$name = $value; } } // -------------------------------------------------------------------------- /** * PHP magic method to facilitate dynamic methods * * @param string $name * @param array $params */ public function __call($name, $params = []) { if(is_callable($this->$name)) { //Call the dynamic function return call_user_func_array($this->$name, $params); } } // -------------------------------------------------------------------------- /** * 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] : []; 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 that is called when an object is treated as a function * * @param array $args */ public static function __invoke($args = []) { $class = __CLASS__; return new $class($args); } } // -------------------------------------------------------------------------- // ! Singleton Trait // -------------------------------------------------------------------------- /** * Singleton pattern * * @package miniMVC * @subpackage System */ trait Singleton { /** * Singleton object * * @var self */ protected static $instance; /** * Protected constructor for creating the one instance */ abstract protected function __construct(); /** * PHP magic method that is called when an object is treated as a function * * @param array $params * @return self */ public static function __invoke($params = []) { return self::get_instance($params); } // -------------------------------------------------------------------------- /** * Singleton getter function * * @return self */ public static function &get_instance() { if ( ! isset(self::$instance)) { $class = __CLASS__; self::$instance = new $class; } return self::$instance; } // -------------------------------------------------------------------------- /** * Magic function called when cloning an object */ public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); } } // End of traits.php