Changeset 5942
- Timestamp:
- 01/18/12 02:34:26 (4 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
core/functions.core.php (modified) (1 diff)
-
core/router.core.php (modified) (5 diffs)
-
core/targetroute.core.php (modified) (1 diff)
-
tests/runAllTests.php (modified) (1 diff)
-
tests/unittests/core/router.core.php (modified) (1 diff)
-
tests/unittests/core/viewhelper/form/form.core.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/functions.core.php
r5901 r5942 484 484 $index = 0; 485 485 486 # more keys than values, reduce keys array 487 while(count($keyArray) > count($valueArray)) 488 { 489 array_pop($keyArray); 490 } 491 492 # @todo more values than keys ? 493 # add pseudo keys a la "key-0" 494 486 495 foreach($keyArray as $key) 487 496 { 488 if(isset($valueArray[$index]) === true) 489 { 497 if(isset($valueArray[$index])) 498 { 499 # index is used, then incremented for the next turn in foreach (post-increment-operator) 490 500 $returnArray[$key] = $valueArray[$index++]; 491 501 } -
trunk/core/router.core.php
r5937 r5942 224 224 { 225 225 # if urlstring is already a qualified url (http://...) 226 if(false !== strpos($urlstring, WWW_ROOT . 'index.php? mod='))226 if(false !== strpos($urlstring, WWW_ROOT . 'index.php?')) 227 227 { 228 228 # there is no need to rebuild it, just return 229 229 return $urlstring; 230 } 231 elseif(false !== strpos($urlstring, 'index.php?')) 232 { 233 # there is no need to rebuild it, just the http prefix is missing 234 # add that and return 235 return WWW_ROOT . $urlstring; 230 236 } 231 237 # e.g. ROOT/news/admin … … 237 243 else # ROOT/index.php?mod=abc&action=123&etc... 238 244 { 245 # get only the part after "index.php=?" 246 if(false !== strpos($urlstring, 'index.php?')) 247 { 248 $urlstring = strstr($urlstring, 'index.php?'); 249 } 250 239 251 # remove all double slahes 240 252 while (false !== strpos($urlstring, '//')) 241 253 { 242 $url = str_replace('//', '/', $urlstring); 243 } 244 245 # get only the part after "index.php=?" 246 if(false !== strpos($urlstring, 'index.php?')) 247 { 248 $urlstring = strstr($urlstring, 'index.php?'); 249 } 250 251 # and explode the string into an indexed array 252 $urlstring = ltrim($urlstring, '/'); 254 $urlstring = str_replace('//', '/', $urlstring); 255 } 256 257 # remove space and slashes from begin and end of string 258 $urlstring = trim($urlstring, ' /'); 259 260 # so something like "news/show/2" is left 261 # explode the string into an indexed array 253 262 $url_params_idx_array = explode('/', $urlstring); 254 255 var_dump($url_params_idx_array);256 263 257 264 /** … … 259 266 * [0]=> "news" to [mod] => "news" 260 267 * [1]=> "show" to [action] => "show" 268 * [2]=> "2" to [id] => "2" 261 269 * 262 270 * It also a static whitelist for url parameter keys. … … 266 274 * Then a reverse lookup in the routes table. For now this is static. 267 275 */ 268 if( $url_params_idx_array[1] === 'admin')276 if(isset($url_params_idx_array[1]) and $url_params_idx_array[1] === 'admin') 269 277 { 270 278 # module admin whitelist … … 278 286 279 287 $url_data = Clansuite_Functions::array_unequal_combine($url_keys, $url_params_idx_array); 280 $url = '';281 288 282 289 # Defaults to & for internal usage in html documents. 283 # = ROOT/index.php?mod=abc&action=123&etc... 284 if($internal_url === true) 285 { 286 $url = http_build_query($url_data, '', '&'); 287 } 288 # external link / redirect etc. 289 # = ROOT/index.php?mod=abc&action=123&etc... 290 elseif($internal_url === false) 291 { 292 $url = http_build_query($url_data, '', '&'); 293 } 290 $arg_separator = ($internal_url === true) ? '&' : '&'; 291 292 $url = http_build_query($url_data, '', $arg_separator); 294 293 295 294 #Clansuite_Debug::printR(WWW_ROOT . 'index.php?' . $url); -
trunk/core/targetroute.core.php
r5519 r5942 367 367 ); 368 368 369 self::$parameters = array_merge(self::$parameters, $reset_params); 369 #self::$parameters = array_merge(self::$parameters, $reset_params); 370 self::$parameters = $reset_params; 370 371 } 371 372 -
trunk/tests/runAllTests.php
r5864 r5942 38 38 require_once 'simpletest/reporter.php'; 39 39 # hmm, we need to load this, to get rid of the "No runnable test cases in runAlltest" error 40 require_once 'simpletest/autorun.php';40 #require_once 'simpletest/autorun.php'; 41 41 42 42 # setup our testsuite and reporter -
trunk/tests/unittests/core/router.core.php
r5937 r5942 100 100 $this->assertEqual(WWW_ROOT . 'index.php?mod=news&action=show', $url); 101 101 102 $urlstring = '/news/admin/edit/1'; 103 $internal_url = true; 104 $url = $this->router->buildURL($urlstring, $internal_url); 105 $this->assertEqual(WWW_ROOT . 'index.php?mod=news&sub=admin&action=edit&id=1', $url); 106 102 107 /*$urlstring = ''; 103 108 $internal_url = false; -
trunk/tests/unittests/core/viewhelper/form/form.core.php
r5936 r5942 63 63 { 64 64 # set internal url - rebuilds the external url via router 65 $this->form->setAction('/ module/action');66 $this->assertEqual( WWW_ROOT . 'index.php?mod= module&sub=action', $this->form->getAction());65 $this->form->setAction('/news/show'); 66 $this->assertEqual( WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction()); 67 67 68 68 # set external url 69 $this->form->setAction(WWW_ROOT .'index.php?mod=news&action=show'); 70 $this->assertEqual( WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction()); 71 72 # set external url withput www_root (http root) 69 73 $this->form->setAction('index.php?mod=news&action=show'); 70 $this->assertEqual( WWW_ROOT . 'index.php?mod %3Dnews%26action%3Dshow', $this->form->getAction());74 $this->assertEqual( WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction()); 71 75 } 72 76 73 77 public function testGetAction() 74 78 { 75 $this->form->setAction('index.php?mod=news&action=show');76 77 79 # via getter - qualified url 78 $this->assertEqual( WWW_ROOT . 'index.php?mod%3Dnews%26action%3Dshow', $this->form->getAction()); 80 $url = WWW_ROOT . 'index.php?mod=news&action=show'; 81 $this->form->setAction( $url ); 82 $this->assertEqual( $url, $this->form->getAction()); 79 83 } 80 84
Note: See TracChangeset
for help on using the changeset viewer.
