- var_dump: documentation ( source)
- class_exists: documentation ( source)
- func_get_args: documentation ( source)
- print_r: documentation ( source)
- ucfirst: documentation ( source)
<?php
class Object {
//
protected $hasMany;
protected $theSignificativeProperties = ['nome', 'login'];
public function getHasMany() {
return $this->hasMany;
}
public function getSignificativeProperties() {
return $this->theSignificativeProperties;
}
}
class Aluno extends Object {
private $nome;
private $login;
protected $hasMany = ['post', 'disciplina'];
protected $theSignificativeProperties = ['nome', 'login'];
/*public function getHasMany() {
return $this->hasMany;
}*/
/*public function getSignificativeProperties() {
return $this->theSignificativeProperties;
}*/
}
class Post extends Object {
//
}
class Disciplina extends Object {
protected $hasMany = ['aluno'];
}
class EntityManager {
//
}
class RelationalEntityManager extends EntityManager {
public function find() {
//
echo 'Usando o RelationalEntityManager.';
}
}
class BaseController {
protected $objectService;
protected $model;
public function __construct($modelName) {
$this->model = $modelName;
$this->objectService = new BaseObjectService($modelName, new RelationalEntityManager());
}
public function view() {
$args = func_get_args();
$this->objectService->view($args);
}
}
class AlunoController extends BaseController {
}
class BaseObjectService {
protected $em;
protected $model;
public function __construct($modelName, EntityManager $entityManager) {
$this->model = $modelName;
$this->em = $entityManager;
}
public function view($args) {
//
echo 'Argumentos: ';
print_r($args);
echo 'Classe em questão: ' . $this->model;
echo ' -> Propriedades: ';
$reflect = new ReflectionClass(ucfirst($this->model));
// $props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
$props = $reflect->getProperties();
foreach ($props as $prop) {
print $prop->getName() . ", ";
}
$methods = $reflect->getMethods();
foreach ($methods as $method) {
print $method->getName() . ", ";
if ( $method->getName() == 'getHasMany') {
echo 'achou o HASMANY de ' . $this->model ;
print_r($reflect->getHasMany());
}
}
// var_dump($props);
$this->em->find();
}
}
echo 'Aluno: ' . class_exists('Aluno') . '<br>';
echo 'Teste: '; var_dump(class_exists('Teste')) . '\n';
$a = new Aluno();
print_r ( $a->getSignificativeProperties() );
$alunoController = new AlunoController('aluno');
$alunoController->view('marcelo', 'boi', 1);