]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow registering closures for navigation entries
authorJoas Schilling <nickvergessen@owncloud.com>
Mon, 16 Mar 2015 15:17:43 +0000 (16:17 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Mon, 16 Mar 2015 15:17:43 +0000 (16:17 +0100)
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.

lib/private/navigationmanager.php
lib/public/inavigationmanager.php

index 8ad2f4c8f63f2df8d1a10ef1beb2256d758885fd..205ecccd506ff2e7e8043bcc9be1c83eeaa71851 100644 (file)
@@ -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();
        }
 
        /**
index 9497d3fd08e10aa44370402978b1c05e97732220..9e0e682645450146b53460158f54137d42fa5e52 100644 (file)
@@ -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