Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created July 1, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/57eeb71161d2835268aea938146918d1 to your computer and use it in GitHub Desktop.
Save weaverryan/57eeb71161d2835268aea938146918d1 to your computer and use it in GitHub Desktop.
<?php
class SomeAutowiredService
{
use UrlGeneratorTrait;
public function doSomething()
{
$url = $this->generateUrl('homepage');
// ...
}
}
<?php
trait UrlGeneratorTrait
{
private $router;
public function setRouter(RouterInterface $router)
{
$this->router = $router;
}
private function generateUrl($name, array $params = array())
{
return $this->router->generate($name, $params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment