Skip to content

Commit a7e577f

Browse files
authored
[Task] Add site resolver (#87)
* Add site resolver * Apply php-cs-fixer changes * Add min-stability * Make internal * Add exceptions to interface
1 parent aac7822 commit a7e577f

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"Pimcore\\Bundle\\StaticResolverBundle\\Tests\\": "tests"
2121
}
2222
},
23+
"prefer-stable": true,
24+
"minimum-stability": "dev",
2325
"require": {
2426
"php": "~8.3.0 || ~8.4.0",
2527
"pimcore/pimcore": "^12.0",

src/Models/Site/SiteResolver.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StaticResolverBundle\Models\Site;
18+
19+
use Exception;
20+
use Pimcore\Model\Site;
21+
22+
/**
23+
* @internal
24+
*/
25+
final readonly class SiteResolver implements SiteResolverInterface
26+
{
27+
/**
28+
* @throws Exception
29+
*/
30+
public function getById(int $id): ?Site
31+
{
32+
return Site::getById($id);
33+
}
34+
35+
/**
36+
* @throws Exception
37+
*/
38+
public function getCurrentSite(): Site
39+
{
40+
return Site::getCurrentSite();
41+
}
42+
43+
public function getByRootId(int $id): ?Site
44+
{
45+
return Site::getByRootId($id);
46+
}
47+
48+
/**
49+
* @throws Exception
50+
*/
51+
public function getByDomain(string $domain): ?Site
52+
{
53+
return Site::getByDomain($domain);
54+
}
55+
56+
/**
57+
* @throws Exception
58+
*/
59+
public function getBy(mixed $mixed): ?Site
60+
{
61+
return Site::getBy($mixed);
62+
}
63+
64+
public function create(array $data): Site
65+
{
66+
return Site::create($data);
67+
}
68+
69+
public function isSiteRequest(): bool
70+
{
71+
return Site::isSiteRequest();
72+
}
73+
74+
public function setCurrentSite(Site $site): void
75+
{
76+
Site::setCurrentSite($site);
77+
}
78+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StaticResolverBundle\Models\Site;
18+
19+
use Exception;
20+
use Pimcore\Model\Site;
21+
22+
/**
23+
* @internal
24+
*/
25+
interface SiteResolverInterface
26+
{
27+
/**
28+
* @throws Exception
29+
*/
30+
public function getById(int $id): ?Site;
31+
32+
public function getByRootId(int $id): ?Site;
33+
34+
/**
35+
* @throws Exception
36+
*/
37+
public function getByDomain(string $domain): ?Site;
38+
39+
/**
40+
* @throws Exception
41+
*/
42+
public function getBy(mixed $mixed): ?Site;
43+
44+
public function create(array $data): Site;
45+
46+
public function isSiteRequest(): bool;
47+
48+
/**
49+
* @throws Exception
50+
*/
51+
public function getCurrentSite(): Site;
52+
53+
public function setCurrentSite(Site $site): void;
54+
}

0 commit comments

Comments
 (0)