CMenuBuilder
in package
Class CMenuBuilder
A service dedicated to building and preparing navigation menus. It encapsulates all database interactions and business logic related to menus.
Table of Contents
Properties
- $logger : ILogger|null
- $menu : array<string|int, mixed>
- $cache : ICache|null
- $dbms_type : string
- $request : CRequest
- $user : CUser
Methods
- __construct() : mixed
- CMenuBuilder constructor.
- GetAvailableModules() : array<string|int, mixed>
- Returns a list of all modules, using cache.
- GetMenu() : array<string|int, mixed>
- Gets the fully prepared menu structure for the current user against a specific URL.
- BuildMenuTree() : bool
- Creates the navigation menu tree recursively by querying the database.
- PostProcessMenu() : void
- Recursively traverses a menu array to add state flags (is_active, is_external).
Properties
$logger
protected
ILogger|null
$logger
= null
The logger instance
$menu
protected
array<string|int, mixed>
$menu
= []
The built menu structure
$cache
private
ICache|null
$cache
The cache handler instance
$dbms_type
private
string
$dbms_type
The database management system type
$request
private
CRequest
$request
The current request object
$user
private
CUser
$user
The current user object
Methods
__construct()
CMenuBuilder constructor.
public
__construct(CUser $user, CRequest $request[, ICache|null $cache = null ][, ILogger|null $logger = null ]) : mixed
Parameters
GetAvailableModules()
Returns a list of all modules, using cache.
public
GetAvailableModules() : array<string|int, mixed>
Return values
array<string|int, mixed> —The array of module data
GetMenu()
Gets the fully prepared menu structure for the current user against a specific URL.
public
GetMenu([string $current_url = '/' ]) : array<string|int, mixed>
Parameters
- $current_url : string = '/'
-
The URL of the current page to determine active states.
Return values
array<string|int, mixed> —The complete menu array, with state flags (is_active, is_external) already set.
BuildMenuTree()
Creates the navigation menu tree recursively by querying the database.
private
BuildMenuTree(array<string|int, mixed> &$menu[, CSqlComposer|null $sql = null ][, int $level = 1 ]) : bool
Parameters
- $menu : array<string|int, mixed>
-
The result menu array.
- $sql : CSqlComposer|null = null
-
The SQL Composer object for sub-menus.
- $level : int = 1
-
The current recursion level.
Return values
bool —True on success.
PostProcessMenu()
Recursively traverses a menu array to add state flags (is_active, is_external).
private
PostProcessMenu(array<string|int, mixed> &$menu_level, string $current_url) : void
Parameters
- $menu_level : array<string|int, mixed>
-
The current level of the menu to process.
- $current_url : string
-
The current page URL to check against.