Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 81e0a25

Browse files
Se crea helper para core y validacion de controlador y metodo
1 parent daf567e commit 81e0a25

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

‎index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
$method = $router->getMethod();
99
$param = $router->getParam();
1010

11+
if(!CoreHelper::validateController($controller))
12+
throw new Exception("Controlador $controller no fue encontrado");
13+
1114
require PATH_CONTROLLERS . "{$controller}/{$controller}Controller.php";
15+
1216
$controller .= 'Controller';
1317

18+
if(!CoreHelper::validateMethodController($controller, $method))
19+
throw new Exception("El método {$method} del controlador {$controller} no fue encontrado");
20+
1421
$controller = new $controller;
1522

1623
$controller->$method($param);

‎system/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
define('PATH_CONTROLLERS', 'app/controllers/');
1717

18+
define('HELPER_PATH', 'system/helpers/');
19+
1820
//////////////////////////////////////
1921
// Valores de core
2022
/////////////////////////////////////

‎system/core/autoload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
spl_autoload_register(function ($class) {
33
if(is_file(CORE . "$class.php"))
4-
require CORE . "$class.php";
4+
return require CORE . "$class.php";
5+
if(is_file(HELPER_PATH . "$class.php"))
6+
return require HELPER_PATH . "$class.php";
57
});

‎system/helpers/CoreHelper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
class CoreHelper
6+
{
7+
public static function validateController($controller)
8+
{
9+
if(!is_file(PATH_CONTROLLERS . "{$controller}/{$controller}Controller.php"))
10+
return false;
11+
return true;
12+
}
13+
14+
public static function validateMethodController($controller, $method)
15+
{
16+
if(!method_exists($controller, $method))
17+
return false;
18+
return true;
19+
}
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /