dbscript
[ class tree: dbscript ] [ index: dbscript ] [ all elements ]

Source for file route.php

Documentation is available at route.php

  1. <?php
  2.  
  3.   /** 
  4.    * dbscript for PHP 4 & 5 - restful crud framework
  5.    * @version 0.1.2 -- 19-Feb-2007
  6.    * @author Brian Hendrickson <brian@dbscript.net>
  7.    * @link http://dbscript.net/
  8.    * @copyright Copyright 2007 Brian Hendrickson
  9.    * @package dbscript
  10.    * @license http://www.opensource.org/licenses/mit-license.php MIT License
  11.    */
  12.  
  13.   /**
  14.    * URI Route
  15.    * 
  16.    * connects the current URI to a Route,
  17.    * establishing the request variable names
  18.    * e.g. my_domain/:resource/:id
  19.    * maps values into $req->resource and $req->id
  20.    * 
  21.    * Usage:
  22.    * <code>
  23.    *   $req->connect( 'virtualdir/:var1/:var2' );
  24.    * </code>
  25.    * 
  26.    * More info...
  27.    * {@link http://dbscript.net/route}
  28.    * 
  29.    * @package dbscript
  30.    * @author Brian Hendrickson <brian@dbscript.net>
  31.    * @access public
  32.    * @version 0.1.2
  33.    */
  34.  
  35. class Route {
  36.  
  37.   var $patterns;
  38.   var $defaults;
  39.   var $requirements;
  40.   var $match;
  41.   var $name;
  42.   
  43.   function Route({
  44.  
  45.     $this->patterns = array();
  46.     $this->requirements = array();
  47.     $this->match = false;
  48.     
  49.     $this->defaults = array(
  50.       
  51.       'controller'=>'index.php',
  52.       'resource'=>NULL,
  53.       'id'=>0,
  54.       'action'=>'get',
  55.       'child'=>0
  56.       
  57.     );
  58.     
  59.   }
  60.   
  61.   function build_url$params$base {
  62.     $url array();
  63.     foreach $this->patterns as $pos => $str {
  64.       if substr$str0== ':' {
  65.         $url[$params[substr$str)];
  66.       else {
  67.         $url[$str;
  68.       }
  69.     }
  70.     return $base "?"implode '/'$url );
  71.   }
  72.  
  73. }
  74.  
  75. ?>

Documentation generated on Mon, 19 Feb 2007 10:25:03 -0800 by phpDocumentor 1.3.1