| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 require_once (AK_LIB_DIR . DS . 'AkDispatcher.php'); 3 require_once (AK_LIB_DIR . DS .'AkUnitTest'. DS . 'AkTestRequest.php'); 4 require_once (AK_LIB_DIR . DS .'AkUnitTest'. DS . 'AkTestResponse.php'); 5 class AkTestDispatcher extends AkDispatcher 6 { 7 var $_controllerVars; 8 9 function AkTestDispatcher($controllerVars = array()) 10 { 11 $this->_controllerVars = $controllerVars; 12 13 } 14 15 function __construct($controllerVars = array()) 16 { 17 $this->_controllerVars = $controllerVars; 18 } 19 function get($url) 20 { 21 $_SERVER['REQUEST_METHOD'] = 'GET'; 22 return $this->process($url); 23 } 24 25 function post($url, $postParams) 26 { 27 $_SERVER['REQUEST_METHOD'] = 'POST'; 28 if (is_array($postParams)) { 29 $_POST = $postParams; 30 } else { 31 $_ENV['RAW_POST_DATA'] = $postParams; 32 } 33 return $this->process($url); 34 } 35 36 function put($url, $data) 37 { 38 $_SERVER['REQUEST_METHOD'] = 'PUT'; 39 $_SERVER['CONTENT_LENGTH'] = strlen($data); 40 $fh = fopen('php://input', 'w'); 41 if ($fh) { 42 fputs($fh, $data); 43 fclose($fh); 44 return $this->process($url); 45 } else { 46 return false; 47 } 48 } 49 50 function delete($url) 51 { 52 $_SERVER['REQUEST_METHOD'] = 'DELETE'; 53 return $this->process($url); 54 } 55 function process($url) 56 { 57 $_SERVER['PHP_SELF'] = '/index.php'; 58 $parts = parse_url($url); 59 if (isset($parts['scheme'])) { 60 $_SERVER['HTTPS']=$parts['scheme']=='https'; 61 62 } 63 if (isset($parts['query'])) { 64 $parts = preg_split('&', $parts['query']); 65 foreach ($parts as $p) { 66 $gets = split('=',$p); 67 $_GET[$gets[0]]=isset($gets[1])?$gets[1]:null; 68 } 69 } 70 $_REQUEST['ak'] = isset($parts['path'])?$parts['path']:'/'; 71 $_SERVER['REQUEST_URI'] = isset($parts['path'])?$parts['path']:'/'; 72 $_SERVER['SERVER_NAME'] = isset($parts['host'])?$parts['host']:null; 73 74 75 return $this->dispatch(); 76 } 77 78 function dispatch() 79 { 80 $this->Request = &new AkTestRequest(); 81 $this->Response = &new AkTestResponse(); 82 $controller = & $this->Request->recognize(); 83 if ($controller === false) { 84 return false; 85 } else { 86 $this->Controller = &$controller; 87 if (is_array($this->_controllerVars)) { 88 foreach ($this->_controllerVars as $key=>$value) { 89 $this->Controller->$key = $value; 90 } 91 } 92 $this->Controller->process(&$this->Request, &$this->Response); 93 94 } 95 return true; 96 } 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |