svn: /pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/ Router.php

From: Date: Tue, 15 Jun 2010 02:04:19 +0000
Subject: svn: /pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/ Router.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9488@lists.php.net to get a copy of this message
gauthierm Tue, 15 Jun 2010 02:04:19 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=300448 Log: Coding standards. Changed paths: U pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/Router.php Modified: pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/Router.php =================================================================== --- pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/Router.php 2010-06-14 23:43:59 UTC (rev 300447) +++ pear2/sandbox/pear2.php.net/trunk/src/PEAR2Web/Router.php 2010-06-15 02:04:19 UTC (rev 300448) @@ -6,43 +6,48 @@ { public static function getRoute($requestURI) { + $options = array(); + if (!empty($_SERVER['QUERY_STRING'])) { - $requestURI = substr($requestURI, 0, strlen($_SERVER['QUERY_STRING'])*-1-1); + $requestURI = substr( + $requestURI, + 0, + -strlen($_SERVER['QUERY_STRING']) - 1 + ); } - $base = \PEAR2\SimpleChannelFrontend\Main::getURL(); - $q_base = preg_quote($base, '/'); + $base = \PEAR2\SimpleChannelFrontend\Main::getURL(); + $quotedBase = preg_quote($base, '/'); + $packageExp = "/" + . "^" + . $quotedBase . " # base" + . "(?<package>[0-9a-z_]+) # package name" + . "(- # dash separator" + . " (?<version>[0-9ab.]+) # version" + . ")? # ... is optional" + . "$" + . "/xi"; - $options = array(); + if ($requestURI === $base) { + $options['view'] = 'news'; + } elseif ($requestURI === $base . 'categories/') { + $options['view'] = 'categories'; + } elseif ($requestURI === $base . 'packages/') { + $options['view'] = 'packages'; + } elseif ($requestURI === $base . 'support/') { + $options['view'] = 'support'; + } elseif (preg_match($packageExp, $requestURI, $matches) === 1) { - switch(true) { - case ($requestURI == $base): - // Short circuit - $options['view'] = 'news'; - break; - case ($requestURI == $base . 'categories/'): - $options['view'] = 'categories'; - break; - case ($requestURI == $base . 'packages/'): - $options['view'] = 'packages'; - break; - case ($requestURI == $base . 'support/'): - $options['view'] = 'support'; - break; + // Viewing an individual package + $options['view'] = 'package'; + $options['package'] = $matches['package']; - case preg_match('/'.$q_base.'(?<package>[0-9a-z_]+)(-(?<version>[0-9ab.]+))?$/i', - $requestURI, $matches): + // Release selected + if (isset($matches['version'])) { + $options['view'] = 'release'; + $options['packageVersion'] = $matches['version']; + } - // Viewing an individual package - $options['view'] = 'package'; - $options['package'] = $matches['package']; - - // Release selected - if (isset($matches['version'])) { - $options['view'] = 'release'; - $options['packageVersion'] = $matches['version']; - } - break; } return $options;

« previous php.pear.core (#9488) next »