public function discover()
{
$serviceNames = $this->getServiceNames(self::$serviceFolders, self::$serviceNames2ClassFindInfo);
$ret = array();
foreach ($serviceNames as $serviceName) {
$serviceObject = Amfphp_Core_Common_ServiceRouter::getServiceObjectStatically($serviceName, self::$serviceFolders, self::$serviceNames2ClassFindInfo);
$objR = new ReflectionObject($serviceObject);
$objComment = $this->formatComment($objR->getDocComment());
if (false !== strpos($objComment, '@amfphpHide')) {
//methods including @amfHide should not appear in the back office but should still be accessible.
continue;
}
$methodRs = $objR->getMethods(ReflectionMethod::IS_PUBLIC);
$methods = array();
foreach ($methodRs as $methodR) {
$methodName = $methodR->name;
if (substr($methodName, 0, 1) == '_') {
//methods starting with a '_' as they are reserved, so filter them out
continue;
}
$parameters = array();
$paramRs = $methodR->getParameters();
$methodComment = $this->formatComment($methodR->getDocComment());
if (false !== strpos($methodComment, '@amfphpHide')) {
//methods including @amfHide should not appear in the back office but should still be accessible.
continue;
}
$parsedMethodComment = $this->parseMethodComment($methodComment);
foreach ($paramRs as $paramR) {
$parameterName = $paramR->name;
//get type from type hinting or from parsed method comment. type hinting has priority
$type = '';
//get example from parsed method comment only
$example = '';
if (isset($parsedMethodComment['param'][$parameterName])) {
$paramMeta = $parsedMethodComment['param'][$parameterName];
if (isset($paramMeta['type'])) {
$type = $paramMeta['type'];
}
if (isset($paramMeta['example'])) {
$example = $paramMeta['example'];
}
}
try {
//this code will throw an exception saying that the class does not exist, only if the class is a namespace.
//in that case there's not much that can be done, so just ignore type.
if ($paramR->getClass()) {
$type = $paramR->getClass()->name;
}
} catch (Exception $e) {
}
$parameterInfo = new AmfphpDiscovery_ParameterDescriptor($parameterName, $type, $example);
$parameters[] = $parameterInfo;
}
//get return from parsed return comment if exists
$return = '';
if (isset($parsedMethodComment['return'])) {
$return = $parsedMethodComment['return'];
}
$methods[$methodName] = new AmfphpDiscovery_MethodDescriptor($methodName, $parameters, $methodComment, $return);
}
$ret[$serviceName] = new AmfphpDiscovery_ServiceDescriptor($serviceName, $methods, $objComment);
}
//note : filtering must be done at the end, as for example excluding a Vo class needed by another creates issues
foreach ($ret as $serviceName => $serviceObj) {
foreach (self::$excludePaths as $excludePath) {
if (strpos($serviceName, $excludePath) !== false) {
unset($ret[$serviceName]);
break;
}
}
}
return $ret;
}