/** * Discover and reflect services and their methods * * @link http://php.net/reflection * @see Butler::factory() * @return array */ public function reflectServices() { $ref = new ReflectionClass('Butler'); $path = preg_replace('/\\.php$/', '', $ref->getFileName()); $allServices = array(); $services = array(); $ignore = array('butler', 'Common', 'Exception', '.svn', 'Serialize'); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if (!is_dir($file) && preg_match('/^[a-z].*\\.php$/i', $file)) { $file = ereg_replace('\\.php', '', $file); if (!in_array($file, $ignore)) { $services[] = "{$file}"; } } } closedir($handle); } foreach ($services as $s) { $service = Butler::factory($s); $refl = new ReflectionClass($service); $methods = array(); foreach ($refl->getMethods() as $method) { if ($method->isPublic() && substr($method->name, 0, 2) != '__') { $methods[] = $method->getName(); } } $allServices[] = array('name' => $s, 'method' => $methods); } return array('service' => $allServices); }