diff --git a/Core/Core.php b/Core/Core.php new file mode 100644 index 0000000..9941014 --- /dev/null +++ b/Core/Core.php @@ -0,0 +1,8 @@ +{$formarly}(...$arguments); + } + else if(method_exists(__CLASS__, "call$name")) + { + return (new static)->{"call$name"}($name, ...$arguments); + } + else + { + if(method_exists(__CLASS__, $name)) + { + var_dump($callback); + exit; + } + try{ + return static::{$name}(...$arguments); + }catch(Exception $e){ + + } + return null; + } + } + public function __call($name, $arguments) + { + $formarlyA = "call" . ucfirst($name); + $formarlyB = "static" . ucfirst($name); + if(method_exists($this, $formarlyA)) + { + return $this->{$formarlyA}(...$arguments); + }else if(method_exists(__CLASS__, $formarlyB)) + { + return (new static)->{$formarlyB}(...$arguments); + } + else if(method_exists(__CLASS__, "call$name")) + { + return (new static)->{"call$name"}($name, ...$arguments); + } + } + public function __get($name) + { + $formarly = ucfirst($name); + if(method_exists(__CLASS__, "get" . $formarly . "Attribute")) + { + return $this->{$formarly}; + } + else if(method_exists(__CLASS__, "getAttribute")) + { + return $this->getAttribute($name); + } + else if(property_exists(__CLASS__, "_attributes")) + { + return $this->_attributes[$name] ?? null; + } + } + public function __set($name, $value) + { + $formarly = ucfirst($name); + if(method_exists($this, "get" . $formarly . "Attribute")) + { + $this->{$formarly} = $value; + } + else if(method_exists($this, "setAttribute")) + { + return $this->setAttribute($name, $value); + } + else if(property_exists($this, "_attributes") && isset($this->_attributes[$name])) + { + $this->_attributes[$name] = $value; + } + } + public function __isset($name) + { + $formarly = ucfirst($name); + if(method_exists($this, "get" . $formarly . "Attribute")) + { + return true; + } + else + { + return isset($this->_attributes[$name]); + } + } + public function __unset($name) + { + $formarly = ucfirst($name); + if(method_exists($this, "set" . $formarly . "Attribute")) + { + $this->{"set" . $formarly . "Attribute"}(); + } + else if(method_exists($this, "setAttribute")) + { + return $this->setAttribute($name, null); + } + else if(method_exists($this, "remoteAttribute")) + { + return $this->remoteAttribute($name); + } + else if(property_exists($this, "_attributes") && isset($this->_attributes[$name])) + { + unset($this->_attributes[$name]); + } + } + public function __invoke(...$args) + { + if(method_exists($this, "reflectionCall")) + { + return $this->reflectionCall(...$args); + } + else + { + if(property_exists(__CLASS__, "reflectionCallException")) + { + if(!(new static)->reflectionCallException) + { + return; + } + } + throw new Exception("\"".__CLASS__."()\" not callable"); + } + } + public function __toString() + { + if(method_exists($this, "toString")) + { + return $this->toString(); + } + else + { + if(property_exists(__CLASS__, "reflectionCallException")) + { + if(!(new static)->reflectionCallException) + { + return ""; + } + } + throw new Exception("\"".__CLASS__."()\" not callable"); + } + } + public function __serialize() + { + if(method_exists($this, "getProperties")) + { + return $this->getProperties(); + } + } + + public function __unserialize($datas) + { + if(method_exists($this, "setProperties")) + { + $this->setProperties($datas); + } + } + } \ No newline at end of file diff --git a/Core/Request.php b/Core/Request.php new file mode 100644 index 0000000..5a6152b --- /dev/null +++ b/Core/Request.php @@ -0,0 +1,120 @@ +mutateRequest(); + } + } + function getJSONRequest() + { + return json_decode(file_get_contents('php://input'), true); + } + function mutateRequest() + { + if(Request::$contentType == "application/json") + { + Request::$data = $this->getJSONRequest(); + } + else + { + if(Request::$method == "post") + { + Request::$data = $_POST; + } + Request::$query = $_GET; + }; + } + function contentType() + { + return Request::$contentType; + } + function method() + { + return Request::$method; + } + function get($name) + { + return Request::$query[$name] ?? null; + } + function has($name) + { + return $this->input($name) !== null; + } + function post($name) + { + return Request::$data[$name] ?? null; + } + function input($name) + { + return Request::staticGet($name) ?? Request::staticPost($name) ?? null; + } + function staticContentType() + { + return $this->contentType(); + } + function staticMethod() + { + return $this->method(); + } + function staticGet($name) + { + return $this->get($name); + } + function staticHeaders() + { + return Request::$headers; + } + function staticFile() + { + return Request::$file; + } + function staticSession() + { + return Request::$session; + } + function staticCookie() + { + return Request::$cookie; + } + function staticPost($name) + { + return $this->post($name); + } + function staticInput($name) + { + return $this->input($name); + } + function staticHas($name) + { + return $this->has($name); + } + function getAttribute($name) + { + return Request::staticInput($name); + } + }; \ No newline at end of file diff --git a/Core/RequestCookie.php b/Core/RequestCookie.php new file mode 100644 index 0000000..a8e578a --- /dev/null +++ b/Core/RequestCookie.php @@ -0,0 +1,28 @@ +setAttribute($name, 0, "-1 days"); + } + }; \ No newline at end of file diff --git a/Core/RequestFile.php b/Core/RequestFile.php new file mode 100644 index 0000000..d7f4ba0 --- /dev/null +++ b/Core/RequestFile.php @@ -0,0 +1,148 @@ +files(); + RequestFile::$ready = true; + }; + } + public function getAttribute($name) + { + return $this->getFile($name); + } + public function hasFile($name) + { + return RequestFile::$files->{$name} ? $this->count($name) : false; + } + public function getFile($name) + { + return $this->hasFile($name) ? RequestFile::$files->{$name} : null; + } + public function count($name) + { + return count(RequestFile::$files->{$name}); + } + public function save($field, $directory, $filename = false, $index = 0) + { + $file = $this->getFile($field)[$index]; + if($filename == false) + { + $filename = explode('.', $file->name); + if(count($filename) == 1) + { + $ext = ".bin"; + } + else + { + $ext = end($filename); + }; + $filename = bin2hex(random_bytes(16)) . "." . $ext; + } + if(move_uploaded_file($file->tmp, $directory . "/" . $filename)) + { + return $filename; + } + else + { + return false; + } + } + public function saveAll($field, $directory, $filename = false, $max = -1) + { + $files = $this->getFile($field); + $current = 0; + foreach ($files as $file) + { + $file->save($directory, $filename); + $current++; + if($current == $max && $max != -1) + { + break; + } + } + } + public function files() + { + $arg = new stdClass; + foreach ($_FILES as $name => $file) + { + $arg->{$name} = []; + for($i = 0; $i < count($file["name"]); $i++) + { + $arg->{$name}[] = new UploadedFile( + $i, + $this, + $name, + $file["name"][$i], + $file["full_path"][$i], + $file["type"][$i], + $file["tmp_name"][$i], + $file["error"][$i], + $file["size"][$i] + ); + } + }; + return $arg; + } + } + class UploadedFile + { + public $name; + public $path; + public $mime; + public $tmp; + public $error; + public $size; + + public $index; + public $requestFile; + public $field; + public function __construct( + $index, + $requestFile, + $field, + $name, + $path, + $mime, + $tmp, + $error, + $size + ) + { + $this->name = $name; + $this->path = $path; + $this->mime = $mime; + $this->tmp = $tmp; + $this->error = $error; + $this->size = $size; + $this->index = $index; + $this->requestFile = $requestFile; + $this->field = $field; + } + //save($field, $directory, $filename = false, $index = 0) + public function save($directory, $filename = false) + { + $this->requestFile->save( + $this->field, + $directory, + $filename, + $this->index + ); + } + public function saveAll($directory, $filename = false, $max = -1) + { + $this->requestFile->saveAll( + $this->field, + $directory, + $filename, + $max + ); + } + } \ No newline at end of file diff --git a/Core/RequestHeader.php b/Core/RequestHeader.php new file mode 100644 index 0000000..5d5b2f9 --- /dev/null +++ b/Core/RequestHeader.php @@ -0,0 +1,39 @@ + $value) + { + if (substr($name, 0, 5) == 'HTTP_') + { + RequestHeader::$_attributes[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + }; + } + public static function get($name) + { + return (new static)->{$name}; + } + public static function set($name, $value) + { + $requestHeader = new static; + $requestHeader->{$name} = $value; + } + function setAttribute($name, $value) + { + $formarly = ucfirst(strtolower($name)); + header("$formarly: $value"); + } + function getAttribute($name) + { + $formarly = ucfirst(strtolower($name)); + return RequestHeader::$_attributes[$formarly] ?? null; + } + }; \ No newline at end of file diff --git a/Core/Response.php b/Core/Response.php new file mode 100644 index 0000000..79f643f --- /dev/null +++ b/Core/Response.php @@ -0,0 +1,75 @@ +has($name)) + { + $_SESSION[$name] = []; + } + return array_pop($_SESSION[$name]); + } + function staticShift($name, $item) + { + if(!!$this->has($name)) + { + $_SESSION[$name] = []; + } + return array_shift($_SESSION[$name]); + } + function staticUnshift($name, $item) + { + if(!!$this->has($name)) + { + $_SESSION[$name] = []; + } + $_SESSION[$name] = [ + $item, + ...$_SESSION[$name] + ]; + } + function staticMerge($name, $item) + { + if(!!$this->has($name)) + { + $_SESSION[$name] = []; + } + $_SESSION[$name] = [ + ...$_SESSION[$name], + ...$item + ]; + } + function staticPath($path) + { + session_save_path($path); + } + function staticStatus() + { + switch(session_status()) + { + case PHP_SESSION_ACTIVE:{ + return Session::$active = true; + } + default:{ + return Session::$active = false; + } + } + } + function staticInit() + { + if(!Session::$ready) + { + $this->__contruct(); + } + if(!$this->staticStatus()) + { + $this->staticStart(); + } + } + }; \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..82b4225 --- /dev/null +++ b/index.php @@ -0,0 +1,2 @@ +