commit 8fff8a2df232cc85566422731b71b7bcd240913c Author: Timothy Warren Date: Tue Dec 27 13:24:28 2011 -0500 First commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app/errors/error.php b/app/errors/error.php new file mode 100644 index 0000000..eea3ff7 --- /dev/null +++ b/app/errors/error.php @@ -0,0 +1,25 @@ +
+

A PHP Error was encountered

+ +

Severity:

+

Message:

+

Filename:

+

Line Number:

+ + + +

Backtrace:

+ + + +

+ File:
+ Line:
+ Function: +

+ + +

+ + +
\ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..235a9fc --- /dev/null +++ b/index.php @@ -0,0 +1,30 @@ +db = new MM_db('pgsql'); + +echo $MM->__toString(); diff --git a/modules/default/controllers/test.php b/modules/default/controllers/test.php new file mode 100644 index 0000000..3032564 --- /dev/null +++ b/modules/default/controllers/test.php @@ -0,0 +1,10 @@ +Stack trace:
%s
thrown in %s on line %s"; + + // alter your trace as you please, here + $trace = $exception->getTrace(); + /*foreach ($trace as $key => $stackPoint) { + // I'm converting arguments to their type + // (prevents passwords from ever getting logged as anything other than 'string') + $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); + }*/ + + // build your tracelines + $result = array(); + foreach ($trace as $key => $stackPoint) { + $result[] = sprintf( + $traceline, + $key, + $stackPoint['file'], + $stackPoint['line'], + $stackPoint['function'], + implode(', ', $stackPoint['args']) + ); + } + // trace always ends with {main} + $result[] = '#' . ++$key . ' {main}'; + + // write tracelines into main template + $msg = sprintf( + $msg, + get_class($exception), + $exception->getMessage(), + $exception->getFile(), + $exception->getLine(), + implode("
", $result), + $exception->getFile(), + $exception->getLine() + ); + + echo $msg; +} + +set_exception_handler('on_exception'); \ No newline at end of file diff --git a/sys/db.php b/sys/db.php new file mode 100644 index 0000000..46e8e46 --- /dev/null +++ b/sys/db.php @@ -0,0 +1,140 @@ + (isset($persist)) ? $persist : FALSE, + ); + + if( ! isset($persist)) + { + unset($opts[PDO::ATTR_PERSISTENT]); + } + + $options = array_merge($opts, $options); + + parent::__construct($dsn, $user, $pass, $options); + } + + // -------------------------------------------------------------------------- + + /** + * PHP magic method to facilitate dynamic methods + * + * @param string $name + * @param array $args + */ + function __call($name, $args) + { + if(is_callable($this->$name)) + { + //Add $this to the beginning of the args array + array_unshift($args, $this); + + //Call the dynamic function + return call_user_func_array($this->$name, $args); + } + } + + // -------------------------------------------------------------------------- + + /** + * Prints out the contents of the object when used as a string + * + * @return string + */ + function __toString() + { + $args = func_get_args(); + $method = ( ! empty($args)) ? $args[0] : "print_r"; + + $output = '
';
+	
+		if($method == "var_dump")
+		{
+			ob_start();
+			var_dump($this);
+			$output .= ob_get_contents();
+			ob_end_clean();
+		}
+		else if($method == "var_export")
+		{
+			ob_start();
+			var_export($this);
+			$output .= ob_get_contents();
+			ob_end_clean();
+		}	
+		else
+		{
+			$output .= print_r($this, TRUE);
+		}
+	
+		return $output . '
'; + } + + // -------------------------------------------------------------------------- + + /** + * Constructor without the "new" + * + * @param array $members + */ + function __invoke($members=array()) + { + return new MM_PDO($members); + } +} + +class MM_db extends MM_PDO { + + function __construct($dbname) + { + parent::__construct($dbname); + } + + function __destruct() + { + + } + + +} diff --git a/sys/miniMVC.php b/sys/miniMVC.php new file mode 100644 index 0000000..9e7ab6d --- /dev/null +++ b/sys/miniMVC.php @@ -0,0 +1,189 @@ + $value) + { + if(is_array($value)) + { + $value = new JSObject($value); + } + + $this->$name = $value; + } + } + + /** + * PHP magic method to facilitate dynamic methods + * + * @param string $name + * @param array $args + */ + function __call($name, $args) + { + if(is_callable($this->$name)) + { + //Call the dynamic function + return call_user_func_array($this->$name, $args); + } + } + + + /** + * Prints out the contents of the object when used as a string + * + * @return string + */ + function __toString() + { + $args = func_get_args(); + $method = ( ! empty($args)) ? $args[0] : "print_r"; + + $output = '
';
+	
+		if($method == "var_dump")
+		{
+			ob_start();
+			var_dump($this);
+			$output .= ob_get_contents();
+			ob_end_clean();
+		}
+		else if($method == "var_export")
+		{
+			ob_start();
+			var_export($this);
+			$output .= ob_get_contents();
+			ob_end_clean();
+		}	
+		else
+		{
+			$output .= print_r($this, TRUE);
+		}
+	
+		return $output . '
'; + } + + /** + * Constructor without the "new" + * + * @param array $members + */ + function __invoke($members=array()) + { + return new JSObject($members); + } +} + +/** + * Base class for the framework + */ +class miniMVC extends JSObject { + + function __construct() + { + $this->buffer = ""; + $this->headers = array(); + + parent::__construct(array( + 'output' => array( + 'set_header' => function($key, $val) + { + $this->headers[$key] = $val; + }, + 'append_output' => function($string) + { + $this->buffer .= $string; + }, + 'set_output' => function($string) + { + $this->buffer = $string; + } + ), + )); + } + + /** + * PHP magic method called when ending the script + * Used for outputing HTML + */ + function __destruct() + { + // Set headers + foreach($this->headers as $key => $val) + { + @header("$key: $val"); + } + + + } + + /** + * PHP magic method to facilitate dynamic class loading + * + * @param string $name + */ + function __get($name) + { + $path = SYS_PATH."{$name}.php"; + $class = "MM_{$key}"; + + //if(is_file($path)) + //{ + include($path); + + if(class_exists($class, FALSE)) + { + $this->$name = new $class(); + } + //} + } +} + + // -------------------------------------------------------------------------- + +class MM_Model extends miniMVC { + + function __construct() + { + parent::__construct(); + } + + function __destruct() + { + parent::__destruct(); + } + +} + + // -------------------------------------------------------------------------- + +class MM_Controller extends miniMVC { + + function __construct() + { + parent::__construct(); + } + + function __destruct() + { + parent::__destruct(); + } +} \ No newline at end of file