-
Notifications
You must be signed in to change notification settings - Fork 2
/
UrlGenerator.php
35 lines (29 loc) · 1.14 KB
/
UrlGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace FOQ\AlbumBundle;
use Symfony\Component\Routing\Router;
use FOQ\AlbumBundle\Model\AlbumInterface;
use FOQ\AlbumBundle\Model\PhotoInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class UrlGenerator
{
protected $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->urlGenerator = $urlGenerator;
}
public function getAlbumUrl($route, AlbumInterface $album, array $parameters = array(), $absolute = false)
{
return $this->urlGenerator->generate($route, array_merge($parameters, array(
'username' => $album->getUser()->getUsernameCanonical(),
'slug' => $album->getSlug()
)), $absolute);
}
public function getPhotoUrl($route, PhotoInterface $photo, array $parameters = array(), $absolute = false)
{
return $this->urlGenerator->generate($route, array_merge($parameters, array(
'username' => $photo->getAlbum()->getUser()->getUsernameCanonical(),
'slug' => $photo->getAlbum()->getSlug(),
'number' => $photo->getNumber()
)), $absolute);
}
}