Skip to content

Commit

Permalink
EZP-32164: Implemented IconPathResolver service
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Nov 17, 2020
1 parent ef92b6c commit 5f1728a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
imports:
- { resource: services/resolver.yaml }
- { resource: services/twig.yaml }

##
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
autoconfigure: true
autowire: true
public: false

Ibexa\Platform\Assets\Resolver\IconPathResolver: ~

Ibexa\Platform\Assets\Resolver\IconPathResolverInterface: '@Ibexa\Platform\Assets\Resolver\IconPathResolver'
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@

namespace Ibexa\Platform\Bundle\Assets\Twig\Extension;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Symfony\Component\Asset\Packages;
use Ibexa\Platform\Assets\Resolver\IconPathResolverInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class IconSetExtension extends AbstractExtension
{
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
private $configResolver;
/** @var \Ibexa\Platform\Assets\Resolver\IconPathResolverInterface */
private $iconPathResolver;

/** @var \Symfony\Component\Asset\Packages */
private $packages;

public function __construct(
ConfigResolverInterface $configResolver,
Packages $packages
) {
$this->configResolver = $configResolver;
$this->packages = $packages;
public function __construct(IconPathResolverInterface $iconPathResolver)
{
$this->iconPathResolver = $iconPathResolver;
}

public function getFunctions(): array
Expand All @@ -44,9 +37,6 @@ public function getFunctions(): array

public function getIconPath(string $icon, string $set = null): string
{
$iconSetName = $set ?? $this->configResolver->getParameter('assets.default_icon_set');
$iconSets = $this->configResolver->getParameter('assets.icon_sets');

return sprintf('%s#%s', $this->packages->getUrl($iconSets[$iconSetName]), $icon);
return $this->iconPathResolver->resolve($icon, $set);
}
}
40 changes: 40 additions & 0 deletions src/IbexaPlatformAssetsBundle/lib/Resolver/IconPathResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Platform\Assets\Resolver;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Symfony\Component\Asset\Packages;

/**
* @internal
*/
final class IconPathResolver implements IconPathResolverInterface
{
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
private $configResolver;

/** @var \Symfony\Component\Asset\Packages */
private $packages;

public function __construct(
ConfigResolverInterface $configResolver,
Packages $packages
) {
$this->configResolver = $configResolver;
$this->packages = $packages;
}

public function resolve(string $icon, string $set = null): string
{
$iconSetName = $set ?? $this->configResolver->getParameter('assets.default_icon_set');
$iconSets = $this->configResolver->getParameter('assets.icon_sets');

return sprintf('%s#%s', $this->packages->getUrl($iconSets[$iconSetName]), $icon);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Platform\Assets\Resolver;

interface IconPathResolverInterface
{
public function resolve(string $icon, string $set = null): string;
}

0 comments on commit 5f1728a

Please sign in to comment.