Created
July 1, 2016 15:22
-
-
Save weaverryan/57eeb71161d2835268aea938146918d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeAutowiredService | |
{ | |
use UrlGeneratorTrait; | |
public function doSomething() | |
{ | |
$url = $this->generateUrl('homepage'); | |
// ... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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