Created
September 7, 2013 21:12
-
-
Save AngeloMerlo/6479352 to your computer and use it in GitHub Desktop.
pergunta no grupo php facebook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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