From 9e5f941436fad66903499bb853a141e4fdcf7deb Mon Sep 17 00:00:00 2001 From: Abdussamed Date: Tue, 11 Apr 2023 00:30:15 +0300 Subject: [PATCH] Route public / mimetypes --- Core/Blade.php | 0 Core/BladeOne.php | 0 Core/BladeOneCache.php | 0 Core/Core.php | 4 +- Core/DatabaseConnection.php | 0 Core/DatabaseMysqlEngine.php | 0 Core/DatabaseORM.php | 0 Core/Helpers.php | 0 Core/Reflection.php | 0 Core/Request.php | 1 - Core/RequestCookie.php | 0 Core/RequestFile.php | 0 Core/RequestHeader.php | 0 Core/Response.php | 6 +- Core/Route.php | 90 ++++++++++++++----- Core/Session.php | 0 Core/mimes.php | 90 +++++++++++++++++++ README.md | 0 cache/.gitignore | 0 ...c97192c2cfed90e18fe99b6efe0e0b45e84.bladec | 17 ++++ index.php | 18 ++-- public/index.js | 1 + views/.gitignore | 0 views/hello.blade.php | 15 ++++ 24 files changed, 205 insertions(+), 37 deletions(-) mode change 100644 => 100755 Core/Blade.php mode change 100644 => 100755 Core/BladeOne.php mode change 100644 => 100755 Core/BladeOneCache.php mode change 100644 => 100755 Core/Core.php mode change 100644 => 100755 Core/DatabaseConnection.php mode change 100644 => 100755 Core/DatabaseMysqlEngine.php mode change 100644 => 100755 Core/DatabaseORM.php mode change 100644 => 100755 Core/Helpers.php mode change 100644 => 100755 Core/Reflection.php mode change 100644 => 100755 Core/Request.php mode change 100644 => 100755 Core/RequestCookie.php mode change 100644 => 100755 Core/RequestFile.php mode change 100644 => 100755 Core/RequestHeader.php mode change 100644 => 100755 Core/Response.php mode change 100644 => 100755 Core/Route.php mode change 100644 => 100755 Core/Session.php create mode 100644 Core/mimes.php mode change 100644 => 100755 README.md mode change 100644 => 100755 cache/.gitignore create mode 100644 cache/hello_f42c5c97192c2cfed90e18fe99b6efe0e0b45e84.bladec mode change 100644 => 100755 index.php create mode 100644 public/index.js mode change 100644 => 100755 views/.gitignore create mode 100755 views/hello.blade.php diff --git a/Core/Blade.php b/Core/Blade.php old mode 100644 new mode 100755 diff --git a/Core/BladeOne.php b/Core/BladeOne.php old mode 100644 new mode 100755 diff --git a/Core/BladeOneCache.php b/Core/BladeOneCache.php old mode 100644 new mode 100755 diff --git a/Core/Core.php b/Core/Core.php old mode 100644 new mode 100755 index f6713f1..ec0ab42 --- a/Core/Core.php +++ b/Core/Core.php @@ -1,10 +1,8 @@ "public", + "path" => preg_quote($route), + "src" => $storagepath, + "method" => "get" + ]); + } public static function any($path, $callback) { $magic = magicRoute($path); @@ -146,6 +156,14 @@ return $route; } }; + foreach (Route::$publics as $route) { + $route->clear(); + if($route->Run()) + { + Route::$current = $route; + return $route; + } + }; return false; }; return Route::$current; @@ -157,6 +175,7 @@ if($route === false) { Response::Code(404); + exit; }; $route->call(); } @@ -168,6 +187,7 @@ public string $type; public string $path; + public string $src; public $callback; public string $method; @@ -185,8 +205,17 @@ } public function call(...$args) { - $callback = $this->callback; - $callback(...$args); + switch ($this->type) { + case 'magic': + case 'text': + $callback = $this->callback; + $callback(...$args); + break; + case 'public': + $callback = $this->callback; + Response::File($callback); + break; + } } public function Run() { @@ -197,27 +226,46 @@ return false; } $url = parse_url($requestUrl, PHP_URL_PATH); - if($this->type == "text") + switch($this->type) { - if($url == $this->path) - { - return true; - }else{ - return false; + case "text":{ + if($url == $this->path) + { + return true; + }else{ + return false; + } + break; + } + case "magic":{ + if($t === false) + { + return false; + }else{ + $this->match = $t; + return true; + } + break; + } + case "public":{ + $path = tstring::from($this->path); + $url = tstring::from($url); + if($url->startsWith($path)) + { + $filename = $url->slice(strlen($path)); // remove first / char + $rpath = realpath($this->src . $filename); + if(file_exists($rpath)) + { + $this->callback = $rpath; + return true; + }else{ + return false; + } + }else{ + return false; + } + break; } - }; - - $t = validateMagicRoute( - $this->path, - $url - ); - - if($t === false) - { - return false; - }else{ - $this->match = $t; - return true; } } } \ No newline at end of file diff --git a/Core/Session.php b/Core/Session.php old mode 100644 new mode 100755 diff --git a/Core/mimes.php b/Core/mimes.php new file mode 100644 index 0000000..ae29b94 --- /dev/null +++ b/Core/mimes.php @@ -0,0 +1,90 @@ + "text/html", + "html" => "text/html", + "shtml" => "text/html", + "css" => "text/css", + "xml" => "text/xml", + "gif" => "image/gif", + "jpeg" => "image/jpeg", + "jpg" => "image/jpeg", + "js" => "application/javascript", + "atom" => "application/atom+xml", + "rss" => "application/rss+xml", + "mml" => "text/mathml", + "txt" => "text/plain", + "jad" => "text/vnd.sun.j2me.app-descriptor", + "wml" => "text/vnd.wap.wml", + "htc" => "text/x-component", + "avif" => "image/avif", + "png" => "image/png", + "svgz" => "image/svg+xml", + "svg" => "image/svg+xml", + "tiff" => "image/tiff", + "tif" => "image/tiff", + "wbmp" => "image/vnd.wap.wbmp", + "webp" => "image/webp", + "ico" => "image/x-icon", + "jng" => "image/x-jng", + "bmp" => "image/x-ms-bmp", + "woff" => "font/woff", + "woff2" => "font/woff2", + "json" => "application/json", + "hqx" => "application/mac-binhex40", + "doc" => "application/msword", + "pdf" => "application/pdf", + "rtf" => "application/rtf", + "m3u8" => "application/vnd.apple.mpegurl", + "kml" => "application/vnd.google-earth.kml+xml", + "kmz" => "application/vnd.google-earth.kmz", + "xls" => "application/vnd.ms-excel", + "eot" => "application/vnd.ms-fontobject", + "ppt" => "application/vnd.ms-powerpoint", + "odg" => "application/vnd.oasis.opendocument.graphics", + "odp" => "application/vnd.oasis.opendocument.presentation", + "ods" => "application/vnd.oasis.opendocument.spreadsheet", + "odt" => "application/vnd.oasis.opendocument.text", + "pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "wmlc" => "application/vnd.wap.wmlc", + "wasm" => "application/wasm", + "7z" => "application/x-7z-compressed", + "cco" => "application/x-cocoa", + "jardiff" => "application/x-java-archive-diff", + "jnlp" => "application/x-java-jnlp-file", + "run" => "application/x-makeself", + "rar" => "application/x-rar-compressed", + "rpm" => "application/x-redhat-package-manager", + "sea" => "application/x-sea", + "swf" => "application/x-shockwave-flash", + "sit" => "application/x-stuffit", + "xpi" => "application/x-xpinstall", + "xhtml" => "application/xhtml+xml", + "xspf" => "application/xspf+xml", + "zip" => "application/zip", + "bin" => "application/octet-stream", + "exe" => "application/octet-stream", + "dll" => "application/octet-stream", + "deb" => "application/octet-stream", + "dmg" => "application/octet-stream", + "img" => "application/octet-stream", + "iso" => "application/octet-stream", + "msi" => "application/octet-stream", + "mp3" => "audio/mpeg", + "ogg" => "audio/ogg", + "m4a" => "audio/x-m4a", + "3gp" => "video/3gpp", + "3gpp" => "video/3gpp", + "ts" => "video/mp2t", + "mp4" => "video/mp4", + "mpg" => "video/mpeg", + "mpeg" => "video/mpeg", + "mov" => "video/quicktime", + "webm" => "video/webm", + "flv" => "video/x-flv", + "m4v" => "video/x-m4v", + "mng" => "video/x-mng", + "wmv" => "video/x-ms-wmv", + "avi" => "video/x-msvideo" + ]; \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/cache/.gitignore b/cache/.gitignore old mode 100644 new mode 100755 diff --git a/cache/hello_f42c5c97192c2cfed90e18fe99b6efe0e0b45e84.bladec b/cache/hello_f42c5c97192c2cfed90e18fe99b6efe0e0b45e84.bladec new file mode 100644 index 0000000..402d4b0 --- /dev/null +++ b/cache/hello_f42c5c97192c2cfed90e18fe99b6efe0e0b45e84.bladec @@ -0,0 +1,17 @@ + + + + + + + + <?php echo \htmlentities($title??'', ENT_QUOTES, 'UTF-8', false); ?> + + + + + + + + + \ No newline at end of file diff --git a/index.php b/index.php old mode 100644 new mode 100755 index dd5b058..6493a44 --- a/index.php +++ b/index.php @@ -1,12 +1,8 @@ "Bir hata oluştu !" - ]); - }); - - Route::Execute(); \ No newline at end of file + if(/*debug*/true) + { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); + } + include_once "Core/Core.php"; \ No newline at end of file diff --git a/public/index.js b/public/index.js new file mode 100644 index 0000000..1fdcebb --- /dev/null +++ b/public/index.js @@ -0,0 +1 @@ +alert("Merhaba"); \ No newline at end of file diff --git a/views/.gitignore b/views/.gitignore old mode 100644 new mode 100755 diff --git a/views/hello.blade.php b/views/hello.blade.php new file mode 100755 index 0000000..4dc755a --- /dev/null +++ b/views/hello.blade.php @@ -0,0 +1,15 @@ + + + + + + + + {{$title}} + + + + {{$text}} + + + \ No newline at end of file