#3 docu system
This commit is contained in:
parent
5770a31ef8
commit
600cf1de0a
@ -15,6 +15,12 @@ namespace SYSTEM;
|
|||||||
* HEADER Class provided by System Send HTML Headers
|
* HEADER Class provided by System Send HTML Headers
|
||||||
*/
|
*/
|
||||||
class HEADER {
|
class HEADER {
|
||||||
|
/**
|
||||||
|
* Check if Header was already sent
|
||||||
|
* Writes Warning into Database on failure if Database logging is enabled.
|
||||||
|
*
|
||||||
|
* @return bool Returns true or false
|
||||||
|
*/
|
||||||
private static function checkHeader(){
|
private static function checkHeader(){
|
||||||
$file = null;
|
$file = null;
|
||||||
$line = null;
|
$line = null;
|
||||||
@ -24,41 +30,91 @@ class HEADER {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given Datatype has a handler within this class.
|
||||||
|
* Not Case sensitive.
|
||||||
|
*
|
||||||
|
* @param string $datatype Datatype to be checked eg. 'jpg'
|
||||||
|
* @return bool Returns true or false
|
||||||
|
*/
|
||||||
|
public static function available($datatype){
|
||||||
|
return \method_exists('\SYSTEM\HEADER', strtoupper($datatype));}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send JSON Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function JSON(){
|
public static function JSON(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('Access-Control-Allow-Origin: *');//allow cross domain calls
|
header('Access-Control-Allow-Origin: *');//allow cross domain calls
|
||||||
header('content-type: application/json');}}
|
header('content-type: application/json');}}
|
||||||
|
/**
|
||||||
|
* Send PNG Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function PNG(){
|
public static function PNG(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
||||||
header('content-type:image/png;');}}
|
header('content-type:image/png;');}}
|
||||||
|
/**
|
||||||
|
* Send JPG Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function JPG(){
|
public static function JPG(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
||||||
header('content-type:image/jpeg;');}}
|
header('content-type:image/jpeg;');}}
|
||||||
|
/**
|
||||||
|
* Send JPEG Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function JPEG(){
|
public static function JPEG(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
||||||
header('content-type:image/jpeg;');}}
|
header('content-type:image/jpeg;');}}
|
||||||
|
/**
|
||||||
|
* Send GIF Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function GIF(){
|
public static function GIF(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // 1 hour
|
||||||
header('content-type:image/gif;');}}
|
header('content-type:image/gif;');}}
|
||||||
|
/**
|
||||||
|
* Send JS Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function JS(){
|
public static function JS(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('content-type:application/javascript;');}}
|
header('content-type:application/javascript;');}}
|
||||||
|
/**
|
||||||
|
* Send CSS Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function CSS(){
|
public static function CSS(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('content-type:text/css;');}}
|
header('content-type:text/css;');}}
|
||||||
|
/**
|
||||||
|
* Send LESS Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function LESS(){
|
public static function LESS(){
|
||||||
if(self::checkHeader()){
|
if(self::checkHeader()){
|
||||||
header('content-type:text/css;');}}
|
header('content-type:text/css;');}}
|
||||||
|
/**
|
||||||
|
* Send FILE(download) Headers, if Header was not sent yet
|
||||||
|
*
|
||||||
|
* @return null Returns null
|
||||||
|
*/
|
||||||
public static function FILE($filename){
|
public static function FILE($filename){
|
||||||
header("Content-type: application/octet-stream");
|
header("Content-type: application/octet-stream");
|
||||||
header("Content-Disposition: attachment; filename=\"".$filename."\"");}
|
header("Content-Disposition: attachment; filename=\"".$filename."\"");}
|
||||||
|
|
||||||
public static function available($datatype){
|
|
||||||
$datatype = strtoupper($datatype);
|
|
||||||
return \method_exists('\SYSTEM\HEADER', $datatype);}
|
|
||||||
}
|
}
|
||||||
@ -22,10 +22,22 @@ class autoload {
|
|||||||
/** string Registered Func Format array(namespace, func) */
|
/** string Registered Func Format array(namespace, func) */
|
||||||
private static $func = array();
|
private static $func = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Classname of a File by removing its extension and containing folders.
|
||||||
|
*
|
||||||
|
* @param string $file Filepath to be reduced to classname
|
||||||
|
* @return string Returns classname
|
||||||
|
*/
|
||||||
private static function getClassFromFile($file){
|
private static function getClassFromFile($file){
|
||||||
$path_info = \pathinfo($file);
|
$path_info = \pathinfo($file);
|
||||||
return $path_info['filename'];}
|
return $path_info['filename'];}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seperates Class and Namespace of a combined string.
|
||||||
|
*
|
||||||
|
* @param string $class Class including possible Namespaces
|
||||||
|
* @return array Returns array(class,namespace).
|
||||||
|
*/
|
||||||
private static function getClassNamespaceFromClass($class){
|
private static function getClassNamespaceFromClass($class){
|
||||||
$path_info = \pathinfo($class);
|
$path_info = \pathinfo($class);
|
||||||
$lastslash = \strrpos($class, 92);
|
$lastslash = \strrpos($class, 92);
|
||||||
@ -38,43 +50,71 @@ class autoload {
|
|||||||
\substr($class, 0, $lastslash));
|
\substr($class, 0, $lastslash));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The autoload Feature. Searches within all registered file, folders and
|
||||||
|
* functions if a matching class can be found, respecting namespaces in the
|
||||||
|
* process.
|
||||||
|
*
|
||||||
|
* @param string $class Class to be autoloaded
|
||||||
|
* @param string $namespace Namespace of the Request
|
||||||
|
* @return bool Returns true or false.
|
||||||
|
*/
|
||||||
private static function autoload_($class, $namespace = ''){
|
private static function autoload_($class, $namespace = ''){
|
||||||
foreach(self::$files as $file){
|
foreach(self::$files as $file){
|
||||||
if(strtolower($file[0]) == strtolower($class) &&
|
if(strtolower($file[0]) == strtolower($class) &&
|
||||||
strtolower($file[1]) == strtolower($namespace)){
|
strtolower($file[1]) == strtolower($namespace)){
|
||||||
require_once $file[2];
|
require_once $file[2];
|
||||||
return true;}
|
return true;}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(self::$folders as $folder){
|
foreach(self::$folders as $folder){
|
||||||
if(strtolower($folder[0]) == strtolower($namespace) &&
|
if(strtolower($folder[0]) == strtolower($namespace) &&
|
||||||
is_file($folder[1].'/'.$class.'.php')){
|
is_file($folder[1].'/'.$class.'.php')){
|
||||||
require_once $folder[1].'/'.$class.'.php';
|
require_once $folder[1].'/'.$class.'.php';
|
||||||
return true;}
|
return true;}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(self::$func as $func){
|
foreach(self::$func as $func){
|
||||||
if(strtolower($func[0]) == strtolower($namespace) && call_user_func($func[1],$class)){
|
if(strtolower($func[0]) == strtolower($namespace) && call_user_func($func[1],$class)){
|
||||||
return true;}
|
return true;}}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a file to the autoload feature
|
||||||
|
* The file has to be named class.php
|
||||||
|
*
|
||||||
|
* @param string $file Filepath to be autoloaded from
|
||||||
|
* @param string $namespace Namespace of the File
|
||||||
|
* @return null Returns null.
|
||||||
|
*/
|
||||||
public static function registerFile($file, $namespace = ''){
|
public static function registerFile($file, $namespace = ''){
|
||||||
if(!is_file($file)){
|
if(!is_file($file)){
|
||||||
throw new \SYSTEM\LOG\ERROR('File not found on registerFile for Autoload: '.$file);}
|
throw new \SYSTEM\LOG\ERROR('File not found on registerFile for Autoload: '.$file);}
|
||||||
|
|
||||||
self::$files[] = array(self::getClassFromFile($file), $namespace, $file);
|
self::$files[] = array(self::getClassFromFile($file), $namespace, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a folder to the autoload feature
|
||||||
|
* All Classes within that Folder can be loaded if
|
||||||
|
* the file is named: class.php
|
||||||
|
*
|
||||||
|
* @param string $folder Folderpath to be autoloaded from
|
||||||
|
* @param string $namespace Namespace of the Folder
|
||||||
|
* @return null Returns null.
|
||||||
|
*/
|
||||||
public static function registerFolder($folder, $namespace = ''){
|
public static function registerFolder($folder, $namespace = ''){
|
||||||
if(!is_dir($folder)){
|
if(!is_dir($folder)){
|
||||||
throw new \SYSTEM\LOG\ERROR('Folder not found on registerFolder for Autoload: '.$folder);}
|
throw new \SYSTEM\LOG\ERROR('Folder not found on registerFolder for Autoload: '.$folder);}
|
||||||
|
|
||||||
self::$folders[] = array($namespace, $folder);
|
self::$folders[] = array($namespace, $folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a function to the autoload feature
|
||||||
|
* @todo Does this work? Is it useful?
|
||||||
|
*
|
||||||
|
* @param string $func Function to be "autoloaded"
|
||||||
|
* @param string $namespace Namespace of the Function
|
||||||
|
* @return null Returns null.
|
||||||
|
*/
|
||||||
public static function registerFunc($func, $namespace = ''){
|
public static function registerFunc($func, $namespace = ''){
|
||||||
/*if(!_exists($func)){
|
/*if(!_exists($func)){
|
||||||
throw new \SYSTEM\LOG\ERROR('Function not found on registerFunc for Autoload: '.$func);}*/
|
throw new \SYSTEM\LOG\ERROR('Function not found on registerFunc for Autoload: '.$func);}*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user