1: <?php
2:
3: namespace PHPixie\Framework\Extensions\Template\Extension;
4:
5: /**
6: * Template extension that allows route generation
7: */
8: class RouteTranslator implements \PHPixie\Template\Extensions\Extension
9: {
10: /**
11: * @var string
12: */
13: protected $name;
14:
15: /**
16: * @type \PHPixie\Route\Translator
17: */
18: protected $routeTranslator;
19:
20: /**
21: * Constructor
22: * @param string $name Extension name to use
23: * @param \PHPixie\Route\Translator $routeTranslator
24: */
25: public function __construct($name, $routeTranslator)
26: {
27: $this->name = $name;
28: $this->routeTranslator = $routeTranslator;
29: }
30:
31: /**
32: * @inheritdoc
33: */
34: public function name()
35: {
36: return $this->name;
37: }
38:
39: /**
40: * @inheritdoc
41: */
42: public function methods()
43: {
44: return array(
45: $this->name.'Path' => 'path',
46: $this->name.'Uri' => 'uri'
47: );
48: }
49:
50: /**
51: * @inheritdoc
52: */
53: public function aliases()
54: {
55: return array();
56: }
57:
58: /**
59: * Generate path
60: * @param string $resolverPath
61: * @param array $attributes
62: * @return string
63: */
64: public function path($resolverPath, $attributes = array())
65: {
66: return $this->routeTranslator->generatePath(
67: $resolverPath,
68: $attributes
69: );
70: }
71:
72: /**
73: * Generate URI
74: * @param string $resolverPath
75: * @param array $attributes
76: * @param bool $withHost Whether to include host in the URI
77: * @return string
78: */
79: public function uri(
80: $resolverPath,
81: $attributes = array(),
82: $withHost = true
83: )
84: {
85: return $this->routeTranslator->generateUri(
86: $resolverPath,
87: $attributes,
88: $withHost
89: );
90: }
91: }