App
in package
Class App
Any application must inherit this call - all controller instances to be used are to be registered using IContainer::registerService
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- buildAppNamespace() : string
- Turns an app id into a namespace by convention. The id is split at the underscores, all parts are CamelCased and reassembled. e.g.: some_app_id -> OCA\SomeAppId
- dispatch() : mixed
- This function is called by the routing component to fire up the frameworks dispatch mechanism.
- getContainer() : IAppContainer
- registerRoutes() : mixed
- This function is to be called to create single routes and restful routes based on the given $routes array.
Properties
$container
private
IAppContainer
$container
Methods
__construct()
public
__construct(string $appName[, array<string|int, mixed> $urlParams = [] ]) : mixed
Parameters
- $appName : string
- $urlParams : array<string|int, mixed> = []
-
an array with variables extracted from the routes
Tags
buildAppNamespace()
Turns an app id into a namespace by convention. The id is split at the underscores, all parts are CamelCased and reassembled. e.g.: some_app_id -> OCA\SomeAppId
public
static buildAppNamespace(string $appId[, string $topNamespace = 'OCA\' ]) : string
Parameters
- $appId : string
-
the app id
- $topNamespace : string = 'OCA\'
-
the namespace which should be prepended to the transformed app id, defaults to OCA\
Tags
Return values
string —the starting namespace for the app
dispatch()
This function is called by the routing component to fire up the frameworks dispatch mechanism.
public
dispatch(string $controllerName, string $methodName) : mixed
Example code in routes.php of the task app: $this->create('tasks_index', '/')->get()->action( function($params){ $app = new TaskApp($params); $app->dispatch('PageController', 'index'); } );
Example for for TaskApp implementation: class TaskApp extends \OCP\AppFramework\App {
public function __construct($params){
parent::__construct('tasks', $params);
$this->getContainer()->registerService('PageController', function(IAppContainer $c){
$a = $c->query('API');
$r = $c->query('Request');
return new PageController($a, $r);
});
}
}
Parameters
- $controllerName : string
-
the name of the controller under which it is stored in the DI container
- $methodName : string
-
the method that you want to call
Tags
getContainer()
public
getContainer() : IAppContainer
Tags
Return values
IAppContainerregisterRoutes()
This function is to be called to create single routes and restful routes based on the given $routes array.
public
registerRoutes(IRouter $router, array<string|int, mixed> $routes) : mixed
Just return an array from your routes.php
Example code in routes.php of tasks app (it will register two restful resources): $routes = array( 'resources' => array( 'lists' => array('url' => '/tasklists'), 'tasks' => array('url' => '/tasklists/{listId}/tasks') ) );
$a = new TasksApp(); $a->registerRoutes($this, $routes);
Parameters
- $router : IRouter
- $routes : array<string|int, mixed>