Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
inject router instead of whole container
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Jan 27, 2018
1 parent 4b9fb81 commit d3691f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<service id="templating.helper.gravatar" class="%templating.helper.gravatar.class%">
<tag name="templating.helper" alias="gravatar" />
<argument type="service" id="gravatar.api" />
<argument type="service" id="service_container" />
<argument type="service" id="router" />
</service>

<service id="twig.extension.gravatar" class="%twig.extension.gravatar.class%">
Expand Down
17 changes: 9 additions & 8 deletions Templating/Helper/GravatarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ornicar\GravatarBundle\Templating\Helper;

use Ornicar\GravatarBundle\GravatarApi;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Templating\Helper\Helper;

/**
Expand All @@ -20,19 +20,20 @@ class GravatarHelper extends Helper implements GravatarHelperInterface
protected $api;

/**
* @var ContainerInterface
* @var RouterInterface
*/
protected $container;
protected $router;

/**
* Constructor.
*
* @param Ornicar\GravatarBundle\GravatarApi $api
* @param GravatarApi $api
* @param RouterInterface|null $router
*/
public function __construct(GravatarApi $api, ContainerInterface $container = null)
public function __construct(GravatarApi $api, RouterInterface $router = null)
{
$this->api = $api;
$this->container = $container;
$this->router = $router;
}

/**
Expand Down Expand Up @@ -98,11 +99,11 @@ protected function isSecure($preset = true)
return !!$preset;
}

if (!$this->container || !$this->container->has('router')) {
if (null === $this->router) {
return false;
}

return 'https' == strtolower($this->container->get('router')->getContext()->getScheme());
return 'https' == strtolower($this->router->getContext()->getScheme());
}

/**
Expand Down

0 comments on commit d3691f2

Please sign in to comment.