2026-03-18 22:20:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Module\Bookmarks\Providers;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
|
|
|
use MintyPHP\App\Module\Contracts\LayoutContextProvider;
|
2026-03-20 00:22:23 +01:00
|
|
|
use MintyPHP\Http\Request;
|
2026-03-18 22:20:20 +01:00
|
|
|
use MintyPHP\Module\Bookmarks\Support\BookmarkUrlNormalizer;
|
|
|
|
|
|
|
|
|
|
final class BookmarksLayoutProvider implements LayoutContextProvider
|
|
|
|
|
{
|
|
|
|
|
public function provide(array $session, AppContainer $container): array
|
|
|
|
|
{
|
|
|
|
|
$grouped = is_array($session['module.bookmarks.grouped'] ?? null)
|
|
|
|
|
? $session['module.bookmarks.grouped']
|
|
|
|
|
: ['groups' => [], 'ungrouped' => []];
|
|
|
|
|
|
2026-03-20 00:22:23 +01:00
|
|
|
$requestUri = '/' . ltrim(Request::pathWithQuery(), '/');
|
|
|
|
|
$localePath = (string) (parse_url(localeBase(), PHP_URL_PATH) ?? '/');
|
|
|
|
|
$localePath = Request::stripBasePath($localePath);
|
|
|
|
|
$localeBasePath = '/' . trim($localePath, '/');
|
|
|
|
|
if ($localeBasePath !== '/') {
|
|
|
|
|
$localeBasePath .= '/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$currentPath = BookmarkUrlNormalizer::canonicalizeRequestUri($requestUri, $localeBasePath);
|
2026-03-18 22:20:20 +01:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'bookmarks.nav' => [
|
|
|
|
|
'grouped' => $grouped,
|
|
|
|
|
'current_path' => $currentPath,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|