Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Search Repo:
Argument tokenizer
bergie (author)
Tue Jul 08 00:49:37 -0700 2008
commit  870edd511d9b09b9878aef309c30080dc74f8072
tree    57267d26197ea2cfe96fae52004372a749399937
parent  c97b4ff28914cef76f36fd4adf26d2a8c665bc6f
...
72
73
74
75
 
76
77
78
...
72
73
74
 
75
76
77
78
0
@@ -72,7 +72,7 @@ class midcom_core_controllers_page extends midcom_core_controllers_baseclasses_m
0
                     $this->object->create();
0
                     break;
0
                 default:
0
- throw new midcom_exception_httperror("{$this->request_method} not allowed", 405);
0
+ throw new midcom_exception_httperror("{$this->dispatcher->request_method} not allowed", 405);
0
             }
0
         }
0
     }
...
473
474
475
476
477
478
 
 
479
480
481
482
483
484
 
485
486
487
...
490
491
492
493
 
494
495
496
...
517
518
519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
521
522
...
473
474
475
 
 
 
476
477
478
479
480
481
482
 
483
484
485
486
...
489
490
491
 
492
493
494
495
...
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
0
@@ -473,15 +473,14 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
             
0
             foreach ($route_path_matches[1] as $index => $varname)
0
             {
0
- preg_match('%/{\$([a-zA-Z]+):([a-zA-Z]+)}/%', $varname, $matches);
0
-
0
- if(count($matches) == 0)
0
+ $variable_parts = explode(':', $varname);
0
+ if(count($variable_parts) == 1)
0
                 {
0
                     $type_hint = '';
0
                 }
0
                 else
0
                 {
0
- $type_hint = $matches[1];
0
+ $type_hint = $variable_parts[0];
0
                 }
0
                                 
0
                 // Strip type hints from variable names
0
@@ -490,7 +489,7 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
                 if ($type_hint == 'token')
0
                 {
0
                     // Tokenize the argument to handle resource typing
0
- $this->action_arguments[$route_id][$varname] = $this->tokenize_argument($this->get[$get_key]);
0
+ $this->action_arguments[$route_id][$varname] = $this->tokenize_argument($route_path_regex_matches[$index + 1]);
0
                 }
0
                 else
0
                 {
0
@@ -517,6 +516,42 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         }
0
         return true;
0
     }
0
+
0
+ private function tokenize_argument($argument)
0
+ {
0
+ $tokens = array
0
+ (
0
+ 'identifier' => '',
0
+ 'variant' => '',
0
+ 'language' => '',
0
+ 'type' => 'html',
0
+ );
0
+ $argument_parts = explode('.', $argument);
0
+
0
+ // First part is always identifier
0
+ $tokens['identifier'] = $argument_parts[0];
0
+
0
+ if (count($argument_parts) >= 2)
0
+ {
0
+ // If there are two or more parts, then second is variant
0
+ $tokens['variant'] = $argument_parts[1];
0
+ }
0
+
0
+ if (count($argument_parts) >= 3)
0
+ {
0
+ // If there are three parts, then third is type
0
+ $tokens['type'] = $argument_parts[2];
0
+ }
0
+
0
+ if (count($argument_parts) >= 4)
0
+ {
0
+ // If there are four or more parts, then third is language and fourth is type
0
+ $tokens['language'] = $argument_parts[2];
0
+ $tokens['type'] = $argument_parts[3];
0
+ }
0
+
0
+ return $tokens;
0
+ }
0
 
0
     /**
0
      * Checks GET part of a route definition and places arguments as needed

Comments

    No one has commented yet.