• 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

86.36
/Content/Application/ResourceLoader/Loader/LinkResourceLoader.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\ResourceLoader\Loader;
15

16
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkItem;
17
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkProviderPoolInterface;
18

19
class LinkResourceLoader implements ResourceLoaderInterface
20
{
21
    public const LINK_TYPE_EXTERNAL = 'external';
22
    public const RESOURCE_LOADER_KEY = 'link';
23

24
    public function __construct(
25
        private LinkProviderPoolInterface $linkProviderPool
26
    ) {
27
    }
4✔
28

29
    /**
30
     * @param string[] $ids
31
     * @param mixed[] $params
32
     *
33
     * @return array<string, mixed>
34
     */
35
    public function load(array $ids, ?string $locale, array $params = []): array
36
    {
37
        if ([] === $ids) {
1✔
NEW
38
            return [];
×
39
        }
40

41
        $links = [];
1✔
42
        foreach ($this->getIdsByProvider($ids) as $provider => $ids) {
1✔
43
            $links = \array_merge($links, $this->loadLinks($provider, $ids, $locale));
1✔
44
        }
45

46
        return $links;
1✔
47
    }
48

49
    /**
50
     * @param string[] $ids
51
     *
52
     * @return array<string, string|LinkItem>
53
     */
54
    private function loadLinks(string $provider, array $ids, ?string $locale): array
55
    {
56
        if (self::LINK_TYPE_EXTERNAL === $provider) {
1✔
NEW
57
            return \array_combine($ids, $ids);
×
58
        }
59

60
        if (null === $locale) {
1✔
NEW
61
            throw new \RuntimeException('Locale is required to resolve non external Links');
×
62
        }
63

64
        $linkProvider = $this->linkProviderPool->getProvider($provider);
1✔
65

66
        $links = [];
1✔
67
        foreach ($linkProvider->preload($ids, $locale) as $link) {
1✔
68
            $links[$provider . '::' . $link->getId()] = $link;
1✔
69
        }
70

71
        return $links;
1✔
72
    }
73

74
    /**
75
     * @param string[] $ids
76
     *
77
     * @return array<string, string[]>
78
     */
79
    private function getIdsByProvider(array $ids): array
80
    {
81
        $idsByProvider = [];
1✔
82
        foreach ($ids as $id) {
1✔
83
            [$provider, $id] = \explode('::', $id, 2);
1✔
84
            $idsByProvider[$provider][] = $id;
1✔
85
        }
86

87
        return $idsByProvider;
1✔
88
    }
89

90
    public static function getKey(): string
91
    {
92
        return self::RESOURCE_LOADER_KEY;
4✔
93
    }
94
}
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