• 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

9.52
/Content/Application/ResourceLoader/Loader/TeaserResourceLoader.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\PageBundle\Teaser\TeaserManagerInterface;
17

18
class TeaserResourceLoader implements ResourceLoaderInterface
19
{
20
    public const RESOURCE_LOADER_KEY = 'teaser';
21

22
    public function __construct(
23
        private TeaserManagerInterface $teaserManager
24
    ) {
25
    }
2✔
26

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

NEW
39
        if (null === $locale) {
×
NEW
40
            throw new \RuntimeException('Locale is required to resolve Teasers');
×
41
        }
42

NEW
43
        $items = $this->getItemsByProvider($ids);
×
NEW
44
        $teasers = [];
×
NEW
45
        foreach ($items as $provider => $itemsPerProvider) {
×
NEW
46
            $loadedTeasers = $this->teaserManager->find($itemsPerProvider, $locale);
×
NEW
47
            foreach ($loadedTeasers as $teaser) {
×
NEW
48
                $teasers[$provider . '::' . $teaser->getId()] = $teaser;
×
49
            }
50
        }
51

NEW
52
        return $teasers;
×
53
    }
54

55
    /**
56
     * @param string[] $ids
57
     *
58
     * @return array<string, non-empty-array<int, array{id: string, type: string}>>
59
     */
60
    private function getItemsByProvider(array $ids): array
61
    {
NEW
62
        $idsByProvider = [];
×
NEW
63
        foreach ($ids as $id) {
×
NEW
64
            [$provider, $id] = \explode('::', $id, 2);
×
NEW
65
            $idsByProvider[$provider][] = [
×
NEW
66
                'id' => $id,
×
NEW
67
                'type' => $provider,
×
NEW
68
            ];
×
69
        }
70

NEW
71
        return $idsByProvider;
×
72
    }
73

74
    public static function getKey(): string
75
    {
76
        return self::RESOURCE_LOADER_KEY;
2✔
77
    }
78
}
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