• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sulu / SuluContentBundle / 11978668947

22 Nov 2024 07:11PM UTC coverage: 97.052% (-2.9%) from 100.0%
11978668947

Pull #271

github

web-flow
Merge 85d51e611 into a23a5b050
Pull Request #271: Draft: Base implementation of website content resolving

268 of 353 new or added lines in 17 files covered. (75.92%)

2798 of 2883 relevant lines covered (97.05%)

10.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/Content/Application/PropertyResolver/Resolver/LinkPropertyResolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Sulu.
7
 *
8
 * (c) Sulu GmbH
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\Resolver;
15

16
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
17
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\Loader\LinkResourceLoader;
18
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkItem;
19

20
class LinkPropertyResolver implements PropertyResolverInterface
21
{
22
    /**
23
     * @param array{
24
     *    rel?: string,
25
     *    href: string,
26
     *    query?: string,
27
     *    title?: string,
28
     *    anchor?: string,
29
     *    target?: string,
30
     *    provider?: string
31
     * }|mixed $data
32
     * @param mixed[] $params
33
     */
34
    public function resolve(mixed $data, string $locale, array $params = []): ContentView
35
    {
36
        if (
37
            !\is_array($data)
11✔
38
            || !\array_key_exists('href', $data)
11✔
39
            || !\array_key_exists('provider', $data)
11✔
40
        ) {
41
            return ContentView::create($data, [...$params]);
8✔
42
        }
43

44
        /** @var string $resourceLoaderKey */
45
        $resourceLoaderKey = $params['resourceLoader'] ?? LinkResourceLoader::getKey();
3✔
46

47
        return ContentView::createResolvable(
3✔
48
            $data['provider'] . '::' . $data['href'],
3✔
49
            $resourceLoaderKey,
3✔
50
            [
3✔
51
                ...$data,
3✔
52
                ...$params,
3✔
53
            ],
3✔
54
            // external links are not passed as a LinkItem
55
            static function(string|LinkItem $linkItem) use ($data) {
3✔
56
                if (\is_string($linkItem)) {
1✔
NEW
57
                    return $linkItem;
×
58
                }
59

60
                $url = $linkItem->getUrl();
1✔
61
                if (isset($data['query'])) {
1✔
62
                    $url = \sprintf('%s?%s', $url, \ltrim($data['query'], '?'));
1✔
63
                }
64
                if (isset($data['anchor'])) {
1✔
65
                    $url = \sprintf('%s#%s', $url, \ltrim($data['anchor'], '#'));
1✔
66
                }
67

68
                return $url;
1✔
69
            }
3✔
70
        );
3✔
71
    }
72

73
    public static function getType(): string
74
    {
75
        return 'link';
1✔
76
    }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc