-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co> Co-authored-by: Łukasz Ostafin <ostafin.lucas@gmail.com> Co-authored-by: Maciej Kobus <maciej.kobus@ez.no>
- Loading branch information
1 parent
50ccad7
commit c0fd4c8
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\UI\Config\Provider; | ||
|
||
use Ibexa\Contracts\AdminUi\UI\Config\ProviderInterface; | ||
use Ibexa\Contracts\Core\Repository\Repository; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
final class CurrentBackOfficePath implements ProviderInterface | ||
{ | ||
private RouterInterface $router; | ||
|
||
private Repository $repository; | ||
|
||
public function __construct( | ||
RouterInterface $router, | ||
Repository $repository | ||
) { | ||
$this->router = $router; | ||
$this->repository = $repository; | ||
} | ||
|
||
public function getConfig(): string | ||
{ | ||
/* | ||
* We need base path here, to properly set backoffice cookies only, | ||
* so they do not interfere with front end SiteAccesses. | ||
* Generating route for `/` allows us to make sure that we do not have any additional parameters | ||
* and we get raw path to back office. | ||
* We are not using reverse matchers here as they work in context of current request. | ||
* | ||
* Sudo is used to avoid insufficient permissions on reading root Location. | ||
*/ | ||
return $this->repository->sudo( | ||
function (Repository $repository): string { | ||
$routeInfo = $this->router->match('/'); | ||
$path = $this->router->generate($routeInfo['_route'], $routeInfo); | ||
$pathInfo = pathinfo($path); | ||
|
||
return $pathInfo['dirname']; | ||
} | ||
); | ||
} | ||
} |