1: <?php
2:
3: namespace PHPixie\Route\Resolvers\Resolver\Pattern;
4:
5: class Implementation extends \PHPixie\Route\Resolvers\Resolver\Pattern
6: {
7: public function match($fragment)
8: {
9: if(!$this->isMethodValid($fragment)) {
10: return null;
11: }
12:
13: $hostAttributes = $this->matchPattern(
14: $this->hostPattern(),
15: $fragment->host()
16: );
17:
18: if($hostAttributes === null) {
19: return null;
20: }
21:
22: $pathAttributes = $this->matchPattern(
23: $this->pathPattern(),
24: $fragment->path()
25: );
26:
27: if($pathAttributes === null) {
28: return null;
29: }
30:
31: $attributes = array_merge(
32: $this->defaults(),
33: $hostAttributes,
34: $pathAttributes
35: );
36:
37: return $this->builder->translatorMatch($attributes);
38: }
39:
40: protected function matchPattern($pattern, $string)
41: {
42: if($pattern === null) {
43: return array();
44: }
45: return $this->builder->matcher()->match($pattern, $string);
46: }
47:
48: public function generate($match, $withHost = false)
49: {
50: $attributes = $this->mergeAttributes($match);
51:
52: $path = $this->generatePatternString($this->pathPattern(), $attributes);
53:
54: if($withHost) {
55: $host = $this->generatePatternString($this->hostPattern(), $attributes);
56: }else{
57: $host = null;
58: }
59:
60: return $this->builder->translatorFragment($path, $host);
61: }
62: }