diff --git a/README.md b/README.md index a1a1d48..2ee10c6 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,31 @@ # Wepesi + * Wepesi library -`wepesi` is the quick ans simple framework the help you devellop simple web application with php and design OOP concept, -it has been design by following most off principle for big framework but make it simple for develloper. + `wepesi` is the quick ans simple framework the help you devellop simple web application with php and design OOP + concept, + it has been design by following most off principle for big framework but make it simple for develloper. ## Installation + The installation of the application does not require somuch thing; + - In you are familliar with `composer` to install : -You can find project directly on packagest on : https://packagist.org/packages/wepesi/wepesi + You can find project directly on packagest on : https://packagist.org/packages/wepesi/wepesi + ```shell composer create-project wepesi/wepesi ``` + and it will create a project for You. -- In case you are not familliar with `composer` you can donwload it directly the source code on github on :https://github.com/kivudesign/Wepesi, no nee of extra module to start workin on the project. +- In case you are not familliar with `composer` you can donwload it directly the source code on github + on :https://github.com/kivudesign/Wepesi, no nee of extra module to start workin on the project. # Intoduction -Wepesi is a simple Web framework that help you devellop simple web application, and benefit advantage of large php framework like + +Wepesi is a simple Web framework that help you devellop simple web application, and benefit advantage of large php +framework like + - routing - controller - simple ORM *without migration @@ -25,24 +35,33 @@ Wepesi is a simple Web framework that help you devellop simple web application, - Validation - View -All module are built-id, its has been design to give to make the framework flexible, you can restructure everything as you want and be able to add more module. +All module are built-id, its has been design to give to make the framework flexible, you can restructure everything as +you want and be able to add more module. # Integration -no need to know about composer, the simple way is to download the all the project and place on the server side devellopenent. + +no need to know about composer, the simple way is to download the all the project and place on the server side +devellopenent. decompress the file, and folder the instruction. -- if you are using `wamp`, place the decopress folder on the `www` folder of `wamp` folder with is on the root of the dick c: on windows + +- if you are using `wamp`, place the decopress folder on the `www` folder of `wamp` folder with is on the root of the + dick c: on windows - if you are using `xamp`, you place the folder on the `htdocs` -you can rename the folder as you want according to you need + you can rename the folder as you want according to you need # Structure + the library is subdivised in multiple part with folder, we have: -- `class` : where all model and where we can find the core logic to run the libray. - there is a folder call `app`, in with you are not allowed to modified any class if you dont know what you are doing. - in some case, it will have an impact on the way your application is working. -- `controller`: where you can creat all the controller. the system has been designed like that to make a difference between controller and model. + +- `class` : where all model and where we can find the core logic to run the libray. + there is a folder call `app`, in with you are not allowed to modified any class if you dont know what you are doing. + in some case, it will have an impact on the way your application is working. +- `controller`: where you can creat all the controller. the system has been designed like that to make a difference + between controller and model. - `config`: where you can config the database configuration, and the autoloading. -- `layout`: the layout help manage all `css style` or `javascript script`, or not. the idea, is to have a better logical. in case you use the layout, - there is a way yu can accee those file by using wepesi class `Bundle`. +- `layout`: the layout help manage all `css style` or `javascript script`, or not. the idea, is to have a better + logical. in case you use the layout, + there is a way yu can accee those file by using wepesi class `Bundle`. - `route`: is where you can define all your route - `views`: here is where you will create all the pages that will display by the user. - `index.php`: this is the main file. to start the app, diff --git a/assets/index.php b/assets/index.php deleted file mode 100644 index 345f463..0000000 --- a/assets/index.php +++ /dev/null @@ -1,5 +0,0 @@ -load(); +(new DotEnv(dirname(__DIR__) . '/.env'))->load(); $GLOBALS['config'] ['mysql'] = [ diff --git a/config/function.php b/config/function.php index 0ceae2d..29bf15e 100644 --- a/config/function.php +++ b/config/function.php @@ -20,10 +20,12 @@ function getSubDirectories(string $dir): array * @param $class * @return false|mixed|string */ -function extractNamespace($class){ - $class_arr = explode("\\",$class); +function extractNamespace($class) +{ + $class_arr = explode("\\", $class); return end($class_arr); } + /** * @param $fileName * @return mixed|string @@ -38,26 +40,27 @@ function checkFileExtension($fileName) * @param array $exclude_folder * @return void */ -function autoIndexFolder(array $exclude_folder = []){ +function autoIndexFolder(array $exclude_folder = []) +{ $app_root = appDirSeparator(dirname(__DIR__)); // check if cache directory exists before processing - $cash_file_dir = appDirSeparator($app_root.'/cache'); + $cash_file_dir = appDirSeparator($app_root . '/cache'); if (!file_exists($cash_file_dir)) { mkdir($cash_file_dir, 0777, true); } // define exclude folder to not be affected by the situation. $exclude = ['vendor', 'test']; - if(count($exclude_folder)) $exclude = array_merge($exclude,$exclude_folder); - $implode = implode('|',$exclude); + if (count($exclude_folder)) $exclude = array_merge($exclude, $exclude_folder); + $implode = implode('|', $exclude); $folder_struct = getSubDirectories($app_root); - $filter = array_filter($folder_struct,function($folder_name) use ($implode) { + $filter = array_filter($folder_struct, function ($folder_name) use ($implode) { $pattern = "/$implode/i"; - if(!preg_match($pattern, strtolower(trim($folder_name)))) { + if (!preg_match($pattern, strtolower(trim($folder_name)))) { return $folder_name; } }); - if(!checkCacheContent($cash_file_dir, $filter)){ + if (!checkCacheContent($cash_file_dir, $filter)) { foreach ($filter as $subFolder) { if (!is_file($subFolder . '/index.php')) { copy(__DIR__ . '/index.php', $subFolder . '/index.php'); @@ -74,18 +77,18 @@ function autoIndexFolder(array $exclude_folder = []){ function checkCacheContent(string $cash_file_dir, array $filter): bool { $status = true; - $cash_file_path = appDirSeparator($cash_file_dir.'/index_folder.txt'); + $cash_file_path = appDirSeparator($cash_file_dir . '/index_folder.txt'); sort($filter); - $file_content = json_encode($filter,true); + $file_content = json_encode($filter, true); $cache_file = fOpen($cash_file_path, 'a+'); - if(!is_file($cash_file_path) || filesize($cash_file_path) < 1 ){ - fwrite($cache_file,$file_content); - }else{ - $content = fread($cache_file,filesize($cash_file_path)); - if($content != $file_content) { + if (!is_file($cash_file_path) || filesize($cash_file_path) < 1) { + fwrite($cache_file, $file_content); + } else { + $content = fread($cache_file, filesize($cash_file_path)); + if ($content != $file_content) { $cache_file = fOpen($cash_file_path, 'w'); fwrite($cache_file, $file_content); - }else{ + } else { $status = false; } } @@ -97,7 +100,8 @@ function checkCacheContent(string $cash_file_dir, array $filter): bool * @param string $path * @return string */ -function appDirSeparator(string $path):string{ +function appDirSeparator(string $path): string +{ $new_path = $path; if ((substr(PHP_OS, 0, 3)) === 'WIN') $new_path = str_replace("\\", '/', $path); return $new_path; @@ -107,7 +111,8 @@ function appDirSeparator(string $path):string{ * @param $ex * @return void */ -function dumper($ex){ +function dumper($ex) +{ print('
'); print_r($ex); print(''); diff --git a/config/globals.php b/config/globals.php index 35581bb..39fd723 100644 --- a/config/globals.php +++ b/config/globals.php @@ -15,5 +15,5 @@ 'vendor' => true, 'autoload' => ['src', 'controller', 'middleware', 'models', 'helpers'], 'helper' => WEB_ROOT, - 'preferences' => WEB_ROOT. 'helper' + 'preferences' => WEB_ROOT . 'helper' ]; \ No newline at end of file diff --git a/config/index.php b/config/index.php deleted file mode 100644 index 345f463..0000000 --- a/config/index.php +++ /dev/null @@ -1,5 +0,0 @@ -load(); +(new DotEnv($ROOT_DIR . '/.env'))->load(); $appConfiguration = new AppConfiguration(); diff --git a/lang/en/index.php b/lang/en/index.php deleted file mode 100644 index 345f463..0000000 --- a/lang/en/index.php +++ /dev/null @@ -1,5 +0,0 @@ -"Welcom" +$language = [ + "Welcom" => "Welcom" ]; -$validation=[ - "required"=>"required", - "min"=>"must be a minimum of", - "max"=>"must be a maximum of", - "matches"=>"must match", - "number"=>"must be a number", - "email"=>"invalid email address", - "url"=>"invalid url", - "file"=>"should be a file", - "unique"=>"already exist.", - "unknown"=>"unknown" +$validation = [ + "required" => "required", + "min" => "must be a minimum of", + "max" => "must be a maximum of", + "matches" => "must match", + "number" => "must be a number", + "email" => "invalid email address", + "url" => "invalid url", + "file" => "should be a file", + "unique" => "already exist.", + "unknown" => "unknown" ]; diff --git a/lang/fr/index.php b/lang/fr/index.php deleted file mode 100644 index 345f463..0000000 --- a/lang/fr/index.php +++ /dev/null @@ -1,5 +0,0 @@ -"Bienvenu", - "Welcome to Wepesi"=>"Bienvenu chez Wepesi", - "you can find the simple example here"=>"Vous pouvez trouvez un exemple ici", - "A Simple Php MVC platform to develop quickly a php application"=>"Une plateforme Simple Php MVC pour développer rapidement une application web", - "Home"=>"Acceuill", - "contact"=>"contact", - "Translate"=>"Traduire", - "Change the language"=>"Changez de langue" +$language = [ + "Welcome" => "Bienvenu", + "Welcome to Wepesi" => "Bienvenu chez Wepesi", + "you can find the simple example here" => "Vous pouvez trouvez un exemple ici", + "A Simple Php MVC platform to develop quickly a php application" => "Une plateforme Simple Php MVC pour développer rapidement une application web", + "Home" => "Acceuill", + "contact" => "contact", + "Translate" => "Traduire", + "Change the language" => "Changez de langue" ]; -$validation=[ - "required"=> "est obligatoire", - "min"=> "doit être au minimum", - "max"=> "doit être au maximum", - "matches"=> "doit correspondre", - "number"=> "doit être un nombre", - "email"=> "Adresse e-mail invalide", - "url"=>"invalid url", - "file"=> "devrait être un fichier", - "unique"=> "existe déjà.", - "unknown"=> "Inconus." +$validation = [ + "required" => "est obligatoire", + "min" => "doit être au minimum", + "max" => "doit être au maximum", + "matches" => "doit correspondre", + "number" => "doit être un nombre", + "email" => "Adresse e-mail invalide", + "url" => "invalid url", + "file" => "devrait être un fichier", + "unique" => "existe déjà.", + "unknown" => "Inconus." ]; \ No newline at end of file diff --git a/middleware/Validation/exampleValidation.php b/middleware/Validation/exampleValidation.php index 6f76627..63bc0fa 100644 --- a/middleware/Validation/exampleValidation.php +++ b/middleware/Validation/exampleValidation.php @@ -1,11 +1,13 @@ $this->schema->string("token") ->min(1) @@ -17,8 +19,8 @@ function changeLang(){ ->required() ]; - $this->validate->check($_POST,$rules); - if(!$this->validate->passed()){ + $this->validate->check($_POST, $rules); + if (!$this->validate->passed()) { dumper($this->validate->errors()); exit(); } diff --git a/src/Core/Application.php b/src/Core/Application.php index 4d3184b..a60af14 100644 --- a/src/Core/Application.php +++ b/src/Core/Application.php @@ -82,19 +82,20 @@ private function domainSetup(): object * use method to get domain ip * @return string */ - public static function getDomainIp() : string + public static function getDomainIp(): string { $ip = $_SERVER['REMOTE_ADDR']; - if (! empty($_SERVER['HTTP_CLIENT_IP'])) { + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; - } elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif ($ip == '::1') { $ip = gethostbyname(getHostName()); } return $ip; } + /** * simple builtin dumper for dump data * @param $ex @@ -115,7 +116,7 @@ public static function dumper($ex) */ public static function setLayout(string $layout) { - self::$LAYOUT = self::$ROOT_DIR.'/views/'.$layout; + self::$LAYOUT = self::$ROOT_DIR . '/views/' . $layout; } /** diff --git a/src/Core/Bundles.php b/src/Core/Bundles.php index d92a9ae..ef920e9 100644 --- a/src/Core/Bundles.php +++ b/src/Core/Bundles.php @@ -2,8 +2,6 @@ namespace Wepesi\Core; -use Wepesi\Core\MetaData; - /** * */ @@ -49,7 +47,7 @@ public static function getHeaderJS() * manage to add javascript script on the page * @param string $file */ - static function insertJS(string $file,bool $is_module = false, bool $not_void=false) + static function insertJS(string $file, bool $is_module = false, bool $not_void = false) { if (is_file(ROOT . 'assets/js/' . $file . '.js')) { $src = WEB_ROOT . "assets/js/$file.js"; @@ -57,7 +55,7 @@ static function insertJS(string $file,bool $is_module = false, bool $not_void=fa $link = <<