public function __construct($owner, &$item, $user = null, $parent = null, $depth = 0) { $this->item = $item; $this->user = $user; $this->parent = $parent; $this->owner = $owner; $uri_to_match = Request::getUri(); if ($this->owner->ignorePrefix()) { $uri_to_match = @preg_replace('#^' . $owner->ignorePrefix() . '#', '', $uri_to_match); if ($uri_to_match === null) { throw new BakedCarrotException('Invalid parameter: "ignore_prefix"'); } } if ($uri_to_match == '/') { $this->item['active'] = isset($this->item['uri']) && $this->item['uri'] == $uri_to_match; $this->item['selected'] = $this->item['active']; } else { $request_uri_parts = $this->splitUri($uri_to_match); $uri_parts = array(); if (isset($this->item['uri']) && strlen($this->item['uri']) > 0) { $uri_parts = $this->splitUri($this->item['uri']); } $matched = false; foreach ($uri_parts as $num => $uri_part) { $matched = isset($request_uri_parts[$num]) && $request_uri_parts[$num] == $uri_part; if (!$matched) { break; } } $this->item['active'] = $matched; $this->item['selected'] = $matched && count($uri_parts) == count($request_uri_parts); } $this->item['depth'] = $depth; $this->item['access'] = true; if (is_object($this->user) && isset($this->item['uri'])) { if (!method_exists($this->user, 'hasRole')) { throw new BakedCarrotException(get_class($this->user) . '::hasRole() is not defined'); } if (($menu_item_route = Router::getRouteByUri($this->item['uri'])) && $menu_item_route->acl) { $this->item['access'] = $this->user->hasRole($menu_item_route->acl); } } $this->getChildren(); }