I would like to get non inherited child class public methods. I tried using Reflection Api like this:
$class = new \ReflectionClass($model);
$modelMethods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
$exclude = ['getSource', 'upsert', 'getUniqueKeyAttributes', 'beforeSave', 'columnMap', 'initialize', 'setId', 'getId'];
$CLASS = __CLASS__;
$props = array_filter(array_map(function(\ReflectionMethod $method) use ($exclude, $CLASS) {
if($method->class === $CLASS && !in_array($method->name, $exclude)) {
if(strpos($method->name, 'get') === 0) {
return str_replace('get', '', $method->name);
}
}
}, $props));
I have to get all getters or setters automatically because I got about 60 of them!
Aucun commentaire:
Enregistrer un commentaire