W prostym systemie pluginow potrzebuje pobrac nazwy wszystkich metod publicznych danej klasy pluginu.
Mam taka klase:
<?php class SprockReflection { private $oReflection; public function __construct(ReflectionClass $oR) { $this->oReflection = $oR; foreach ($this->oReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $oM) { $this->aServices[] = $oM; } } public function __call($method, $args) { if (method_exists($this->oReflection, $method)) { return $this->oReflection->{$method}($args); } } /** * Get all the public methods from the plugin class and store them in an array * Uses Reflection API: ReflectionClass and ReflectionMethod * @return array */ public function getServices() { return $this->aServices; } } ?>
Ktorej uzywam w sposob nastepujacy:
<?php $ins = new SprockReflection(new ReflectionClass('news')); $a = new ArrayObject($ins->getServices()); for ($it = $a->getIterator(); $it->valid(); $it->next()) { $c = $it->current(); } ?>
I teraz moje pytanie - czy to rozwiazanie jest w miare optymalne? Czy jest prostszy lub lepszy sposob na wyciagniecie nazw kazdej metody publicznej (ale rowniez obiektu)
Pzdr