Skip to content

Instantly share code, notes, and snippets.

@AngeloMerlo
Created September 7, 2013 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngeloMerlo/6479352 to your computer and use it in GitHub Desktop.
Save AngeloMerlo/6479352 to your computer and use it in GitHub Desktop.
pergunta no grupo php facebook.
<?php
class Loader{
private $_mod;
private $class = array("ModeloTeste");
function __construct(){
//cria o array de objetos
foreach ($this->class as $Instancia) {
$this->addMod(new $Instancia());
}
}
function addMod($arg){
//veririfica se o parametro é um objeto
if(is_object($arg)){
//adiciona objeto ao array
$this->_mod[] = $arg;
}
}
function __call($metodo, $parametros = array()){
$error = true;
//varre o array de objetos
foreach ($this->_mod as $objeto) {
//verifica se o metodo existe no objeto
if (method_exists($objeto,$metodo)) {
$error = false;
// chama o metodo do objeto com seus respectivos parametros
$resposta = call_user_func_array(array(&$objeto, $metodo), $parametros);
break;
}
}
if ($error == true) {
trigger_error(error_msg);
} else {
return $resposta;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment