/usr/share/php/Horde/Routes/Route.php is in php-horde-routes 2.0.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 | <?php
/**
* Horde Routes package
*
* This package is heavily inspired by the Python "Routes" library
* by Ben Bangert (http://routes.groovie.org). Routes is based
* largely on ideas from Ruby on Rails (http://www.rubyonrails.org).
*
* @author Maintainable Software, LLC. (http://www.maintainable.com)
* @author Mike Naberezny <mike@maintainable.com>
* @license http://www.horde.org/licenses/bsd BSD
* @package Routes
*/
/**
* The Route object holds a route recognition and generation routine.
* See __construct() docs for usage.
*
* @package Routes
*/
class Horde_Routes_Route
{
/**
* The path for this route, such as ':controller/:action/:id'
* @var string
*/
public $routePath;
/**
* Encoding of this route (not yet supported)
* @var string
*/
public $encoding = 'utf-8';
/**
* What to do on decoding errors? 'ignore' or 'replace'
* @var string
*/
public $decodeErrors = 'replace';
/**
* Is this a static route?
* @var string
*/
public $static;
/**
* Filter function to operate on arguments before generation
* @var callback
*/
public $filter;
/**
* Is this an absolute path? (Mapper will not prepend SCRIPT_NAME)
* @var boolean
*/
public $absolute;
/**
* Does this route use explicit mode (no implicit defaults)?
* @var boolean
*/
public $explicit;
/**
* Default keyword arguments for this route
* @var array
*/
public $defaults = array();
/**
* Array of keyword args for special conditions (method, subDomain, function)
* @var array
*/
public $conditions;
/**
* Maximum keys that this route could utilize.
* @var array
*/
public $maxKeys;
/**
* Minimum keys required to generate this route
* @var array
*/
public $minKeys;
/**
* Default keywords that don't exist in the path; can't be changed by an incomng URL.
* @var array
*/
public $hardCoded;
/**
* Requirements for this route
* @var array
*/
public $reqs;
/**
* Regular expression for matching this route
* @var string
*/
public $regexp;
/**
* Route path split by '/'
* @var array
*/
protected $_routeList;
/**
* Reverse of $routeList
* @var array
*/
protected $_routeBackwards;
/**
* Characters that split the parts of a URL
* @var array
*/
protected $_splitChars;
/**
* Last path part used by buildNextReg()
* @var string
*/
protected $_prior;
/**
* Requirements formatted as regexps suitable for preg_match()
* @var array
*/
protected $_reqRegs;
/**
* Member name if this is a RESTful route
* @see resource()
* @var null|string
*/
protected $_memberName;
/**
* Collection name if this is a RESTful route
* @see resource()
* @var null|string
*/
protected $_collectionName;
/**
* Name of the parent resource, if this is a RESTful route & has a parent
* @see resource
* @var string
*/
protected $_parentResource;
/**
* Initialize a route, with a given routepath for matching/generation
*
* The set of keyword args will be used as defaults.
*
* Usage:
* $route = new Horde_Routes_Route(':controller/:action/:id');
*
* $route = new Horde_Routes_Route('date/:year/:month/:day',
* array('controller'=>'blog', 'action'=>'view'));
*
* $route = new Horde_Routes_Route('archives/:page',
* array('controller'=>'blog', 'action'=>'by_page',
* 'requirements' => array('page'=>'\d{1,2}'));
*
* Note:
* Route is generally not called directly, a Mapper instance connect()
* method should be used to add routes.
*/
public function __construct($routePath, $kargs = array())
{
$this->routePath = $routePath;
// Don't bother forming stuff we don't need if its a static route
$this->static = isset($kargs['_static']) ? $kargs['_static'] : false;
$this->filter = isset($kargs['_filter']) ? $kargs['_filter'] : null;
unset($kargs['_filter']);
$this->absolute = isset($kargs['_absolute']) ? $kargs['_absolute'] : false;
unset($kargs['_absolute']);
// Pull out the member/collection name if present, this applies only to
// map.resource
$this->_memberName = isset($kargs['_memberName']) ? $kargs['_memberName'] : null;
unset($kargs['_memberName']);
$this->_collectionName = isset($kargs['_collectionName']) ? $kargs['_collectionName'] : null;
unset($kargs['_collectionName']);
$this->_parentResource = isset($kargs['_parentResource']) ? $kargs['_parentResource'] : null;
unset($kargs['_parentResource']);
// Pull out route conditions
$this->conditions = isset($kargs['conditions']) ? $kargs['conditions'] : null;
unset($kargs['conditions']);
// Determine if explicit behavior should be used
$this->explicit = isset($kargs['_explicit']) ? $kargs['_explicit'] : false;
unset($kargs['_explicit']);
// Reserved keys that don't count
$reservedKeys = array('requirements');
// Name has been changed from the Python version
// This is a list of characters natural splitters in a URL
$this->_splitChars = array('/', ',', ';', '.', '#');
// trim preceding '/' if present
if (substr($this->routePath, 0, 1) == '/') {
$routePath = substr($this->routePath, 1);
}
// Build our routelist, and the keys used in the route
$this->_routeList = $this->_pathKeys($routePath);
$routeKeys = array();
foreach ($this->_routeList as $key) {
if (is_array($key)) { $routeKeys[] = $key['name']; }
}
// Build a req list with all the regexp requirements for our args
$this->reqs = isset($kargs['requirements']) ? $kargs['requirements'] : array();
$this->_reqRegs = array();
foreach ($this->reqs as $key => $value) {
$this->_reqRegs[$key] = '@^' . str_replace('@', '\@', $value) . '$@';
}
// Update our defaults and set new default keys if needed. defaults
// needs to be saved
list($this->defaults, $defaultKeys) = $this->_defaults($routeKeys, $reservedKeys, $kargs);
// Save the maximum keys we could utilize
$this->maxKeys = array_keys(array_flip(array_merge($defaultKeys, $routeKeys)));
list($this->minKeys, $this->_routeBackwards) = $this->_minKeys($this->_routeList);
// Populate our hardcoded keys, these are ones that are set and don't
// exist in the route
$this->hardCoded = array();
foreach ($this->maxKeys as $key) {
if (!in_array($key, $routeKeys) && $this->defaults[$key] != null) {
$this->hardCoded[] = $key;
}
}
}
/**
* Utility method to walk the route, and pull out the valid
* dynamic/wildcard keys
*
* @param string $routePath Route path
* @return array Route list
*/
protected function _pathKeys($routePath)
{
$collecting = false;
$current = '';
$doneOn = array();
$varType = '';
$justStarted = false;
$routeList = array();
foreach (preg_split('//', $routePath, -1, PREG_SPLIT_NO_EMPTY) as $char) {
if (!$collecting && in_array($char, array(':', '*'))) {
$justStarted = true;
$collecting = true;
$varType = $char;
if (strlen($current) > 0) {
$routeList[] = $current;
$current = '';
}
} elseif ($collecting && $justStarted) {
$justStarted = false;
if ($char == '(') {
$doneOn = array(')');
} else {
$current = $char;
// Basically appends '-' to _splitChars
// Helps it fall in line with the Python idioms.
$doneOn = $this->_splitChars + array('-');
}
} elseif ($collecting && !in_array($char, $doneOn)) {
$current .= $char;
} elseif ($collecting) {
$collecting = false;
$routeList[] = array('type' => $varType, 'name' => $current);
if (in_array($char, $this->_splitChars)) {
$routeList[] = $char;
}
$doneOn = $varType = $current = '';
} else {
$current .= $char;
}
}
if ($collecting) {
$routeList[] = array('type' => $varType, 'name' => $current);
} elseif (!empty($current)) {
$routeList[] = $current;
}
return $routeList;
}
/**
* Utility function to walk the route backwards
*
* Will determine the minimum keys we must have to generate a
* working route.
*
* @param array $routeList Route path split by '/'
* @return array [minimum keys for route, route list reversed]
*/
protected function _minKeys($routeList)
{
$minKeys = array();
$backCheck = array_reverse($routeList);
$gaps = false;
foreach ($backCheck as $part) {
if (!is_array($part) && !in_array($part, $this->_splitChars)) {
$gaps = true;
continue;
} elseif (!is_array($part)) {
continue;
}
$key = $part['name'];
if (array_key_exists($key, $this->defaults) && !$gaps)
continue;
$minKeys[] = $key;
$gaps = true;
}
return array($minKeys, $backCheck);
}
/**
* Creates a default array of strings
*
* Puts together the array of defaults, turns non-null values to strings,
* and add in our action/id default if they use and do not specify it
*
* Precondition: $this->_defaultKeys is an array of the currently assumed default keys
*
* @param array $routekeys All the keys found in the route path
* @param array $reservedKeys Array of keys not in the route path
* @param array $kargs Keyword args passed to the Route constructor
* @return array [defaults, new default keys]
*/
protected function _defaults($routeKeys, $reservedKeys, $kargs)
{
$defaults = array();
// Add in a controller/action default if they don't exist
if ((!in_array('controller', $routeKeys)) &&
(!in_array('controller', array_keys($kargs))) &&
(!$this->explicit)) {
$kargs['controller'] = 'content';
}
if (!in_array('action', $routeKeys) &&
(!in_array('action', array_keys($kargs))) &&
(!$this->explicit)) {
$kargs['action'] = 'index';
}
$defaultKeys = array();
foreach (array_keys($kargs) as $key) {
if (!in_array($key, $reservedKeys)) {
$defaultKeys[] = $key;
}
}
foreach ($defaultKeys as $key) {
if ($kargs[$key] !== null) {
$defaults[$key] = (string)$kargs[$key];
} else {
$defaults[$key] = null;
}
}
if (in_array('action', $routeKeys) &&
(!array_key_exists('action', $defaults)) &&
(!$this->explicit)) {
$defaults['action'] = 'index';
}
if (in_array('id', $routeKeys) &&
(!array_key_exists('id', $defaults)) &&
(!$this->explicit)) {
$defaults['id'] = null;
}
$newDefaultKeys = array();
foreach (array_keys($defaults) as $key) {
if (!in_array($key, $reservedKeys)) {
$newDefaultKeys[] = $key;
}
}
return array($defaults, $newDefaultKeys);
}
/**
* Create the regular expression for matching.
*
* Note: This MUST be called before match can function properly.
*
* clist should be a list of valid controller strings that can be
* matched, for this reason makeregexp should be called by the web
* framework after it knows all available controllers that can be
* utilized.
*
* @param array $clist List of all possible controllers
* @return void
*/
public function makeRegexp($clist)
{
list($reg, $noreqs, $allblank) = $this->buildNextReg($this->_routeList, $clist);
if (empty($reg)) {
$reg = '/';
}
$reg = $reg . '(/)?$';
if (substr($reg, 0, 1) != '/') {
$reg = '/' . $reg;
}
$reg = '^' . $reg;
$this->regexp = $reg;
}
/**
* Recursively build a regexp given a path, and a controller list.
*
* Returns the regular expression string, and two booleans that can be
* ignored as they're only used internally by buildnextreg.
*
* @param array $path The RouteList for the path
* @param array $clist List of all possible controllers
* @return array [array, boolean, boolean]
*/
public function buildNextReg($path, $clist)
{
if (!empty($path)) {
$part = $path[0];
} else {
$part = '';
}
// noreqs will remember whether the remainder has either a string
// match, or a non-defaulted regexp match on a key, allblank remembers
// if the rest could possible be completely empty
list($rest, $noreqs, $allblank) = array('', true, true);
if (count($path) > 1) {
$this->_prior = $part;
list($rest, $noreqs, $allblank) = $this->buildNextReg(array_slice($path, 1), $clist);
}
if (is_array($part) && $part['type'] == ':') {
$var = $part['name'];
$partreg = '';
// First we plug in the proper part matcher
if (array_key_exists($var, $this->reqs)) {
$partreg = '(?P<' . $var . '>' . $this->reqs[$var] . ')';
} elseif ($var == 'controller') {
$partreg = '(?P<' . $var . '>' . implode('|', array_map('preg_quote', $clist)) . ')';
} elseif (in_array($this->_prior, array('/', '#'))) {
$partreg = '(?P<' . $var . '>[^' . $this->_prior . ']+?)';
} else {
if (empty($rest)) {
$partreg = '(?P<' . $var . '>[^/]+?)';
} else {
$partreg = '(?P<' . $var . '>[^' . implode('', $this->_splitChars) . ']+?)';
}
}
if (array_key_exists($var, $this->reqs)) {
$noreqs = false;
}
if (!array_key_exists($var, $this->defaults)) {
$allblank = false;
$noreqs = false;
}
// Now we determine if its optional, or required. This changes
// depending on what is in the rest of the match. If noreqs is
// true, then its possible the entire thing is optional as there's
// no reqs or string matches.
if ($noreqs) {
// The rest is optional, but now we have an optional with a
// regexp. Wrap to ensure that if we match anything, we match
// our regexp first. It's still possible we could be completely
// blank as we have a default
if (array_key_exists($var, $this->reqs) && array_key_exists($var, $this->defaults)) {
$reg = '(' . $partreg . $rest . ')?';
// Or we have a regexp match with no default, so now being
// completely blank form here on out isn't possible
} elseif (array_key_exists($var, $this->reqs)) {
$allblank = false;
$reg = $partreg . $rest;
// If the character before this is a special char, it has to be
// followed by this
} elseif (array_key_exists($var, $this->defaults) && in_array($this->_prior, array(',', ';', '.'))) {
$reg = $partreg . $rest;
// Or we have a default with no regexp, don't touch the allblank
} elseif (array_key_exists($var, $this->defaults)) {
$reg = $partreg . '?' . $rest;
// Or we have a key with no default, and no reqs. Not possible
// to be all blank from here
} else {
$allblank = false;
$reg = $partreg . $rest;
}
// In this case, we have something dangling that might need to be
// matched
} else {
// If they can all be blank, and we have a default here, we know
// its safe to make everything from here optional. Since
// something else in the chain does have req's though, we have
// to make the partreg here required to continue matching
if ($allblank && array_key_exists($var, $this->defaults)) {
$reg = '(' . $partreg . $rest . ')?';
// Same as before, but they can't all be blank, so we have to
// require it all to ensure our matches line up right
} else {
$reg = $partreg . $rest;
}
}
} elseif (is_array($part) && $part['type'] == '*') {
$var = $part['name'];
if ($noreqs) {
$reg = '(?P<' . $var . '>.*)' . $rest;
if (!array_key_exists($var, $this->defaults)) {
$allblank = false;
$noreqs = false;
}
} else {
if ($allblank && array_key_exists($var, $this->defaults)) {
$reg = '(?P<' . $var . '>.*)' . $rest;
} elseif (array_key_exists($var, $this->defaults)) {
$reg = '(?P<' . $var . '>.*)' . $rest;
} else {
$allblank = false;
$noreqs = false;
$reg = '(?P<' . $var . '>.*)' . $rest;
}
}
} elseif ($part && in_array(substr($part, -1), $this->_splitChars)) {
if ($allblank) {
$reg = preg_quote(substr($part, 0, -1)) . '(' . preg_quote(substr($part, -1)) . $rest . ')?';
} else {
$allblank = false;
$reg = preg_quote($part) . $rest;
}
// We have a normal string here, this is a req, and it prevents us from
// being all blank
} else {
$noreqs = false;
$allblank = false;
$reg = preg_quote($part) . $rest;
}
return array($reg, $noreqs, $allblank);
}
/**
* Match a url to our regexp.
*
* While the regexp might match, this operation isn't
* guaranteed as there's other factors that can cause a match to fail
* even though the regexp succeeds (Default that was relied on wasn't
* given, requirement regexp doesn't pass, etc.).
*
* Therefore the calling function shouldn't assume this will return a
* valid dict, the other possible return is False if a match doesn't work
* out.
*
* @param string $url URL to match
* @param array Keyword arguments
* @return null|array Array of match data if matched, Null otherwise
*/
public function match($url, $kargs = array())
{
$defaultKargs = array('environ' => array(),
'subDomains' => false,
'subDomainsIgnore' => array(),
'domainMatch' => '');
$kargs = array_merge($defaultKargs, $kargs);
// Static routes don't match, they generate only
if ($this->static) {
return false;
}
if (substr($url, -1) == '/' && strlen($url) > 1) {
$url = substr($url, 0, -1);
}
// Match the regexps we generated
$match = preg_match('@' . str_replace('@', '\@', $this->regexp) . '@', $url, $matches);
if ($match == 0) {
return false;
}
$host = isset($kargs['environ']['HTTP_HOST']) ? $kargs['environ']['HTTP_HOST'] : null;
if ($host !== null && !empty($kargs['subDomains'])) {
$host = substr($host, 0, strpos(':', $host));
$subMatch = '@^(.+?)\.' . $kargs['domainMatch'] . '$';
$subdomain = preg_replace($subMatch, '$1', $host);
if (!in_array($subdomain, $kargs['subDomainsIgnore']) && $host != $subdomain) {
$subDomain = $subdomain;
}
}
if (!empty($this->conditions)) {
if (isset($this->conditions['method'])) {
if (empty($kargs['environ']['REQUEST_METHOD'])) { return false; }
if (!in_array($kargs['environ']['REQUEST_METHOD'], $this->conditions['method'])) {
return false;
}
}
// Check sub-domains?
$use_sd = isset($this->conditions['subDomain']) ? $this->conditions['subDomain'] : null;
if (!empty($use_sd) && empty($subDomain)) {
return false;
}
if (is_array($use_sd) && !in_array($subDomain, $use_sd)) {
return false;
}
}
$matchDict = $matches;
// Clear out int keys as PHP gives us both the named subgroups and numbered subgroups
foreach ($matchDict as $key => $val) {
if (is_int($key)) {
unset($matchDict[$key]);
}
}
$result = array();
$extras = Horde_Routes_Utils::arraySubtract(array_keys($this->defaults), array_keys($matchDict));
foreach ($matchDict as $key => $val) {
// TODO: character set decoding
if ($key != 'path_info' && $this->encoding) {
$val = urldecode($val);
}
if (empty($val) && array_key_exists($key, $this->defaults) && !empty($this->defaults[$key])) {
$result[$key] = $this->defaults[$key];
} else {
$result[$key] = $val;
}
}
foreach ($extras as $key) {
$result[$key] = $this->defaults[$key];
}
// Add the sub-domain if there is one
if (!empty($kargs['subDomains'])) {
$result['subDomain'] = $subDomain;
}
// If there's a function, call it with environ and expire if it
// returns False
if (!empty($this->conditions) && array_key_exists('function', $this->conditions) &&
!call_user_func_array($this->conditions['function'], array($kargs['environ'], $result))) {
return false;
}
return $result;
}
/**
* Generate a URL from ourself given a set of keyword arguments
*
* @param array $kargs Keyword arguments
* @param null|string Null if generation failed, URL otherwise
*/
public function generate($kargs)
{
$defaultKargs = array('_ignoreReqList' => false,
'_appendSlash' => false);
$kargs = array_merge($defaultKargs, $kargs);
$_appendSlash = $kargs['_appendSlash'];
unset($kargs['_appendSlash']);
$_ignoreReqList = $kargs['_ignoreReqList'];
unset($kargs['_ignoreReqList']);
// Verify that our args pass any regexp requirements
if (!$_ignoreReqList) {
foreach ($this->reqs as $key => $v) {
$value = (isset($kargs[$key])) ? $kargs[$key] : null;
if (!empty($value) && !preg_match($this->_reqRegs[$key], $value)) {
return null;
}
}
}
// Verify that if we have a method arg, it's in the method accept list.
// Also, method will be changed to _method for route generation.
$meth = (isset($kargs['method'])) ? $kargs['method'] : null;
if ($meth) {
if ($this->conditions && isset($this->conditions['method']) &&
(!in_array(Horde_String::upper($meth), $this->conditions['method']))) {
return null;
}
unset($kargs['method']);
}
$routeList = $this->_routeBackwards;
$urlList = array();
$gaps = false;
foreach ($routeList as $part) {
if (is_array($part) && $part['type'] == ':') {
$arg = $part['name'];
// For efficiency, check these just once
$hasArg = array_key_exists($arg, $kargs);
$hasDefault = array_key_exists($arg, $this->defaults);
// Determine if we can leave this part off
// First check if the default exists and wasn't provided in the
// call (also no gaps)
if ($hasDefault && !$hasArg && !$gaps) {
continue;
}
// Now check to see if there's a default and it matches the
// incoming call arg
if (($hasDefault && $hasArg) && $kargs[$arg] == $this->defaults[$arg] && !$gaps) {
continue;
}
// We need to pull the value to append, if the arg is NULL and
// we have a default, use that
if ($hasArg && $kargs[$arg] === null && $hasDefault && !$gaps) {
continue;
// Otherwise if we do have an arg, use that
} elseif ($hasArg) {
$val = ($kargs[$arg] === null) ? 'null' : $kargs[$arg];
} elseif ($hasDefault && $this->defaults[$arg] != null) {
$val = $this->defaults[$arg];
// No arg at all? This won't work
} else {
return null;
}
$urlList[] = Horde_Routes_Utils::urlQuote($val, $this->encoding);
if ($hasArg) {
unset($kargs[$arg]);
}
$gaps = true;
} elseif (is_array($part) && $part['type'] == '*') {
$arg = $part['name'];
$kar = (isset($kargs[$arg])) ? $kargs[$arg] : null;
if ($kar != null) {
$urlList[] = Horde_Routes_Utils::urlQuote($kar, $this->encoding);
$gaps = true;
}
} elseif (!empty($part) && in_array(substr($part, -1), $this->_splitChars)) {
if (!$gaps && in_array($part, $this->_splitChars)) {
continue;
} elseif (!$gaps) {
$gaps = true;
$urlList[] = substr($part, 0, -1);
} else {
$gaps = true;
$urlList[] = $part;
}
} else {
$gaps = true;
$urlList[] = $part;
}
}
$urlList = array_reverse($urlList);
$url = implode('', $urlList);
if (substr($url, 0, 1) != '/') {
$url = '/' . $url;
}
$extras = $kargs;
foreach ($this->maxKeys as $key) {
unset($extras[$key]);
}
$extras = array_keys($extras);
if (!empty($extras)) {
if ($_appendSlash && substr($url, -1) != '/') {
$url .= '/';
}
$url .= '?';
$newExtras = array();
foreach ($kargs as $key => $value) {
if (in_array($key, $extras) && ($key != 'action' || $key != 'controller')) {
$newExtras[$key] = $value;
}
}
$url .= http_build_query($newExtras);
} elseif ($_appendSlash && substr($url, -1) != '/') {
$url .= '/';
}
return $url;
}
}
|