Skip to content

Commit

Permalink
Make resolver and loader internal and final
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 17, 2024
1 parent 769e159 commit 32e3639
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class CategorySelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
use Sulu\Bundle\CategoryBundle\Category\CategoryManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class CategoryResourceLoader implements ResourceLoaderInterface
{
public const RESOURCE_LOADER_KEY = 'category';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class AccountSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ResolvableResource;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class ContactAccountSelectionPropertyResolver implements PropertyResolverInterface
{
public const PREFIX_CONTACT = 'c';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class ContactSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class SingleAccountSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class SingleContactSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
use Sulu\Bundle\ContactBundle\Entity\AccountInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class AccountResourceLoader implements ResourceLoaderInterface
{
public const RESOURCE_LOADER_KEY = 'account';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class ContactResourceLoader implements ResourceLoaderInterface
{
public const RESOURCE_LOADER_KEY = 'contact';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;
use Sulu\Bundle\MediaBundle\Infrastructure\Sulu\Content\ResourceLoader\MediaResourceLoader;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class MediaSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface;
use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class MediaResourceLoader implements ResourceLoaderInterface
{
public const RESOURCE_LOADER_KEY = 'media';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\TagBundle\Infrastructure\Content\PropertyResolver;

use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView;
use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface;
use Sulu\Bundle\TagBundle\Infrastructure\Content\ResourceLoader\TagResourceLoader;

/**
* @internal if you need to override this service, create a new service with based on ResourceLoaderInterface instead of extending this class
*
* @final
*/
class TagSelectionPropertyResolver implements PropertyResolverInterface
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
{
if (!\is_array($data)
|| 0 === \count($data)
|| !\array_is_list($data)
) {
return ContentView::create([], ['ids' => []]);
}

/** @var string $resourceLoaderKey */
$resourceLoaderKey = $params['resourceLoader'] ?? TagResourceLoader::getKey();

return ContentView::createResolvables(
$data,
$resourceLoaderKey,
['ids' => $data],
);
}

public static function getType(): string
{
return 'tag_selection';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\TagBundle\Infrastructure\Content\ResourceLoader;

use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface;
use Sulu\Bundle\TagBundle\Tag\TagRepositoryInterface;

/**
* @final
*/
class TagResourceLoader implements ResourceLoaderInterface
{
public const RESOURCE_LOADER_KEY = 'tag';

public function __construct(
private TagRepositoryInterface $tagRepository
) {
}

public function load(array $ids, ?string $locale, array $params = []): array
{
$result = $this->tagRepository->findBy(['id' => $ids]);

$mappedResult = [];
foreach ($result as $tag) {
$mappedResult[$tag->getId()] = $tag->getName();
}

return $mappedResult;
}

public static function getKey(): string
{
return self::RESOURCE_LOADER_KEY;
}
}

0 comments on commit 32e3639

Please sign in to comment.