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.
This commit is contained in:
parent
1075914f8a
commit
970846624f
|
@ -14,13 +14,23 @@ namespace OC;
|
||||||
*/
|
*/
|
||||||
class NavigationManager implements \OCP\INavigationManager {
|
class NavigationManager implements \OCP\INavigationManager {
|
||||||
protected $entries = array();
|
protected $entries = array();
|
||||||
|
protected $closureEntries = array();
|
||||||
protected $activeEntry;
|
protected $activeEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new navigation entry
|
* 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;
|
$entry['active'] = false;
|
||||||
if(!isset($entry['icon'])) {
|
if(!isset($entry['icon'])) {
|
||||||
$entry['icon'] = '';
|
$entry['icon'] = '';
|
||||||
|
@ -33,6 +43,10 @@ class NavigationManager implements \OCP\INavigationManager {
|
||||||
* @return array an array of the added entries
|
* @return array an array of the added entries
|
||||||
*/
|
*/
|
||||||
public function getAll() {
|
public function getAll() {
|
||||||
|
foreach ($this->closureEntries as $c) {
|
||||||
|
$this->add($c());
|
||||||
|
}
|
||||||
|
$this->closureEntries = array();
|
||||||
return $this->entries;
|
return $this->entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +55,7 @@ class NavigationManager implements \OCP\INavigationManager {
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear() {
|
||||||
$this->entries = array();
|
$this->entries = array();
|
||||||
|
$this->closureEntries = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,10 +36,13 @@ namespace OCP;
|
||||||
interface INavigationManager {
|
interface INavigationManager {
|
||||||
/**
|
/**
|
||||||
* Creates a new navigation entry
|
* 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
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add(array $entry);
|
public function add($entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current navigation entry of the currently running app
|
* Sets the current navigation entry of the currently running app
|
||||||
|
|
Loading…
Reference in New Issue