From d4d700efe6e9bbf5b2f973794f0273d782864847 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 16 May 2012 16:47:36 -0400 Subject: [PATCH] simplify index.php file --- docs/classes.svg | 32 ++-- docs/classes/DB.html | 2 +- docs/classes/MM.html | 2 +- docs/classes/MM_Controller.html | 2 +- docs/classes/MM_Data_Store.html | 2 +- docs/classes/MM_Model.html | 2 +- docs/classes/MM_Output.html | 2 +- docs/classes/MM_Page.html | 2 +- docs/classes/MM_Session.html | 2 +- docs/classes/miniMVC.html | 2 +- docs/deprecated.html | 2 +- docs/errors.html | 4 +- docs/graph_class.html | 2 +- docs/index.html | 2 +- docs/markers.html | 2 +- docs/namespaces/default.html | 8 +- docs/packages/.html | 2 +- docs/packages/Default.html | 2 +- docs/packages/miniMVC.App.html | 2 +- docs/packages/miniMVC.Libraries.html | 2 +- docs/packages/miniMVC.System.html | 4 +- docs/packages/miniMVC.html | 9 +- docs/structure.xml | 193 ++++++++++++---------- index.php | 17 +- sys/common.php | 30 ++++ sys/core/MM.php | 70 ++++++++ sys/core/miniMVC.php | 230 --------------------------- sys/core/traits.php | 186 ++++++++++++++++++++++ 28 files changed, 450 insertions(+), 367 deletions(-) create mode 100644 sys/core/MM.php create mode 100644 sys/core/traits.php diff --git a/docs/classes.svg b/docs/classes.svg index 1e4e773..a771c03 100644 --- a/docs/classes.svg +++ b/docs/classes.svg @@ -27,7 +27,7 @@ -\\miniMVC +\\miniMVC miniMVC @@ -56,29 +56,19 @@ -\\MM - +\\MM + MM - -\\ArrayObject - -\ArrayObject - - -\\MM->\\ArrayObject - - - -\\miniMVC->\\MM +\\miniMVC->\\MM -\\MM_Page +\\MM_Page MM_Page @@ -92,10 +82,20 @@ -\\MM_Page->\\MM_Output +\\MM_Page->\\MM_Output + +\\ArrayObject + +\ArrayObject + + +\\MM->\\ArrayObject + + + \\MM_Controller diff --git a/docs/classes/DB.html b/docs/classes/DB.html index 35660b1..456a5b7 100644 --- a/docs/classes/DB.html +++ b/docs/classes/DB.html @@ -159,7 +159,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM.html b/docs/classes/MM.html index 19b5cca..81d3ce1 100644 --- a/docs/classes/MM.html +++ b/docs/classes/MM.html @@ -433,7 +433,7 @@ dynamic methods
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Controller.html b/docs/classes/MM_Controller.html index e5fd188..ca390de 100644 --- a/docs/classes/MM_Controller.html +++ b/docs/classes/MM_Controller.html @@ -757,7 +757,7 @@ dynamic methods
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Data_Store.html b/docs/classes/MM_Data_Store.html index 2adfc76..dc2569d 100644 --- a/docs/classes/MM_Data_Store.html +++ b/docs/classes/MM_Data_Store.html @@ -199,7 +199,7 @@ of the singleton
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Model.html b/docs/classes/MM_Model.html index b9d3473..4c86ca4 100644 --- a/docs/classes/MM_Model.html +++ b/docs/classes/MM_Model.html @@ -710,7 +710,7 @@ dynamic methods
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Output.html b/docs/classes/MM_Output.html index 6ffb412..4b0a4ef 100644 --- a/docs/classes/MM_Output.html +++ b/docs/classes/MM_Output.html @@ -639,7 +639,7 @@ Used for outputing HTML
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Page.html b/docs/classes/MM_Page.html index e77c397..e6ee0e1 100644 --- a/docs/classes/MM_Page.html +++ b/docs/classes/MM_Page.html @@ -1174,7 +1174,7 @@ supports

+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/MM_Session.html b/docs/classes/MM_Session.html index 9262cba..c59ab0a 100644 --- a/docs/classes/MM_Session.html +++ b/docs/classes/MM_Session.html @@ -143,7 +143,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/classes/miniMVC.html b/docs/classes/miniMVC.html index ef655b8..7778c43 100644 --- a/docs/classes/miniMVC.html +++ b/docs/classes/miniMVC.html @@ -608,7 +608,7 @@ dynamic methods
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/deprecated.html b/docs/deprecated.html index 0983515..87d3cac 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -66,7 +66,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/errors.html b/docs/errors.html index 56dfb11..95f8b39 100644 --- a/docs/errors.html +++ b/docs/errors.html @@ -74,12 +74,14 @@
+
+
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/graph_class.html b/docs/graph_class.html index abc65b2..31364a2 100644 --- a/docs/graph_class.html +++ b/docs/graph_class.html @@ -63,7 +63,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/index.html b/docs/index.html index 41ee1b6..2db479d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -78,7 +78,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/markers.html b/docs/markers.html index 9299d4f..292b3cc 100644 --- a/docs/markers.html +++ b/docs/markers.html @@ -68,7 +68,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/namespaces/default.html b/docs/namespaces/default.html index 3c1d71d..b321456 100644 --- a/docs/namespaces/default.html +++ b/docs/namespaces/default.html @@ -163,6 +163,12 @@
\self
+
+

Load required classes for bootstraping

+
init() : void
+
+

+

Utility function to check if a variable is set, and is an array or object

is_like_array(mixed $var) : bool
@@ -427,7 +433,7 @@ display them cleanly
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/packages/.html b/docs/packages/.html index 194585f..6ab3b6e 100644 --- a/docs/packages/.html +++ b/docs/packages/.html @@ -66,7 +66,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/packages/Default.html b/docs/packages/Default.html index 901285b..f8587e6 100644 --- a/docs/packages/Default.html +++ b/docs/packages/Default.html @@ -114,7 +114,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/packages/miniMVC.App.html b/docs/packages/miniMVC.App.html index ff714dc..b60eb43 100644 --- a/docs/packages/miniMVC.App.html +++ b/docs/packages/miniMVC.App.html @@ -99,7 +99,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/packages/miniMVC.Libraries.html b/docs/packages/miniMVC.Libraries.html index 80a8522..a49da7a 100644 --- a/docs/packages/miniMVC.Libraries.html +++ b/docs/packages/miniMVC.Libraries.html @@ -96,7 +96,7 @@
+ generated on 2012-05-16T16:47:16-04:00.
diff --git a/docs/packages/miniMVC.System.html b/docs/packages/miniMVC.System.html index 2bd9d03..9682159 100644 --- a/docs/packages/miniMVC.System.html +++ b/docs/packages/miniMVC.System.html @@ -63,9 +63,9 @@ Classes
  • MM_Model
  • DB
  • -
  • MM
  • miniMVC
  • MM_Page
  • +
  • MM
  • MM_Controller
  • MM_Output
  • @@ -136,7 +136,7 @@
    + generated on 2012-05-16T16:47:16-04:00.
    diff --git a/docs/packages/miniMVC.html b/docs/packages/miniMVC.html index 71571e1..8b68f37 100644 --- a/docs/packages/miniMVC.html +++ b/docs/packages/miniMVC.html @@ -79,6 +79,7 @@
  • Returns routable methods for the specified controller class
    controller_methods
  • Array_map callback to load a folder of classes at once
    do_include
  • Singleton getter function
    get_instance
  • +
  • Load required classes for bootstraping
    init
  • Utility function to check if a variable is set, and is an array or object
    is_like_array
  • Function to search through the tree to find the necessary file
    load_file
  • Custom error handler
    on_error
  • @@ -197,6 +198,12 @@ display them cleanly
    shutdown
    \self
    +
    +

    Load required classes for bootstraping

    +
    init() : void
    +
    +

    +

    Utility function to check if a variable is set, and is an array or object

    is_like_array(mixed $var) : bool
    @@ -460,7 +467,7 @@ display them cleanly
    + generated on 2012-05-16T16:47:16-04:00.
    diff --git a/docs/structure.xml b/docs/structure.xml index 573685a..49c7de5 100644 --- a/docs/structure.xml +++ b/docs/structure.xml @@ -155,7 +155,7 @@ - + Convention-based micro-framework for PHP

    ]]>
    @@ -246,131 +246,89 @@
    - - MM - \MM - \ArrayObject - - - - - - - - __construct - function - - - - - - - $members - - - - - - __call - function - - - - - string - - - array - - - mixed - - - - $name - - - - - $params - - - - - - +
    + + + + Convention-based micro-framework for PHP

    ]]>
    + + + + + +
    + miniMVC \miniMVC \MM - + - - + + - + __construct function - + - + array - + $members - + load_class function - + - + string - + object - + $name - + unload function - + - + string - + $name - + load_config function - + - + string - + $name @@ -945,6 +903,70 @@ page.

    ]]>
    + + + + Convention-based micro-framework for PHP

    ]]>
    + + + + + +
    + + MM + \MM + \ArrayObject + + + + + + + + __construct + function + + + + + + + $members + + + + + + __call + function + + + + + string + + + array + + + mixed + + + + $name + + + + + $params + + + + + +
    @@ -1432,7 +1454,7 @@ of the singleton]]> - + Convention-based micro-framework for PHP

    ]]>
    @@ -1693,8 +1715,19 @@ display them cleanly]]> + + init + function + + + + + void + + +
    - + Convention-based micro-framework for PHP

    ]]>
    @@ -1710,12 +1743,6 @@ display them cleanly]]> common.php - - db/autoload.php - - - core/miniMVC.php - ENVIRONMENT diff --git a/index.php b/index.php index 2b07ff2..82197ec 100644 --- a/index.php +++ b/index.php @@ -54,22 +54,7 @@ require(MM_APP_PATH.'config/config.php'); // Require the most important files require(MM_SYS_PATH . "common.php"); -// Load Database classes -require_once(MM_SYS_PATH.'db/autoload.php'); - -// Load system libraries -require_once(MM_SYS_PATH.'core/miniMVC.php'); -array_map('do_include', glob(MM_SYS_PATH.'core/*.php')); - -// Catch fatal errors, don't show them -error_reporting((-1) & ~(E_ERROR | E_PARSE)); -register_shutdown_function('shutdown'); - -//Set error handlers -set_error_handler('on_error'); -set_exception_handler('on_exception'); - // And away we go! -route(); +init(); // End of index.php \ No newline at end of file diff --git a/sys/common.php b/sys/common.php index a6919f2..ca14478 100644 --- a/sys/common.php +++ b/sys/common.php @@ -403,4 +403,34 @@ function do_include($path) require_once($path); } +// -------------------------------------------------------------------------- + +/** + * Load required classes for bootstraping + * + * @return void + */ +function init() +{ + // Catch fatal errors, don't show them + error_reporting((-1) & ~(E_ERROR | E_PARSE)); + register_shutdown_function('shutdown'); + + //Set error handlers + set_error_handler('on_error'); + set_exception_handler('on_exception'); + + // Load Database classes + require_once(MM_SYS_PATH.'db/autoload.php'); + + // Load system libraries + require_once(MM_SYS_PATH.'core/traits.php'); + require_once(MM_SYS_PATH.'core/MM.php'); + require_once(MM_SYS_PATH.'core/miniMVC.php'); + array_map('do_include', glob(MM_SYS_PATH.'core/*.php')); + + // Map to the appropriate module/controller/function + route(); +} + // End of common.php \ No newline at end of file diff --git a/sys/core/MM.php b/sys/core/MM.php new file mode 100644 index 0000000..16fa685 --- /dev/null +++ b/sys/core/MM.php @@ -0,0 +1,70 @@ + &$value) + { + $this->$name = $value; + } + } + + // -------------------------------------------------------------------------- + + /** + * Allow calling of array methods on the object and + * dynamic methods + * + * @param string $name + * @param array $params + * @return mixed + */ + public function __call($name, $params = []) + { + // 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); + } + + // Allow dynamic method calls + if(is_callable($this->$name)) + { + //Call the dynamic function + return call_user_func_array($this->$name, $params); + } + } +} + +// End of MM.php \ No newline at end of file diff --git a/sys/core/miniMVC.php b/sys/core/miniMVC.php index 53e249e..f4142b0 100644 --- a/sys/core/miniMVC.php +++ b/sys/core/miniMVC.php @@ -10,236 +10,6 @@ * @link https://github.com/timw4mail/miniMVC * @license http://philsturgeon.co.uk/code/dbad-license */ - -// -------------------------------------------------------------------------- -// ! JSObject Trait -// -------------------------------------------------------------------------- - -/** - * Parent trait of base class, contains much of the magic - * - * @package miniMVC - * @subpackage System - */ -trait JSObject { - - /** - * Constructor for creating the objects - * - * @param array $members - * @return void - */ - public function __construct($members = []) - { - // Add the passed parameters to the object - foreach($members as $name => &$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); - } -} - -// -------------------------------------------------------------------------- -// ! Base Classes -// -------------------------------------------------------------------------- - -/** - * Class for standalone JSObject objects - * - * @package miniMVC - * @subpackage System - */ -class MM extends ArrayObject { - - use JSObject; - - /** - * Create the ArrayObject/JSObject hybrid object - * - * @param array - */ - public function __construct($members = []) - { - parent::__construct($members); - - // Add the passed parameters to the object - foreach($members as $name => &$value) - { - $this->$name = $value; - } - } - - // -------------------------------------------------------------------------- - - /** - * Allow calling of array methods on the object and - * dynamic methods - * - * @param string $name - * @param array $params - * @return mixed - */ - public function __call($name, $params = []) - { - // 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); - } - - // Allow dynamic method calls - if(is_callable($this->$name)) - { - //Call the dynamic function - return call_user_func_array($this->$name, $params); - } - } -} // -------------------------------------------------------------------------- diff --git a/sys/core/traits.php b/sys/core/traits.php new file mode 100644 index 0000000..4c4ae62 --- /dev/null +++ b/sys/core/traits.php @@ -0,0 +1,186 @@ + &$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 \ No newline at end of file