summaryrefslogtreecommitdiffstats
path: root/lib/private/appframework/app.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/appframework/app.php')
-rw-r--r--lib/private/appframework/app.php44
1 files changed, 41 insertions, 3 deletions
diff --git a/lib/private/appframework/app.php b/lib/private/appframework/app.php
index f56ba4af870..b94c7bd9957 100644
--- a/lib/private/appframework/app.php
+++ b/lib/private/appframework/app.php
@@ -24,8 +24,9 @@
namespace OC\AppFramework;
-use OC\AppFramework\DependencyInjection\DIContainer;
-
+use \OC_App;
+use \OC\AppFramework\DependencyInjection\DIContainer;
+use \OCP\AppFramework\QueryException;
/**
* Entry point for every request in your app. You can consider this as your
@@ -37,6 +38,34 @@ class App {
/**
+ * Turns an app id into a namespace by either reading the appinfo.xml's
+ * namespace tag or uppercasing the appid's first letter
+ * @param string $appId the app id
+ * @param string $topNamespace the namespace which should be prepended to
+ * the transformed app id, defaults to OCA\
+ * @return string the starting namespace for the app
+ */
+ public static function buildAppNamespace($appId, $topNamespace='OCA\\') {
+ // first try to parse the app's appinfo/info.xml <namespace> tag
+ $filePath = OC_App::getAppPath($appId) . '/appinfo/info.xml';
+ $loadEntities = libxml_disable_entity_loader(false);
+ $xml = @simplexml_load_file($filePath);
+ libxml_disable_entity_loader($loadEntities);
+
+ if ($xml) {
+ $result = $xml->xpath('/info/namespace');
+ if ($result && count($result) > 0) {
+ // take first namespace result
+ return $topNamespace . trim((string) $result[0]);
+ }
+ }
+
+ // if the tag is not found, fall back to uppercasing the first letter
+ return $topNamespace . ucfirst($appId);
+ }
+
+
+ /**
* Shortcut for calling a controller method and printing the result
* @param string $controllerName the name of the controller under which it is
* stored in the DI container
@@ -48,7 +77,16 @@ class App {
if (!is_null($urlParams)) {
$container['urlParams'] = $urlParams;
}
- $controller = $container[$controllerName];
+ $appName = $container['AppName'];
+
+ // first try $controllerName then go for \OCA\AppName\Controller\$controllerName
+ try {
+ $controller = $container->query($controllerName);
+ } catch(QueryException $e) {
+ $appNameSpace = self::buildAppNamespace($appName);
+ $controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
+ $controller = $container->query($controllerName);
+ }
// initialize the dispatcher and run all the middleware before the controller
$dispatcher = $container['Dispatcher'];