From 66f914c80fa8f8d6a01ebff1cc800dd71243b819 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 21 May 2012 14:58:58 -0400 Subject: [PATCH] Autoload traits --- docs/classes/DB.html | 2 +- docs/classes/Data_Store.html | 2 +- docs/classes/MM.html | 2 +- docs/classes/MM_Controller.html | 2 +- docs/classes/MM_Model.html | 2 +- docs/classes/MM_Output.html | 2 +- docs/classes/MM_Page.html | 2 +- docs/classes/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 | 28 +- 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 | 2 +- docs/packages/miniMVC.html | 30 ++- docs/structure.xml | 376 ++++++++++++++++----------- sys/common.php | 13 +- sys/core/traits.php | 201 -------------- sys/core/traits/Generic.php | 85 ++++++ sys/core/traits/JSObject.php | 59 +++++ sys/core/traits/Singleton.php | 79 ++++++ 27 files changed, 525 insertions(+), 386 deletions(-) delete mode 100644 sys/core/traits.php create mode 100644 sys/core/traits/Generic.php create mode 100644 sys/core/traits/JSObject.php create mode 100644 sys/core/traits/Singleton.php diff --git a/docs/classes/DB.html b/docs/classes/DB.html index d47f9fb..b0e137a 100644 --- a/docs/classes/DB.html +++ b/docs/classes/DB.html @@ -125,7 +125,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/Data_Store.html b/docs/classes/Data_Store.html index 25678c2..678633f 100644 --- a/docs/classes/Data_Store.html +++ b/docs/classes/Data_Store.html @@ -199,7 +199,7 @@ of the singleton
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/MM.html b/docs/classes/MM.html index df17249..67cdf32 100644 --- a/docs/classes/MM.html +++ b/docs/classes/MM.html @@ -433,7 +433,7 @@ dynamic methods
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/MM_Controller.html b/docs/classes/MM_Controller.html index 593da4d..5f05d59 100644 --- a/docs/classes/MM_Controller.html +++ b/docs/classes/MM_Controller.html @@ -737,7 +737,7 @@ dynamic methods
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/MM_Model.html b/docs/classes/MM_Model.html index 99d41af..bd0e27d 100644 --- a/docs/classes/MM_Model.html +++ b/docs/classes/MM_Model.html @@ -690,7 +690,7 @@ dynamic methods
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/MM_Output.html b/docs/classes/MM_Output.html index d7b44fc..e1ecb89 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-21T14:58:49-04:00.
diff --git a/docs/classes/MM_Page.html b/docs/classes/MM_Page.html index dd5cd22..bbab42a 100644 --- a/docs/classes/MM_Page.html +++ b/docs/classes/MM_Page.html @@ -1165,7 +1165,7 @@ supports

+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/Session.html b/docs/classes/Session.html index 89db00e..0010b7a 100644 --- a/docs/classes/Session.html +++ b/docs/classes/Session.html @@ -143,7 +143,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/classes/miniMVC.html b/docs/classes/miniMVC.html index 1fa41ec..4deedba 100644 --- a/docs/classes/miniMVC.html +++ b/docs/classes/miniMVC.html @@ -592,7 +592,7 @@ dynamic methods
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/deprecated.html b/docs/deprecated.html index 80f9137..a6d1fcd 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -66,7 +66,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/errors.html b/docs/errors.html index 8f4a4b9..8fd888a 100644 --- a/docs/errors.html +++ b/docs/errors.html @@ -76,12 +76,14 @@
+
+
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/graph_class.html b/docs/graph_class.html index 42a3ff8..cd5aef4 100644 --- a/docs/graph_class.html +++ b/docs/graph_class.html @@ -63,7 +63,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/index.html b/docs/index.html index 0b49b4e..61e255e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -78,7 +78,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/markers.html b/docs/markers.html index 3595503..5dac97c 100644 --- a/docs/markers.html +++ b/docs/markers.html @@ -68,7 +68,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/namespaces/default.html b/docs/namespaces/default.html index 4f913d1..4650d19 100644 --- a/docs/namespaces/default.html +++ b/docs/namespaces/default.html @@ -100,6 +100,19 @@

+
+

Constructor for creating the objects

+
__construct(array $members) : void
+
+
+

+

Parameters

+
+

$members

+array +
+
+

PHP magic method that is called when an object is treated as a function

__invoke(array $params) : \self
@@ -115,6 +128,19 @@
\self
+
+

PHP magic method that is called when an object is treated as a function

+
__invoke(array $args) 
+
+
+

+

Parameters

+
+

$args

+array +
+
+

Prints out the contents of the object when used as a string

__toString() : string
@@ -434,7 +460,7 @@ display them cleanly
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/.html b/docs/packages/.html index 0edf4a2..a1fdb46 100644 --- a/docs/packages/.html +++ b/docs/packages/.html @@ -66,7 +66,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/Default.html b/docs/packages/Default.html index 70ce8da..8533f8a 100644 --- a/docs/packages/Default.html +++ b/docs/packages/Default.html @@ -107,7 +107,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/miniMVC.App.html b/docs/packages/miniMVC.App.html index a1cc663..0473cc4 100644 --- a/docs/packages/miniMVC.App.html +++ b/docs/packages/miniMVC.App.html @@ -99,7 +99,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/miniMVC.Libraries.html b/docs/packages/miniMVC.Libraries.html index 562d1b4..a0d4d29 100644 --- a/docs/packages/miniMVC.Libraries.html +++ b/docs/packages/miniMVC.Libraries.html @@ -96,7 +96,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/miniMVC.System.html b/docs/packages/miniMVC.System.html index 4e3256f..f92adf8 100644 --- a/docs/packages/miniMVC.System.html +++ b/docs/packages/miniMVC.System.html @@ -136,7 +136,7 @@
+ generated on 2012-05-21T14:58:49-04:00.
diff --git a/docs/packages/miniMVC.html b/docs/packages/miniMVC.html index d994795..90c3894 100644 --- a/docs/packages/miniMVC.html +++ b/docs/packages/miniMVC.html @@ -74,6 +74,8 @@
  • PHP magic method to facilitate dynamic methods
    __call
  • Magic function called when cloning an object
    __clone
  • Protected constructor for creating the one instance
    __construct
  • +
  • Constructor for creating the objects
    __construct
  • +
  • PHP magic method that is called when an object is treated as a function
    __invoke
  • PHP magic method that is called when an object is treated as a function
    __invoke
  • Prints out the contents of the object when used as a string
    __toString
  • Function to autoload libraries/classes
    autoload
  • @@ -136,6 +138,19 @@ display them cleanly
    shutdown

    +
    +

    Constructor for creating the objects

    +
    __construct(array $members) : void
    +
    +
    +

    +

    Parameters

    +
    +

    $members

    +array +
    +
    +

    PHP magic method that is called when an object is treated as a function

    __invoke(array $params) : \self
    @@ -151,6 +166,19 @@ display them cleanly
    shutdown
    \self
    +
    +

    PHP magic method that is called when an object is treated as a function

    +
    __invoke(array $args) 
    +
    +
    +

    +

    Parameters

    +
    +

    $args

    +array +
    +
    +

    Prints out the contents of the object when used as a string

    __toString() : string
    @@ -475,7 +503,7 @@ display them cleanly
    + generated on 2012-05-21T14:58:49-04:00.
    diff --git a/docs/structure.xml b/docs/structure.xml index 9cab69b..cdb361c 100644 --- a/docs/structure.xml +++ b/docs/structure.xml @@ -705,6 +705,157 @@ Used for outputing HTML]]> + + + + Convention-based micro-framework for PHP

    ]]>
    + + + + + +
    + Generic + + __construct + function + + + + + + + __invoke + function + + + + + array + + + \self + + + + $params + + + + + + get_instance + function + + + + + \self + + + + + __clone + function + + + + + +
    + + + + Convention-based micro-framework for PHP

    ]]>
    + + + + + +
    + Generic + + __construct + function + + + + + array + + + void + + + + $members + + + + + + __call + function + + + + + string + + + array + + + + $name + + + + + $params + + + + +
    + + + + Convention-based micro-framework for PHP

    ]]>
    + + + + + +
    + + __toString + function + + + + + string + + + + + __invoke + function + + + + + array + + + + $args + + + + +
    @@ -882,99 +1033,6 @@ Used for outputing HTML]]> - - - - Convention-based micro-framework for PHP

    ]]>
    - - - - - -
    - Generic - - __toString - function - - - - - string - - - - - __invoke - function - - - - - array - - - \self - - - - $params - - - - - - __construct - function - - - - - - - __call - function - - - - - string - - - array - - - - $name - - - - - $params - - - - - - get_instance - function - - - - - \self - - - - - __clone - function - - - - - -
    @@ -1393,7 +1451,7 @@ of the singleton]]> - + Convention-based micro-framework for PHP

    ]]>
    @@ -1417,251 +1475,251 @@ of the singleton]]> - + autoload function - + - + - + $name - + shutdown function - + - + void - + on_error function - + - + int - + string - + string - + int - + \ErrorException - + $severity - + $message - + $filepath - + $line - + on_exception function - + - + \Exception - + void - + $exception - + show_404 function - + - + void - + show_error function - + - + string - + int - + $message - + $status_code - + is_like_array function - + - + mixed - + bool - + $var - + controller_methods function - + - + string - + array - + $controller - + site_url function - + - + string - + string - + $segment - + to_string function - + - + \object/array - + string - + string - + $data - + $method - + do_include function - + - + string - + void - + $path - + init function - + - + void - + route function - + - + void diff --git a/sys/common.php b/sys/common.php index 3d9436c..15187a9 100644 --- a/sys/common.php +++ b/sys/common.php @@ -30,14 +30,18 @@ * @param string */ function sys_autoload($name) -{ - +{ $path = MM_SYS_PATH . "/core/{$name}.php"; - + $trait_path = MM_SYS_PATH . "/core/traits/{$name}.php"; + if (is_file($path)) { require_once($path); } + elseif (is_file($trait_path)) + { + require_once($trait_path); + } } // -------------------------------------------------------------------------- @@ -321,8 +325,7 @@ function init() // Load Database classes require_once(MM_SYS_PATH . 'db/autoload.php'); - // Load system libraries - require_once(MM_SYS_PATH . 'core/traits.php'); + // Load system libraries/traits spl_autoload_register('sys_autoload'); // Start the library autoloader diff --git a/sys/core/traits.php b/sys/core/traits.php deleted file mode 100644 index 344e21c..0000000 --- a/sys/core/traits.php +++ /dev/null @@ -1,201 +0,0 @@ -'; - - if ($method == "var_dump") - { - ob_start(); - var_dump($data); - $output .= ob_get_contents(); - ob_end_clean(); - } - elseif ($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); - } -} - -// -------------------------------------------------------------------------- -// ! JSObject Trait -// -------------------------------------------------------------------------- - -/** - * Parent trait of base class, contains much of the magic - * - * @package miniMVC - * @subpackage System - */ -trait JSObject { - - use Generic; - - /** - * 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); - } - } -} - -// -------------------------------------------------------------------------- -// ! Singleton Trait -// -------------------------------------------------------------------------- - -/** - * Singleton pattern - * - * @package miniMVC - * @subpackage System - */ -trait Singleton { - - use Generic; - - /** - * 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 diff --git a/sys/core/traits/Generic.php b/sys/core/traits/Generic.php new file mode 100644 index 0000000..9cf1e48 --- /dev/null +++ b/sys/core/traits/Generic.php @@ -0,0 +1,85 @@ +'; + + if ($method == "var_dump") + { + ob_start(); + var_dump($data); + $output .= ob_get_contents(); + ob_end_clean(); + } + elseif ($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); + } +} + +// End of Generic.php \ No newline at end of file diff --git a/sys/core/traits/JSObject.php b/sys/core/traits/JSObject.php new file mode 100644 index 0000000..7a56766 --- /dev/null +++ b/sys/core/traits/JSObject.php @@ -0,0 +1,59 @@ + &$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); + } + } +} + +// End of JSObject.php \ No newline at end of file diff --git a/sys/core/traits/Singleton.php b/sys/core/traits/Singleton.php new file mode 100644 index 0000000..0259f66 --- /dev/null +++ b/sys/core/traits/Singleton.php @@ -0,0 +1,79 @@ +