# RouterChainRule.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2008 by Sergey S. Sergeev                               *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00012     final class RouterChainRule extends RouterBaseRule
    00013     {
    00014         protected $routes       = array();
    00015         protected $separators   = array();
    00016
    00020         public static function create()
    00021         {
    00022             return new self();
    00023         }
    00024
    00028         public function chain(RouterRule $route, $separator = '/')
    00029         {
    00030             $this->routes[] = $route;
    00031             $this->separators[] = $separator;
    00032
    00033             return $this;
    00034         }
    00035
    00036         public function getCount()
    00037         {
    00038             return count($this->routes);
    00039         }
    00040
    00041         public function match(HttpRequest $request)
    00042         {
    00043             $values = array();
    00044
    00045             foreach ($this->routes as $key => $route) {
    00046                 $res = $route->match($request);
    00047
    00048                 if (empty($res))
    00049                     return array();
    00050
    00051                 $values = $res + $values;
    00052             }
    00053
    00054             return $values;
    00055         }
    00056
    00057         public function assembly(
    00058             array $data = array(),
    00059             $reset = false,
    00060             $encode = false
    00061         )
    00062         {
    00063             $value = null;
    00064
    00065             foreach ($this->routes as $key => $route) {
    00066                 if ($key > 0)
    00067                     $value .= $this->separators[$key];
    00068
    00069                 $value .= $route->assembly($data, $reset, $encode);
    00070
    00071                 if (
    00072                     $route instanceof RouterHostnameRule
    00073                     && $key > 0
    00074                 ) {
    00075                     throw new RouterException('wrong chain route');
    00076                 }
    00077             }
    00078
    00079             return $value;
    00080         }
    00081     }
    00082 ?>