summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-03-16 16:17:43 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-03-16 16:17:43 +0100
commit970846624feb154800666c7c3293d9ec27861c71 (patch)
treefc6ea288065b2c85735c1ba1791b8f210d5d782d
parent1075914f8ab8f5f4c20ab7f0b9ce35e9a9e2ffe1 (diff)
downloadnextcloud-server-970846624feb154800666c7c3293d9ec27861c71.tar.gz
nextcloud-server-970846624feb154800666c7c3293d9ec27861c71.zip
Allow registering closures for navigation entries
This speeds up all pages that don't use the navigation by 0.04sec per app, because we don't need to create the routing anymore, unless we really need to.
-rw-r--r--lib/private/navigationmanager.php19
-rw-r--r--lib/public/inavigationmanager.php7
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/private/navigationmanager.php b/lib/private/navigationmanager.php
index 8ad2f4c8f63..205ecccd506 100644
--- a/lib/private/navigationmanager.php
+++ b/lib/private/navigationmanager.php
@@ -14,13 +14,23 @@ namespace OC;
*/
class NavigationManager implements \OCP\INavigationManager {
protected $entries = array();
+ protected $closureEntries = array();
protected $activeEntry;
/**
* Creates a new navigation entry
- * @param array $entry containing: id, name, order, icon and href key
+ *
+ * @param array|\Closure $entry Array containing: id, name, order, icon and href key
+ * The use of a closure is preferred, because it will avoid
+ * loading the routing of your app, unless required.
+ * @return void
*/
- public function add(array $entry) {
+ public function add($entry) {
+ if ($entry instanceof \Closure) {
+ $this->closureEntries[] = $entry;
+ return;
+ }
+
$entry['active'] = false;
if(!isset($entry['icon'])) {
$entry['icon'] = '';
@@ -33,6 +43,10 @@ class NavigationManager implements \OCP\INavigationManager {
* @return array an array of the added entries
*/
public function getAll() {
+ foreach ($this->closureEntries as $c) {
+ $this->add($c());
+ }
+ $this->closureEntries = array();
return $this->entries;
}
@@ -41,6 +55,7 @@ class NavigationManager implements \OCP\INavigationManager {
*/
public function clear() {
$this->entries = array();
+ $this->closureEntries = array();
}
/**
diff --git a/lib/public/inavigationmanager.php b/lib/public/inavigationmanager.php
index 9497d3fd08e..9e0e6826454 100644
--- a/lib/public/inavigationmanager.php
+++ b/lib/public/inavigationmanager.php
@@ -36,10 +36,13 @@ namespace OCP;
interface INavigationManager {
/**
* Creates a new navigation entry
- * @param array $entry containing: id, name, order, icon and href key
+ *
+ * @param array|\Closure $entry Array containing: id, name, order, icon and href key
+ * The use of a closure is preferred, because it will avoid
+ * loading the routing of your app, unless required.
* @return void
*/
- public function add(array $entry);
+ public function add($entry);
/**
* Sets the current navigation entry of the currently running app