mirror of
https://github.com/flextype/flextype.git
synced 2025-08-05 04:37:43 +02:00
refactor(cors): code cleanup
This commit is contained in:
190
index.php
190
index.php
@@ -18,191 +18,6 @@ use function version_compare;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const PHP_VERSION;
|
||||
|
||||
|
||||
class Debug
|
||||
{
|
||||
/**
|
||||
* Time
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $time = [];
|
||||
|
||||
/**
|
||||
* Memory
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $memory = [];
|
||||
|
||||
/**
|
||||
* Save current time for current point
|
||||
*
|
||||
* Debug::elapsedTimeSetPoint('point_name');
|
||||
*
|
||||
* @param string $point_name Point name
|
||||
*/
|
||||
public static function elapsedTimeSetPoint(string $point_name) : void
|
||||
{
|
||||
Debug::$time[$point_name] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elapsed time for current point
|
||||
*
|
||||
* echo Debug::elapsedTime('point_name');
|
||||
*
|
||||
* @param string $point_name Point name
|
||||
* @return string
|
||||
*/
|
||||
public static function elapsedTime(string $point_name) : string
|
||||
{
|
||||
if (isset(Debug::$time[$point_name])) return sprintf("%01.4f", microtime(true) - Debug::$time[$point_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current memory for current point
|
||||
*
|
||||
* Debug::memoryUsageSetPoint('point_name');
|
||||
*
|
||||
* @param string $point_name Point name
|
||||
*/
|
||||
public static function memoryUsageSetPoint(string $point_name) : void
|
||||
{
|
||||
Debug::$memory[$point_name] = memory_get_usage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get memory usage for current point
|
||||
*
|
||||
* echo Debug::memoryUsage('point_name');
|
||||
*
|
||||
* @param string $point_name Point name
|
||||
* @return string
|
||||
*/
|
||||
public static function memoryUsage(string $point_name) : string
|
||||
{
|
||||
if (isset(Debug::$memory[$point_name])) {
|
||||
$unit = array('B', 'KB', 'MB', 'GB', 'TiB', 'PiB');
|
||||
$size = memory_get_usage() - Debug::$memory[$point_name];
|
||||
$memory_usage = @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).' '.$unit[($i < 0 ? 0 : $i)];
|
||||
return $memory_usage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the variable $data and exit if exit = true
|
||||
*
|
||||
* Debug::dump($data);
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param bool $exit Exit
|
||||
*/
|
||||
public static function dump($data, bool $exit = false) : void
|
||||
{
|
||||
echo "<pre>dump \n---------------------- \n\n" . print_r($data, true) . "\n----------------------</pre>";
|
||||
if ($exit) exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently declared classes.
|
||||
*
|
||||
* Debug::classes();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function classes()
|
||||
{
|
||||
return Debug::dump(get_declared_classes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently declared interfaces.
|
||||
*
|
||||
* Debug::interfaces();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function interfaces()
|
||||
{
|
||||
return Debug::dump(get_declared_interfaces());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently included (or required) files.
|
||||
*
|
||||
* Debug::includes();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function includes()
|
||||
{
|
||||
return Debug::dump(get_included_files());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently declared functions.
|
||||
*
|
||||
* Debug::functions();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function functions()
|
||||
{
|
||||
return Debug::dump(get_defined_functions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently declared constants.
|
||||
*
|
||||
* Debug::constants();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function constants()
|
||||
{
|
||||
return Debug::dump(get_defined_constants());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of all currently loaded PHP extensions.
|
||||
*
|
||||
* Debug::extensions();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function extensions()
|
||||
{
|
||||
return Debug::dump(get_loaded_extensions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a list of the configuration settings read from php.ini
|
||||
*
|
||||
* Debug::phpini();
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function phpini()
|
||||
{
|
||||
if (!is_readable(get_cfg_var('cfg_file_path'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Debug::dump(parse_ini_file(get_cfg_var('cfg_file_path'), true));
|
||||
}
|
||||
}
|
||||
|
||||
Debug::elapsedTimeSetPoint('flextype');
|
||||
Debug::memoryUsageSetPoint('flextype');
|
||||
|
||||
/**
|
||||
* Define the application minimum supported PHP version.
|
||||
*/
|
||||
@@ -250,8 +65,3 @@ $flextypeLoader = require_once $flextypeAutoload;
|
||||
* the responses back to the browser and delight our users.
|
||||
*/
|
||||
require_once __DIR__ . '/src/flextype/flextype.php';
|
||||
|
||||
echo "<div style='position:absolute; bottom: 10px; left: 10px;'>";
|
||||
echo "Time: " . Debug::elapsedTime('flextype');
|
||||
echo " Memory: " . Debug::memoryUsage('flextype');
|
||||
echo "</div>";
|
Reference in New Issue
Block a user