Skip to content

Commit 2d012eb

Browse files
committed
switch to default branch 2.x. Add new feature group fcontrollers by sub directory
1 parent f2d7c43 commit 2d012eb

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

Boot/System/Frouting.php

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,118 @@ public function load_page_controller()
237237
}
238238
}
239239
}
240+
240241
} else {
241-
// Controller File not found in parent directory.
242+
243+
// Add Something. Method not found in controller.
244+
// Trying find in parent directory & sub directory and restructure url data & params
245+
246+
$controllerFolderSet = ucfirst(str_replace('-', '_', $tempParsingUrl[0]));
247+
248+
$controllerLoadFileSetParent = $this->bootConfig->base_fcontroller_dir . $controllerFolderSet . '.php';
249+
250+
// check controller file in parent directoy controller
251+
if (file_exists($controllerLoadFileSetParent)) {
252+
253+
$controllerFileNameSet = ucfirst($tempParsingUrl[0]);
254+
$controllerFileNameSet = str_replace('-', '_', $controllerFileNameSet);
255+
256+
$controllerLoadFileSet = $this->bootConfig->base_fcontroller_dir . $controllerFileNameSet . '.php';
257+
258+
// check controller file if exist
259+
if (file_exists($controllerLoadFileSet)) {
260+
261+
include_once $controllerLoadFileSet;
262+
263+
$trySetMethodFromUrl = isset($tempParsingUrl[1]) ?
264+
$tempParsingUrl[1] : $default_set_method;
265+
266+
// unset method name from parsing url.
267+
unset($tempParsingUrl[0]);
268+
unset($tempParsingUrl[1]);
269+
270+
// clean parsing url & set data Params
271+
$tryDataCleanParsingUrl = is_array($tempParsingUrl) ? $tempParsingUrl : [];
272+
$tryParamsFromUrl = array_values($tryDataCleanParsingUrl);
273+
274+
// load method set for call func
275+
$tryLoadMethodSet = str_replace('-', '_', $trySetMethodFromUrl);
276+
$tryLoadMethodSetClean = trim($tryLoadMethodSet) !== '' ?
277+
trim($tryLoadMethodSet) : $default_set_method;
278+
279+
$try_controller_sets = $this->bootConfig->base_fcontroller_dir . $controllerFolderSet .'/'. $controllerFileNameSet;
280+
281+
// auto instance Frontend Controller
282+
$tryControllerLoad = new $controller_set();
283+
284+
// check method in controller is set.
285+
if (method_exists($tryControllerLoad, $tryLoadMethodSetClean)) {
286+
call_user_func_array([$tryControllerLoad, $tryLoadMethodSetClean], $tryParamsFromUrl);
287+
} else {
288+
// Method not found in controller.
289+
}
290+
291+
} else {
292+
// Controller File not found in directory.
293+
}
294+
295+
}else {
296+
297+
// check controller file in any directory in parent controller directory
298+
299+
// check set controller name in url
300+
if (isset($tempParsingUrl[1])) {
301+
302+
$controllerFileNameSet = ucfirst($tempParsingUrl[1]);
303+
$controllerFileNameSet = str_replace('-', '_', $controllerFileNameSet);
304+
305+
$controllerLoadFileSet = $this->bootConfig->base_fcontroller_dir . $controllerFolderSet .'/'. $controllerFileNameSet . '.php';
306+
307+
// check controller file if exist
308+
if (file_exists($controllerLoadFileSet)) {
309+
310+
include_once $controllerLoadFileSet;
311+
312+
$trySetMethodFromUrl = isset($tempParsingUrl[2]) ?
313+
$tempParsingUrl[2] : $default_set_method;
314+
315+
// unset method name from parsing url.
316+
unset($tempParsingUrl[0]);
317+
unset($tempParsingUrl[1]);
318+
319+
if (isset($tempParsingUrl[2])) {
320+
unset($tempParsingUrl[2]);
321+
}
322+
323+
// clean parsing url & set data Params
324+
$tryDataCleanParsingUrl = is_array($tempParsingUrl) ? $tempParsingUrl : [];
325+
$tryParamsFromUrl = array_values($tryDataCleanParsingUrl);
326+
327+
// load method set for call func
328+
$tryLoadMethodSet = str_replace('-', '_', $trySetMethodFromUrl);
329+
$tryLoadMethodSetClean = trim($tryLoadMethodSet) !== '' ?
330+
trim($tryLoadMethodSet) : $default_set_method;
331+
332+
$try_controller_sets = $this->bootConfig->base_fcontroller_dir . $controllerFolderSet .'/'. $controllerFileNameSet;
333+
334+
// auto instance Frontend Controller
335+
$tryControllerLoad = new $controller_set();
336+
337+
// check method in controller is set.
338+
if (method_exists($tryControllerLoad, $tryLoadMethodSetClean)) {
339+
call_user_func_array([$tryControllerLoad, $tryLoadMethodSetClean], $tryParamsFromUrl);
340+
} else {
341+
// Method not found in controller.
342+
}
343+
344+
} else {
345+
// Controller File not found in directory.
346+
}
347+
348+
} else {
349+
// Controller name not set in url.
350+
}
351+
}
242352
}
243353
} else {
244354
// Method not found in Url.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<img src="https://initflex.com/wp-content/uploads/2022/08/initflex-logo-2-stripped-in-full-text-blue-with-double-circle-blue-v2.png" alt= “Initflex” width="auto" height="40px"> <img src="https://raw.githubusercontent.com/initflex/wpframe/main/public/assets/images/logos/android-icon-144x144.png" alt= “” width="auto" height="40px">
66

7-
[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](http://opensource.org/licenses/MIT) [![GitHub](https://img.shields.io/badge/version-2.1.4-lightgrey?style=flat-square)](https://github.com/initflex/wpframe/releases) [![GitHub](https://img.shields.io/badge/wpfx%20version-1.0.2-brightgreen?style=flat-square)](https://github.com/initflex/wpframe/releases) [![GitHub](https://img.shields.io/badge/php%20version-%3E%3D7.4%20%3C=8.1-blue?style=flat-square)](https://php.net/downloads/) [![GitHub](https://img.shields.io/badge/maintained-yes-green?style=flat-square)](https://github.com/initflex/wpframe/) [![GitHub](https://img.shields.io/badge/docs-100%25(Bahasa%20Indonesia)-yellow?style=flat-square)](https://initflex.com/docs/wpframe/) [![GitHub](https://img.shields.io/badge/composer-%3E1.6-green?style=flat-square)](https://getcomposer.org/)
7+
[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](http://opensource.org/licenses/MIT) [![GitHub](https://img.shields.io/badge/version-2.1.5-lightgrey?style=flat-square)](https://github.com/initflex/wpframe/releases) [![GitHub](https://img.shields.io/badge/wpfx%20version-1.0.2-brightgreen?style=flat-square)](https://github.com/initflex/wpframe/releases) [![GitHub](https://img.shields.io/badge/php%20version-%3E%3D7.4%20%3C=8.1-blue?style=flat-square)](https://php.net/downloads/) [![GitHub](https://img.shields.io/badge/maintained-yes-green?style=flat-square)](https://github.com/initflex/wpframe/) [![GitHub](https://img.shields.io/badge/docs-100%25(Bahasa%20Indonesia)-yellow?style=flat-square)](https://initflex.com/docs/wpframe/) [![GitHub](https://img.shields.io/badge/composer-%3E1.6-green?style=flat-square)](https://getcomposer.org/)
88

99
---
1010

0 commit comments

Comments
 (0)