Last active
October 31, 2016 19:09
-
-
Save victorknust/45ce2e43d7b3236a32e2 to your computer and use it in GitHub Desktop.
This file contains 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 Generica { | |
private $dados = array(); | |
public function __set( $chave, $valor ) { | |
$this->dados[$chave] = $valor; | |
} | |
public function __get( $chave ) { | |
if ( !$this->__isset( $chave ) ) { | |
return null; | |
} | |
return $this->dados[$chave]; | |
} | |
public function __isset( $chave ) { | |
return isset( $this->dados[$chave] ); | |
} | |
public function __unset( $chave ) { | |
if ( !$this->__isset( $chave ) ) { | |
return null; | |
} | |
unset( $this->dados[$chave] ); | |
} | |
public function __call( $metodo, $valor = null ) { | |
$prefixo = strtolower(substr($metodo, 0, 3)); | |
$chave = substr($metodo, 3); | |
$chave = lcfirst($chave); | |
if ($prefixo == 'get') { | |
$this->__get( $chave ); | |
} else if ($prefixo == 'set') { | |
if (count($valor) <= 1) { | |
$valor = $valor[0]; | |
} | |
$this->__set( $chave, $valor ); | |
} else { | |
throw new \Exception(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment