2
Setting
I use a method to dynamically instantiate classes and methods.
Properties received:
modulo
= name of briefcase with the files.class.php
ferramenta
= name of filing cabinet.class.php
acao
= name of method
Method executing the request:
private function executar()
{
try {
# Monta o patch e faz require da classe
$classe = DIR_MODULOS . $this -> modulo . DS . $this -> ferramenta . '.class.php';
require_once $classe;
# Instancia o objeto e executa o método
$obj = new $this -> ferramenta();
$resposta = $obj -> {$this -> acao}($this -> dados);
# Retorna a resposta
$this -> retorno = $resposta;
} catch (Exception $e) {
$this -> error = $e->getMessage();
}
}
Problems
- If the property
modulo
incorrect, will not find the folder path.- Error: Warning and Fatal Error of require.
- If the property
ferramenta
incorrect, will not find the class file.- Error: Warning and Fatal Error of require.
- If the property
acao
is incorrect, you will not find the method in the class.- Error: Error in method call: Fatal error: Call to Undefined method
Doubt
How best to deal with mistakes since the
try-catch
does not treat them?(preferably native functions)
Goal
The idea is to return only one string simple according to error.
Example:
- "Invalid module"
- "Invalid tool"
- "Invalid action"
I understood what you meant, but I like to treat any "possible" error, even if it will still be I who make the requisitions. But I would like to make the return as simple as possible. The "module" and "tool" I am already dealing with the
file_exists
, I have not yet looked at the "action" that is the method request. The idea would be to treat them, I do not want to change the code. I may have typo, so why not facilitate the return of the reason for the error!?– rbz
Depending on how you do you have a huge security hole. Like I do not argue, I always speak of what is right, when it is done by taste ,anything serves.
– Maniero
I agree, the more dynamic, the more possible failures. But those I’m going to treat in a previous layer, considering that if you go beyond it, you can execute the rest.
– rbz