Skip to content

Commit

Permalink
[ENH] refactor and clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
bim-g committed Jan 2, 2024
1 parent 7cefb62 commit bc00900
Show file tree
Hide file tree
Showing 48 changed files with 702 additions and 633 deletions.
49 changes: 34 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions assets/index.php

This file was deleted.

13 changes: 8 additions & 5 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
$autoload = is_string($config['autoload']) ? [$config['autoload']] : $config['autoload'];
}
// check project is still on development.
if (! APP_DEV){
if (!APP_DEV) {
autoIndexFolder();
}
// builtin autoload
spl_autoload_register(function ($class) use ($autoload) {
spl_autoload_register(/**
* @param $class
* @return void
*/ function ($class) use ($autoload) {
$app_root = appDirSeparator(dirname(__DIR__));
foreach ($autoload as $src){
$folder = $app_root. '/' .$src;
foreach ($autoload as $src) {
$folder = $app_root . '/' . $src;
$dirs = getSubDirectories($folder);
$classFile = extractNamespace($class);
foreach ($dirs as $dir) {
Expand All @@ -32,4 +35,4 @@
}
}
}
},true);
}, true);
2 changes: 1 addition & 1 deletion config/constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@

// define in witch cycle are you are working on.
// in case you are in dev, indexing file will not be generated, but in prod fase, it will be generated
define('APP_DEV',true);
define('APP_DEV', true);
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Wepesi\Core\DotEnv;

(new DotEnv(dirname(__DIR__).'/.env'))->load();
(new DotEnv(dirname(__DIR__) . '/.env'))->load();

$GLOBALS['config'] ['mysql'] =
[
Expand Down
43 changes: 24 additions & 19 deletions config/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -107,7 +111,8 @@ function appDirSeparator(string $path):string{
* @param $ex
* @return void
*/
function dumper($ex){
function dumper($ex)
{
print('<pre>');
print_r($ex);
print('</pre>');
Expand Down
2 changes: 1 addition & 1 deletion config/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
'vendor' => true,
'autoload' => ['src', 'controller', 'middleware', 'models', 'helpers'],
'helper' => WEB_ROOT,
'preferences' => WEB_ROOT. 'helper'
'preferences' => WEB_ROOT . 'helper'
];
5 changes: 0 additions & 5 deletions config/index.php

This file was deleted.

18 changes: 9 additions & 9 deletions config/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

session_start();

require_once $ROOT_DIR.'/config/constant.php';
require_once $ROOT_DIR . '/config/constant.php';
/**
* Application Global Configuration
*/
require_once $ROOT_DIR. '/config/globals.php';
require_once $ROOT_DIR . '/config/globals.php';

/**
* Project General built-in Functions
*/
require_once $ROOT_DIR. '/config/function.php';
require_once $ROOT_DIR . '/config/function.php';

/**
* Project autoload register
*/
require_once $ROOT_DIR. '/config/autoload.php';
require_once $ROOT_DIR. '/vendor/autoload.php';
require_once $ROOT_DIR . '/config/autoload.php';
require_once $ROOT_DIR . '/vendor/autoload.php';
/**
* Project Utils
*/

require_once $ROOT_DIR.'/config/database.php';
require_once $ROOT_DIR . '/config/database.php';

/**
* Init default lang
*/
if(class_exists(\Wepesi\Core\Session::class)){
if(\Wepesi\Core\Session::get('lang') == ''){
\Wepesi\Core\Session::put('lang',$GLOBALS['config']['lang']);
if (class_exists(\Wepesi\Core\Session::class)) {
if (\Wepesi\Core\Session::get('lang') == '') {
\Wepesi\Core\Session::put('lang', $GLOBALS['config']['lang']);
}
}
23 changes: 14 additions & 9 deletions controller/exampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@
* Wepesi Home Controller
*
*/

namespace Wepesi\Controller;

use Wepesi\Core\Input;
use Wepesi\Core\Redirect;
use Wepesi\Core\Session;

class exampleController{
class exampleController
{

/**
* @return void
*/
function home(){
Redirect::to("/");
}
function home()
{
Redirect::to("/");
}

/**
* @return void
*/
function changeLang(){
Session::put('lang', Input::get("lang"));
Redirect::to("/");
}
}
function changeLang()
{
Session::put('lang', Input::get("lang"));
Redirect::to("/");
}
}
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

require_once $ROOT_DIR . '/config/init.php';

(new DotEnv($ROOT_DIR.'/.env'))->load();
(new DotEnv($ROOT_DIR . '/.env'))->load();

$appConfiguration = new AppConfiguration();

Expand Down
5 changes: 0 additions & 5 deletions lang/en/index.php

This file was deleted.

26 changes: 13 additions & 13 deletions lang/en/language.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
$language=[
"Welcom"=>"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"
];
5 changes: 0 additions & 5 deletions lang/fr/index.php

This file was deleted.

Loading

0 comments on commit bc00900

Please sign in to comment.