public function __construct() { //Not self::$context because Contexts have $context self has null $path = "Models/.model-cache/" . self::getContext() . ".rln"; if (FileSystem::exists($path)) { $data = FileSystem::get($path); $relations = (array) @json_decode($data); $this->linkRelations($relations); } }
public function printView($filePath) { if (!FileSystem::exists(BASE_DIR . "/Views/.cache")) { FileSystem::makeDirectory(BASE_DIR . "/Views/.cache"); } $razr = new Engine(new FileSystemLoader(), BASE_DIR . "/Views/.cache"); $page = new \stdClass(); $page->title = $this->title; $page->author = $this->author; $page->metaContent = $this->metaContent; $this->registeredVariables["MetaPageDetails"] = $page; echo $razr->render($filePath, $this->registeredVariables); }
public function parseClass() { $class = get_class($this); $re = "/Controllers\\\\([A-Z0-9_]*)Controller/i"; preg_match($re, $class, $matches); if (isset($matches[1])) { $cls = $matches[1]; $fullCls = "Models\\Context\\" . $cls; if (FileSystem::exists("Models/Context/" . $cls . ".php") && class_exists("Models\\Context\\" . $cls)) { return $fullCls; } } return null; }
public static function upload(string $path, string $postName = "images", $thumbWidth = 300, $thumbHeight = 300) { $path = FileSystem::getRealPath($path); $response = []; if (isset($_FILES[$postName])) { foreach ($_FILES[$postName]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES[$postName]["tmp_name"][$key]; $name = Etc::sanitize($_FILES[$postName]["name"][$key]); if (move_uploaded_file($tmp_name, "{$path}/{$name}")) { $image = new Image("{$path}/{$name}"); $response[] = ["thumb" => $image->src($thumbWidth, $thumbHeight), "file" => $name]; } } } } return $response; }
public function errorLog() { $now = new \DateTime('now'); $file = "log/" . $now->format("Y-m-d") . ".txt"; try { $logs = FileSystem::get($file); $logs .= "Ref# : " . $this->reference . " || \t"; $logs .= "Level : " . $this->level . "\n"; $logs .= $now->format("Y-m-d h:i:s A") . " || \t"; $logs .= "IP: " . GeoLocation::getIP() . " || \t"; $logs .= "Country: " . GeoLocation::getCountry() . "\n"; $logs .= GeoLocation::userAgent() . "\n"; $logs .= "Error: " . $this->error . "\n"; $logs .= "Debug Errors: " . $this->debugErrors . "\n"; $logs .= "Error Location: " . $this->file . " in line " . $this->line . "\n"; $logs .= "--------------------------------------------------------------------------------------------------------------------------\n"; FileSystem::put($file, $logs); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } }
public static function log($log, $level = 1) { $ref = Etc::getRandomId(); $now = new \DateTime('now'); $file = "log/" . $now->format("Y-m-d") . ".txt"; try { $logs = FileSystem::get($file); $logs .= "Ref# : " . $ref . " || \t"; $logs .= "Level : " . $level . "\n"; $logs .= $now->format("Y-m-d h:i:s A") . " || \t"; $logs .= "IP: " . GeoLocation::getIP() . " || \t"; $logs .= "Country: " . GeoLocation::getCountry() . "\n"; $logs .= GeoLocation::userAgent() . "\n"; $logs .= "Log: " . $log . "\n"; $logs .= "--------------------------------------------------------------------------------------------------------------------------\n"; FileSystem::put($file, $logs); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } return $ref; }
public static function getColumns($table) { $file = "Models/.model-cache/" . $table . ".cols"; if (FileSystem::exists($file)) { $data = FileSystem::get($file); try { return json_decode($data); } catch (\Exception $e) { new Error($e->getMessage(), 0); } } $sql = "SHOW COLUMNS FROM " . $table; $query = new SQLQuery($sql); $results = $query->getResults(); try { FileSystem::put($file, json_encode($results)); } catch (\Exception $e) { new Error($e->getMessage(), 0); } return $results; }
public function getFiles() { $return = []; $exclude = array('..', '.', '.DS_Store', '.git', '.gitignore', '.idea'); $array = array_diff(scandir($this->path), $exclude); foreach ($array as $item) { $path = $this->path . DIRECTORY_SEPARATOR . $item; if (FileSystem::isDirectory($path)) { $return[] = new Directory($path); } else { if (FileSystem::isImage($path)) { $return[] = new Image($path); } else { if (FileSystem::isFile($path)) { $return[] = new File($path); } } } } return $return; }
private function saveTempImage($thumbnail) { if (!FileSystem::exists($this->tempDirectory)) { FileSystem::makeDirectory($this->tempDirectory); } $fileName = $this->tempDirectory . $this->tempFileName(); switch ($this->imageType) { case "image/jpeg": imagejpeg($thumbnail, $fileName); break; case "image/png": imagepng($thumbnail, $fileName); break; case "image/gif": imagegif($thumbnail, $fileName); break; default: die("Invalid Image Type"); break; } }
public static function DeriveRelations($tables, $tableName, $columns) { $data = []; foreach ($columns as $col) { if ($col->Type == "timestamp") { $data[$col->Field] = "DateTime"; } else { if ($col->Type == "date") { $data[$col->Field] = "DateTime"; } else { if ($col->Type == "time") { $data[$col->Field] = "DateTime"; } else { if ($col->Field == "image") { $data[$col->Field] = "hooks\\Media\\Image"; } else { if (in_array($col->Field, $tables)) { $data[$col->Field] = self::$namespace . "\\" . self::generateModelName($col->Field); } else { if (in_array($col->Field . "s", $tables)) { $data[$col->Field] = self::$namespace . "\\" . self::generateModelName($col->Field); } else { if (in_array(rtrim($col->Field, "id"), $tables)) { $data[$col->Field] = self::$namespace . "\\" . self::generateModelName($col->Field); } else { if (in_array(rtrim($col->Field, "Id"), $tables)) { $data[$col->Field] = self::$namespace . "\\" . self::generateModelName($col->Field); } } } } } } } } } echo count($data) . " relations defined."; FileSystem::put("Models/.model-cache/" . $tableName . ".rln", json_encode($data, JSON_PRETTY_PRINT)); }
public static function getContents($path) { $path = self::getRealPath($path); if (FileSystem::exists($path)) { return array_diff(scandir($path), array('..', '.')); } return []; }
public function content() { return FileSystem::get($this->path); }
private function controllerExists($controller, $method) { if (FileSystem::exists(BASE_DIR . "/Controllers/" . ucfirst($controller) . "Controller.php")) { $controllerPath = "Controllers\\" . ucfirst($controller) . "Controller"; if (method_exists($controllerPath, $method)) { return true; } $method = $this->hyphenToCammelCase($method); if (method_exists($controllerPath, $method)) { return true; } } return false; }