Skip to content

Commit 0b34e5f

Browse files
lukmzigmartineiber
authored andcommitted
[Documents] Add DocType resolver (#108)
* Add doctype resolver * Apply php-cs-fixer changes
1 parent 7b5086b commit 0b34e5f

File tree

8 files changed

+171
-0
lines changed

8 files changed

+171
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document;
15+
16+
use Exception;
17+
use Pimcore\Model\Document\DocType;
18+
19+
class DocTypeResolverContract implements DocTypeResolverContractInterface
20+
{
21+
/**
22+
* @throws Exception
23+
*/
24+
public function getById(string $id): ?DocType
25+
{
26+
return DocType::getById($id);
27+
}
28+
29+
public function create(): DocType
30+
{
31+
return DocType::create();
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document;
15+
16+
use Pimcore\Model\Document\DocType;
17+
18+
interface DocTypeResolverContractInterface
19+
{
20+
public function getById(string $id): ?DocType;
21+
22+
public function create(): DocType;
23+
}

src/Lib/ToolResolver.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,55 @@
1515

1616
use Pimcore\Bundle\StaticResolverBundle\Contract\Lib\ToolResolverContract;
1717
use Pimcore\Tool;
18+
use Symfony\Component\HttpFoundation\Request;
1819

1920
/**
2021
* @internal
2122
*/
2223
final class ToolResolver extends ToolResolverContract implements ToolResolverInterface
2324
{
25+
public function hasCurrentRequest(): bool
26+
{
27+
return Tool::hasCurrentRequest();
28+
}
29+
30+
public function useFrontendOutputFilters(?Request $request = null): bool
31+
{
32+
return Tool::useFrontendOutputFilters($request);
33+
}
34+
2435
public function getHostname(): ?string
2536
{
2637
return Tool::getHostname();
2738
}
39+
40+
public function getRequestScheme(?Request $request = null): string
41+
{
42+
return Tool::getRequestScheme($request);
43+
}
44+
45+
public function getClientIp(?Request $request = null): ?string
46+
{
47+
return Tool::getClientIp($request);
48+
}
49+
50+
public function getAnonymizedClientIp(?Request $request = null): ?string
51+
{
52+
return Tool::getAnonymizedClientIp($request);
53+
}
54+
55+
public function classExists(string $class): bool
56+
{
57+
return Tool::classExists($class);
58+
}
59+
60+
public function interfaceExists(string $class): bool
61+
{
62+
return Tool::interfaceExists($class);
63+
}
64+
65+
public function traitExists(string $class): bool
66+
{
67+
return Tool::traitExists($class);
68+
}
2869
}

src/Lib/ToolResolverInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,28 @@
1414
namespace Pimcore\Bundle\StaticResolverBundle\Lib;
1515

1616
use Pimcore\Bundle\StaticResolverBundle\Contract\Lib\ToolResolverContractInterface;
17+
use Symfony\Component\HttpFoundation\Request;
1718

1819
/**
1920
* @internal
2021
*/
2122
interface ToolResolverInterface extends ToolResolverContractInterface
2223
{
24+
public function hasCurrentRequest(): bool;
25+
26+
public function useFrontendOutputFilters(?Request $request = null): bool;
27+
2328
public function getHostname(): ?string;
29+
30+
public function getRequestScheme(?Request $request = null): string;
31+
32+
public function getClientIp(?Request $request = null): ?string;
33+
34+
public function getAnonymizedClientIp(?Request $request = null): ?string;
35+
36+
public function classExists(string $class): bool;
37+
38+
public function interfaceExists(string $class): bool;
39+
40+
public function traitExists(string $class): bool;
2441
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StaticResolverBundle\Models\Document;
15+
16+
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document\DocTypeResolverContract;
17+
18+
/**
19+
* @internal
20+
*/
21+
final class DocTypeResolver extends DocTypeResolverContract implements DocTypeResolverInterface
22+
{
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StaticResolverBundle\Models\Document;
15+
16+
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document\DocTypeResolverContractInterface;
17+
18+
/**
19+
* @internal
20+
*/
21+
interface DocTypeResolverInterface extends DocTypeResolverContractInterface
22+
{
23+
}

src/Models/Document/DocumentResolver.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414
namespace Pimcore\Bundle\StaticResolverBundle\Models\Document;
1515

1616
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document\DocumentResolverContract;
17+
use Pimcore\Model\Document;
1718

1819
/**
1920
* @internal
2021
*/
2122
final class DocumentResolver extends DocumentResolverContract implements DocumentResolverInterface
2223
{
24+
public function createByClassName(string $className, int $parentId, array $data = [], bool $save = true): Document
25+
{
26+
if (!is_subclass_of($className, Document::class)) {
27+
throw new \InvalidArgumentException("Class $className must extend " . Document::class);
28+
}
29+
30+
return $className::create($parentId, $data, $save);
31+
}
2332
}

src/Models/Document/DocumentResolverInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
namespace Pimcore\Bundle\StaticResolverBundle\Models\Document;
1515

1616
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document\DocumentResolverContractInterface;
17+
use Pimcore\Model\Document;
1718

1819
/**
1920
* @internal
2021
*/
2122
interface DocumentResolverInterface extends DocumentResolverContractInterface
2223
{
24+
public function createByClassName(string $className, int $parentId, array $data = [], bool $save = true): Document;
2325
}

0 commit comments

Comments
 (0)