Skip to content

Commit fcce494

Browse files
authored
Add models contracts (#94)
Add all public non-internal static functions to contracts. Add test to ensure this.
1 parent ede649e commit fcce494

File tree

166 files changed

+4487
-1088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+4487
-1088
lines changed

src/Contract/Lib/CacheResolverContract.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public function save(
5353
DateInterval|int|null $lifetime = null,
5454
int $priority = 0,
5555
bool $force = false
56-
): void {
57-
Cache::save($data, $key, $tags, $lifetime, $priority, $force);
56+
): bool {
57+
return Cache::save($data, $key, $tags, $lifetime, $priority, $force);
5858
}
5959

6060
public function isEnabled(): bool
@@ -67,9 +67,9 @@ public function enable(): void
6767
Cache::enable();
6868
}
6969

70-
public function clearTags(array $tag = []): bool
70+
public function clearTags(array $tags = []): bool
7171
{
72-
return Cache::clearTags($tag);
72+
return Cache::clearTags($tags);
7373
}
7474

7575
public function addClearTagOnShutdown(string $tag): void
@@ -97,9 +97,9 @@ public function removeIgnoredTagOnClear(string $tag): void
9797
Cache::removeIgnoredTagOnClear($tag);
9898
}
9999

100-
public function setForceImmediateWrite(bool $force): void
100+
public function setForceImmediateWrite(bool $forceImmediateWrite): void
101101
{
102-
Cache::setForceImmediateWrite($force);
102+
Cache::setForceImmediateWrite($forceImmediateWrite);
103103
}
104104

105105
public function getForceImmediateWrite(): bool

src/Contract/Lib/CacheResolverContractInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public function save(
3737
DateInterval|int|null $lifetime = null,
3838
int $priority = 0,
3939
bool $force = false
40-
): void;
40+
): bool;
4141

4242
public function isEnabled(): bool;
4343

4444
public function enable(): void;
4545

46-
public function clearTags(array $tag = []): bool;
46+
public function clearTags(array $tags = []): bool;
4747

4848
public function addClearTagOnShutdown(string $tag): void;
4949

@@ -55,7 +55,7 @@ public function addIgnoredTagOnClear(string $tag): void;
5555

5656
public function removeIgnoredTagOnClear(string $tag): void;
5757

58-
public function setForceImmediateWrite(bool $force): void;
58+
public function setForceImmediateWrite(bool $forceImmediateWrite): void;
5959

6060
public function getForceImmediateWrite(): bool;
6161
}

src/Contract/Lib/PimcoreResolverContract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function inDebugMode(): bool
4040
return Pimcore::inDebugMode();
4141
}
4242

43-
public function collectGarbage(): void
43+
public function collectGarbage(array $keepItems = []): void
4444
{
45-
Pimcore::collectGarbage();
45+
Pimcore::collectGarbage($keepItems);
4646
}
4747

4848
public function deleteTemporaryFiles(): void

src/Contract/Lib/ToolResolverContract.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getDefaultLanguage(): ?string
5050
return Tool::getDefaultLanguage();
5151
}
5252

53-
public function isValidLanguage(string $language): bool
53+
public function isValidLanguage(?string $language): bool
5454
{
5555
return Tool::isValidLanguage($language);
5656
}
@@ -65,24 +65,24 @@ public function getSupportedJSLocales(): array
6565
return Tool::getSupportedJSLocales();
6666
}
6767

68-
public function isFrontend(): bool
68+
public function isFrontend(?Request $request = null): bool
6969
{
70-
return Tool::isFrontend();
70+
return Tool::isFrontend($request);
7171
}
7272

73-
public function isFrontendRequestByAdmin(): bool
73+
public function isFrontendRequestByAdmin(?Request $request = null): bool
7474
{
75-
return Tool::isFrontendRequestByAdmin();
75+
return Tool::isFrontendRequestByAdmin($request);
7676
}
7777

7878
public function isElementRequestByAdmin(Request $request, ElementInterface $element): bool
7979
{
8080
return Tool::isElementRequestByAdmin($request, $element);
8181
}
8282

83-
public function getHostUrl(): string
83+
public function getHostUrl(?string $useProtocol = null, ?Request $request = null): string
8484
{
85-
return Tool::getHostUrl();
85+
return Tool::getHostUrl($useProtocol, $request);
8686
}
8787

8888
public function getHttpData(

src/Contract/Lib/ToolResolverContractInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public function getValidLanguages(): array;
3737

3838
public function getDefaultLanguage(): ?string;
3939

40-
public function isValidLanguage(string $language): bool;
40+
public function isValidLanguage(?string $language): bool;
4141

4242
public function getRequiredLanguages(): array;
4343

4444
public function getSupportedJSLocales(): array;
4545

46-
public function isFrontend(): bool;
46+
public function isFrontend(?Request $request = null): bool;
4747

48-
public function isFrontendRequestByAdmin(): bool;
48+
public function isFrontendRequestByAdmin(?Request $request = null): bool;
4949

5050
public function isElementRequestByAdmin(Request $request, ElementInterface $element): bool;
5151

52-
public function getHostUrl(): string;
52+
public function getHostUrl(?string $useProtocol = null, ?Request $request = null): string;
5353

5454
public function getHttpData(string $url, array $paramsGet = [], array $paramsPost = [], array $options = []
5555
): false|string;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\Contract\Models\Asset;
18+
19+
use Exception;
20+
use Pimcore\Model\Asset;
21+
use Pimcore\Model\Asset\Listing;
22+
23+
class AssetResolverContract implements AssetResolverContractInterface
24+
{
25+
/**
26+
* @throws Exception
27+
*/
28+
public function getList(array $config = []): Listing
29+
{
30+
return Asset::getList($config);
31+
}
32+
33+
public function getByPath(string $path, array $params = []): ?Asset
34+
{
35+
return Asset::getByPath($path, $params);
36+
}
37+
38+
public function getTypes(): array
39+
{
40+
return Asset::getTypes();
41+
}
42+
43+
public function create(int $parentId, array $data = [], bool $save = true): Asset
44+
{
45+
return Asset::create($parentId, $data, $save);
46+
}
47+
48+
public function getById(int|string $id, array $params = []): ?Asset
49+
{
50+
return Asset::getById($id, $params);
51+
}
52+
53+
public function locateDaoClass(string $modelClass): ?string
54+
{
55+
return Asset::locateDaoClass($modelClass);
56+
}
57+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\Contract\Models\Asset;
18+
19+
use Exception;
20+
use Pimcore\Model\Asset;
21+
use Pimcore\Model\Asset\Listing;
22+
23+
interface AssetResolverContractInterface
24+
{
25+
/**
26+
* @throws Exception
27+
*/
28+
public function getList(array $config = []): Listing;
29+
30+
public function getByPath(string $path, array $params = []): ?Asset;
31+
32+
public function getTypes(): array;
33+
34+
public function create(int $parentId, array $data = [], bool $save = true): Asset;
35+
36+
public function getById(int|string $id, array $params = []): ?Asset;
37+
38+
public function locateDaoClass(string $modelClass): ?string;
39+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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\Contract\Models\Asset;
18+
19+
use Exception;
20+
use League\Flysystem\FilesystemException;
21+
use Pimcore\Model\Asset;
22+
use Pimcore\Model\Asset\Image\ThumbnailInterface;
23+
use Pimcore\Model\Asset\Service;
24+
use Pimcore\Model\DataObject;
25+
use Pimcore\Model\DataObject\AbstractObject;
26+
use Pimcore\Model\Document;
27+
use Pimcore\Model\Element\ElementInterface;
28+
use Symfony\Component\HttpFoundation\StreamedResponse;
29+
30+
class AssetServiceResolverContract implements AssetServiceResolverContractInterface
31+
{
32+
public function pathExists(string $path, ?string $type = null): bool
33+
{
34+
return Service::pathExists($path, $type);
35+
}
36+
37+
/**
38+
* @throws Exception
39+
*/
40+
public function createFolderByPath(
41+
string $path,
42+
array $options = []
43+
): Asset\Folder|DataObject\Folder|Document\Folder|null {
44+
return Service::createFolderByPath($path, $options);
45+
}
46+
47+
/**
48+
* @throws Exception
49+
*/
50+
public function getUniqueKey(ElementInterface $element, int $nr = 0): string
51+
{
52+
return Service::getUniqueKey($element, $nr);
53+
}
54+
55+
/**
56+
* @throws Exception
57+
*/
58+
public function getImageThumbnailByArrayConfig(
59+
array $config
60+
): null|ThumbnailInterface|Asset\Video\ImageThumbnailInterface|Asset\Document\ImageThumbnailInterface|array {
61+
return Service::getImageThumbnailByArrayConfig($config);
62+
}
63+
64+
/**
65+
* @throws FilesystemException
66+
*/
67+
public function getStreamedResponseFromImageThumbnail(
68+
ThumbnailInterface|Asset\Video\ImageThumbnailInterface|Asset\Document\ImageThumbnailInterface|array $thumbnail,
69+
array $config
70+
): ?StreamedResponse {
71+
return Service::getStreamedResponseFromImageThumbnail($thumbnail, $config);
72+
}
73+
74+
/**
75+
* @throws Exception
76+
*/
77+
public function getStreamedResponseByUri(string $uri): ?StreamedResponse
78+
{
79+
return Service::getStreamedResponseByUri($uri);
80+
}
81+
82+
/**
83+
* @throws Exception
84+
*/
85+
public function extractThumbnailInfoFromUri(string $uri): array
86+
{
87+
return Service::extractThumbnailInfoFromUri($uri);
88+
}
89+
90+
public function doHideUnpublished(?ElementInterface $element): bool
91+
{
92+
return Service::doHideUnpublished($element);
93+
}
94+
95+
public function getElementByPath(string $type, string $path): ?ElementInterface
96+
{
97+
return Service::getElementByPath($type, $path);
98+
}
99+
100+
public function getSafeCopyName(string $sourceKey, ElementInterface $target): string
101+
{
102+
return Service::getSafeCopyName($sourceKey, $target);
103+
}
104+
105+
public function getElementById(string $type, int|string $id, array $params = []): Asset|Document|AbstractObject|null
106+
{
107+
return Service::getElementById($type, $id, $params);
108+
}
109+
110+
public function getElementType(ElementInterface $element): ?string
111+
{
112+
return Service::getElementType($element);
113+
}
114+
115+
public function getValidKey(string $key, string $type): string
116+
{
117+
return Service::getValidKey($key, $type);
118+
}
119+
120+
public function isValidKey(string $key, string $type): bool
121+
{
122+
return Service::isValidKey($key, $type);
123+
}
124+
125+
public function isValidPath(string $path, string $type): bool
126+
{
127+
return Service::isValidPath($path, $type);
128+
}
129+
130+
public function cloneMe(ElementInterface $element): ElementInterface
131+
{
132+
return Service::cloneMe($element);
133+
}
134+
135+
public function cloneProperties(mixed $properties): mixed
136+
{
137+
return Service::cloneProperties($properties);
138+
}
139+
140+
public function getElementFromSession(
141+
string $type,
142+
int $elementId,
143+
string $sessionId,
144+
?string $postfix = ''
145+
): Asset|Document|AbstractObject|null {
146+
return Service::getElementFromSession($type, $elementId, $sessionId, $postfix);
147+
}
148+
149+
public function locateDaoClass(string $modelClass): ?string
150+
{
151+
return Service::locateDaoClass($modelClass);
152+
}
153+
}

0 commit comments

Comments
 (0)