[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontURIMapper { 4 5 private $map; 6 7 final public function __construct(array $map) { 8 $this->map = $map; 9 } 10 11 final public function mapPath($path) { 12 $map = $this->map; 13 foreach ($map as $rule => $value) { 14 list($controller, $data) = $this->tryRule($rule, $value, $path); 15 if ($controller) { 16 foreach ($data as $k => $v) { 17 if (is_numeric($k)) { 18 unset($data[$k]); 19 } 20 } 21 return array($controller, $data); 22 } 23 } 24 25 return array(null, null); 26 } 27 28 final private function tryRule($rule, $value, $path) { 29 $match = null; 30 $pattern = '#^'.$rule.(is_array($value) ? '' : '$').'#'; 31 if (!preg_match($pattern, $path, $match)) { 32 return array(null, null); 33 } 34 35 if (!is_array($value)) { 36 return array($value, $match); 37 } 38 39 $path = substr($path, strlen($match[0])); 40 foreach ($value as $srule => $sval) { 41 list($controller, $data) = $this->tryRule($srule, $sval, $path); 42 if ($controller) { 43 return array($controller, $data + $match); 44 } 45 } 46 47 return array(null, null); 48 } 49 50 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |