| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTServicesHTTPRequestRouter { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
private $map; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var mixed |
| 22 |
*/ |
| 23 |
private $methodData; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
* @param mixed $defaults |
| 29 |
* @param mixed $method |
| 30 |
* @return CJTServicesRequestRouter |
| 31 |
*/ |
| 32 |
public function __construct($map, $method = 'request') { |
| 33 |
# Initiaize |
| 34 |
$this->map = $map; |
| 35 |
$this->methodData =& $GLOBALS[ '_' . strtoupper( $method ) ]; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* put your comment there... |
| 40 |
* |
| 41 |
* @param mixed $route |
| 42 |
* @return CJTServicesRequestRouter |
| 43 |
*/ |
| 44 |
public function getRoute(& $route) { |
| 45 |
# Initialize |
| 46 |
$newRoute = array(); |
| 47 |
# Overwrite defauls values if submitted |
| 48 |
foreach ( $this->map as $name => $paramName ) { |
| 49 |
$newRoute[ $name ] = isset( $this->methodData[ $paramName ] ) ? |
| 50 |
$this->methodData[ $paramName ] : |
| 51 |
( isset( $route[ $name ] ) ? $route[ $name ] : null ); |
| 52 |
} |
| 53 |
# Set new route |
| 54 |
$route = array_merge( $route, $newRoute ); |
| 55 |
# Chain |
| 56 |
return $this; |
| 57 |
} |
| 58 |
} |
| 59 |
|