85 lines
1.5 KiB
PHP
85 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* MiniMVC
|
|
*
|
|
* Convention-based micro-framework for PHP
|
|
*
|
|
* @package miniMVC
|
|
* @author Timothy J. Warren
|
|
* @copyright Copyright (c) 2011 - 2012
|
|
* @link https://github.com/timw4mail/miniMVC
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
*/
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Simple Trait to include most useful default methods
|
|
*
|
|
* @package miniMVC
|
|
* @subpackage System
|
|
*/
|
|
trait Generic {
|
|
|
|
/**
|
|
* 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 = '<pre>';
|
|
|
|
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 . '</pre>';
|
|
}
|
|
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
|