/** * Get routes * * @return array */ public static function getRoutes() { $tempo = array(); $obj = get_called_class(); $ref = new \ReflectionClass(get_called_class()); foreach ($ref->getMethods() as $method) { $methodName = $method->getName(); if (substr($methodName, -6) == 'Action') { foreach (explode("\n", $method->getDocComment()) as $line) { $str = trim(str_replace("* ", '', $line)); if (substr($str, 0, 6) == '@route') { $route = substr($str, 6); $objExp = explode('\\', $obj); $nbOcc = count($objExp) - 1; $finalName = substr($objExp[$nbOcc], 0, strlen($objExp[$nbOcc]) - 3); $route = str_replace('{object}', strtolower($finalName), $route); $tempo[$methodName]['route'] = trim($route); } elseif (substr($str, 0, 7) == '@method') { $method_type = strtoupper(substr($str, 7)); $tempo[$methodName]['method_type'] = trim($method_type); } elseif (substr($str, 0, 4) == '@acl') { $aclFlags = explode(",", trim(substr($str, 4))); $tempo[$methodName]['acl'] = Acl::convertAclFlags($aclFlags); } elseif (substr($str, 0, 5) == '@auth') { $tempo[$methodName]['auth'] = true; } elseif (substr($str, 0, 4) == '@api') { $route = substr($str, 4); /* @todo better */ $objExp = explode('\\', $obj); $nbOcc = count($objExp) - 1; $finalName = substr($objExp[$nbOcc], 0, strlen($objExp[$nbOcc]) - 3); $route = str_replace('{object}', strtolower($finalName), $route); $tempo[$methodName]['api_route'] = trim($route); } elseif (substr($str, 0, 6) == '@since') { $version = substr($str, 6); $tempo[$methodName]['api_version'] = trim($version); } } if (isset($tempo[$methodName]['auth']) && $tempo[$methodName]['auth']) { if (isset($tempo[$methodName]['route'])) { static::$routeAuth[] = '\\' . $obj . '::' . $methodName; } } } } return $tempo; }
/** * Get routes * * @return array */ public static function getRoutes() { $tempo = array(); $className = get_called_class(); $ref = new \ReflectionClass($className); foreach ($ref->getMethods() as $method) { $methodName = $method->getName(); if (substr($methodName, -6) == 'Action') { foreach (explode("\n", $method->getDocComment()) as $line) { $str = trim(str_replace("* ", '', $line)); if (substr($str, 0, 6) == '@route') { $route = substr($str, 6); if (isset($className::$objectName)) { $route = str_replace("{object}", $className::$objectName, $route); } $tempo[$methodName]['route'] = trim($route); } elseif (substr($str, 0, 7) == '@method') { $method_type = strtoupper(substr($str, 7)); $tempo[$methodName]['method_type'] = trim($method_type); } elseif (substr($str, 0, 4) == '@acl') { $aclFlags = explode(",", trim(substr($str, 4))); $tempo[$methodName]['acl'] = Acl::convertAclFlags($aclFlags); } } } } return $tempo; }