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

Commit

Permalink
Merge pull request #63 from garak/inject-router
Browse files Browse the repository at this point in the history
inject router instead of whole container
  • Loading branch information
henrikbjorn committed Feb 1, 2018
2 parents 34d3302 + d3691f2 commit 5a4e361
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 @@ -108,10 +109,10 @@ protected function isSecure($preset = true)
return (bool) $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());
}
}

0 comments on commit 5a4e361

Please sign in to comment.