本文整理汇总了PHP中Zend_Controller_Router_Route::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Router_Route::match方法的具体用法?PHP Zend_Controller_Router_Route::match怎么用?PHP Zend_Controller_Router_Route::match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Router_Route
的用法示例。
在下文中一共展示了Zend_Controller_Router_Route::match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request, $partial = false)
{
if (!$request instanceof \Zend_Controller_Request_Http) {
throw new \Zend_Controller_Router_Exception("Route needs a http request");
}
$return = parent::match($request->getPathInfo(), $partial);
if (!$return) {
return $return;
}
if (!($token = $return[$this->_tokenVariable])) {
throw new \Zend_Controller_Router_Exception("Token not defined", 400);
}
if (!($tokenData = \Download\Service\DownloadTokenService::getInstance()->popToken($token))) {
throw new \Zend_Controller_Router_Exception("Token does not exist or has expired", 400);
}
$return = array_merge($return, $tokenData->exportData());
$return['downloadToken'] = $tokenData;
$return['module'] = 'download';
//Data defined inside token
$return['controller'] = $tokenData->controller;
$return['action'] = $tokenData->action;
if (is_array($tokenData->params)) {
$return += $tokenData->params;
}
return $return;
}
示例2: match
/**
* Attempt to match the current request URL
* If a match is found, instantiate a new ImboClient
*
* @see Zend_Controller_Router_Route::match()
*/
public function match($path, $partial = false)
{
$match = parent::match($path, $partial);
$config = array();
$instance = false;
$imgUrl = '';
if ($match) {
$instance = $match['instance'];
// Check if the passed instance exists
if (!isset($this->instances[$instance])) {
throw new Zend_Controller_Router_Exception('Instance "' . $instance . '" does not exist in configuration', 404);
}
// If this is not a sub-action, check if this is an XMLHttpRequest
if ($match['controller'] != 'instance' && (!isset($_SERVER['X_REQUESTED_WITH']) || $_SERVER['X_REQUESTED_WITH'] != 'XMLHttpRequest')) {
$match['controller'] = 'instance';
$match['action'] = 'index';
}
// Create an imbo client for the given instance and make it available in request
$config = $this->instances[$instance];
$match['imboClient'] = new ImboClient\Client($config['host'], $config['pubkey'], $config['privkey']);
$imgUrl = $match['imboClient']->getImagesUrl();
}
// Set active instance name to view so we may use it in frontend
$frontController = Zend_Controller_Front::getInstance();
$view = $frontController->getParam('bootstrap')->getResource('view');
$view->activeInstance = $instance;
$view->imagesUrl = $imgUrl;
$view->maxUploadSize = $this->getMaxUploadSize($config);
return $match;
}
示例3: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$return = parent::match($path, $partial);
// add the RESTful action mapping
if ($return) {
//add the data that is a wildcard to the end of the return array
$path = trim($path, self::URI_DELIMITER);
$this->_route = trim($this->_route, self::URI_DELIMITER);
if ($path != '') {
$elementsPath = explode(self::URI_DELIMITER, $path);
}
if ($this->_route != '') {
$elementsRoute = explode(self::URI_DELIMITER, $this->_route);
}
//and now get rid of all entries that are not a wildcard. when we have done that,
//we have what we wanted...
foreach ($elementsRoute as $key => $value) {
if ($value !== "*") {
array_shift($elementsPath);
} else {
break;
}
}
$i = 0;
foreach ($elementsPath as $value) {
$return['wild' . $i] = $value;
$i++;
}
//reset things
$request = $this->_front->getRequest();
$params = $request->getParams();
$path = $elementsPath;
//Store path count for method mapping
$pathElementCount = count($path);
// Determine Action
$requestMethod = strtolower($request->getMethod());
if ($requestMethod != 'get') {
if ($request->getParam('_method')) {
$return[$this->_actionKey] = strtolower($request->getParam('_method'));
} elseif ($request->getHeader('X-HTTP-Method-Override')) {
$return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
} else {
$return[$this->_actionKey] = $requestMethod;
}
} else {
// this is only an index call, if no options are acutally provided
if ($pathElementCount > 0) {
$return[$this->_actionKey] = 'get';
} else {
$return[$this->_actionKey] = 'index';
}
}
}
return $return;
}
示例4: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$params = parent::match($path, $partial);
if (!empty($params['controller']) && 'Axis_Admin' !== $params['module']) {
$params['controller'] = 'admin_' . $params['controller'];
}
if ($params) {
Axis_Area::backend();
}
return $params;
}
示例5: match
public function match($path)
{
if ($this->_actionKey === null) {
require_once 'Xzend/Controller/Exception.php';
throw new Xzend_Controller_Exception('call setActionKey() before ' . __METHOD__);
}
if ($this->_restMethodKey === null) {
require_once 'Xzend/Controller/Exception.php';
throw new Xzend_Controller_Exception('call setRestMethod() before ' . __METHOD__);
}
#$representation = null;
#if(preg_match('/(.*)\.(\w*)$/', $path, $matches))
if (preg_match('/(.*)$/', $path, $matches)) {
$path = $matches[1];
#$representation = $matches[2];
}
$return = parent::match($path);
if (!$return) {
return false;
}
/*
if($this->_representationKey !== null)
{
if($representation !== null)
{
$return[$this->_representationKey] = $representation;
}
else if(isset($this->_defaults[$this->_representationKey]))
{
$return[$this->_representationKey] = $this->_defaults[$this->_representationKey];
}
}
*/
$defaults = $this->getDefaults();
if (!isset($defaults[$this->_getRestMethod()])) {
return false;
}
$return[$this->_actionKey] = $defaults[$this->_getRestMethod()];
unset($return['get']);
unset($return['put']);
unset($return['post']);
unset($return['head']);
unset($return['delete']);
/*
print '<pre>';
print_r($return);
exit;
*/
return $return;
}
示例6: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$return = parent::match($path, $partial);
// add the RESTful action mapping
if ($return) {
$request = $this->_front->getRequest();
$path = $request->getPathInfo();
$params = $request->getParams();
$path = trim($path, self::URI_DELIMITER);
if ($path != '') {
$path = explode(self::URI_DELIMITER, $path);
}
//Store path count for method mapping
$pathElementCount = count($path);
// Determine Action
$requestMethod = strtolower($request->getMethod());
if ($requestMethod != 'get') {
if ($request->getParam('_method')) {
$return[$this->_actionKey] = strtolower($request->getParam('_method'));
} elseif ($request->getHeader('X-HTTP-Method-Override')) {
$return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
} else {
$return[$this->_actionKey] = $requestMethod;
}
// Map PUT and POST to actual create/update actions
// based on parameter count (posting to resource or collection)
switch ($return[$this->_actionKey]) {
case 'post':
if ($pathElementCount > 0) {
$return[$this->_actionKey] = 'put';
} else {
$return[$this->_actionKey] = 'post';
}
break;
case 'put':
$return[$this->_actionKey] = 'put';
break;
}
} else {
// if the last argument in the path is a numeric value, consider this request a GET of an item
$lastParam = array_pop($path);
if (is_numeric($lastParam)) {
$return[$this->_actionKey] = 'get';
} else {
$return[$this->_actionKey] = 'index';
}
}
}
return $return;
}
示例7: match
public function match($path)
{
$representation = null;
if (preg_match('/\\.\\w*$/', $path, $matches)) {
$representation = trim($matches[0], '.');
$path = preg_replace('/(\\.\\w*)?$/', '', $path);
}
if ($this->_representationParam !== null && $this->_defaultRepresentation !== null) {
$this->_defaults[$this->_representationParam] = $this->_defaultRepresentation;
}
$return = parent::match($path);
if (is_array($return) && $this->_representationParam !== null && !isset($return[$this->_representationParam])) {
$return[$this->_representationParam] = $representation;
}
return $return;
}
示例8: match
/**
* Matches a user submitted path with a previously defined route.
* Assigns and returns an array of defaults on a successful match.
*
* @param string $request used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request)
{
// This is in here so that the router doesn't break when Route_Abstract gets
// upped to version 2 and accepts $request objects. (after that happens, this
// code may be removed
if (parent::getVersion() == 1) {
$match = $request->getPathInfo();
} else {
$match = $request;
}
$result = parent::match($match);
$params = $request->getParams();
$map = $this->_variableMap;
// If certain map elements weren't specified, we look for their regular ?controller= names
if (!isset($map["controller"])) {
$map["controller"] = "controller";
}
if (!isset($map["module"])) {
$map["module"] = "module";
}
if (!isset($map["action"])) {
$map["action"] = "action";
}
foreach ($map as $mvcParam => $urlParam) {
if (isset($params[$urlParam])) {
$result[$mvcParam] = $params[$urlParam];
// save for later assembly
$this->_paramValues[$urlParam] = $params[$urlParam];
} else {
// maybe we got it from the regular $route (first param to constructor)
if (!isset($result[$mvcParam])) {
// This route isn't satisfied because not all vars were passed.
return false;
}
}
}
return $result;
}
示例9: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path)
{
if (!count($this->_host)) {
// We need a host
if (!isset($_SERVER['HTTP_HOST'])) {
return false;
}
// Get host
$requestHost = trim($_SERVER['HTTP_HOST']);
// Assign host and remove any :42 port indicators
$requestHost = preg_replace('/' . self::PORT_SEPARATOR . '\d+/', '', $requestHost);
$this->_host = array_reverse(explode(self::DOMAIN_SEPARATOR, $requestHost));
}
// If cache checked, continue match
$matchKey = serialize($this->_hostParts);
if (isset(self::$_matchCache[$matchKey]) && self::$_matchCache[$matchKey] === true) {
return parent::match($path);
} else if (isset(self::$_matchCache[$matchKey]) && self::$_matchCache[$matchKey] === false) {
return false;
}
$hostStaticCount = 0;
if (!empty($requestHost)) {
$defaults = $this->_defaults;
if (count($defaults)) {
$unique = array_combine(array_keys($defaults), array_fill(0, count($defaults), true));
} else {
$unique = array();
}
foreach ($this->_host as $pos => $part) {
// Make sure required parts exist (eg foo.com -> foo and com)
if (!isset($this->_hostParts[$pos])) {
self::$_matchCache[$matchKey] = false;
return false;
}
// Don't match if wildcard
if ($this->_hostParts[$pos]['regex'] === self::DOMAIN_WILDCARD) {
continue;
}
$hostPart = $this->_hostParts[$pos];
$name = isset($hostPart['name']) ? $hostPart['name'] : null;
if ($name === null) {
if ($hostPart['regex'] != $part) {
self::$_matchCache[$matchKey] = false;
return false;
}
} else if ($hostPart['regex'] === null) {
if (strlen($part) == 0) {
self::$_matchCache[$matchKey] = false;
return false;
}
} else {
$regex = $this->_regexDelimiter . '^' . $hostPart['regex'] . '$' . $this->_regexDelimiter . 'iu';
if (!preg_match($regex, $part)) {
self::$_matchCache[$matchKey] = false;
return false;
}
}
if ($name !== null) {
// It's a variable. Setting a value
$this->_values[$name] = $part;
$unique[$name] = true;
} else {
$hostStaticCount++;
}
}
}
$return = $this->_values + $this->_defaults;
// Check if all static mappings have been met
if ($this->_hostStaticCount != $hostStaticCount) {
self::$_matchCache[$matchKey] = false;
return false;
}
// Check if all map variables have been initialized
foreach ($this->_hostVars as $var) {
if (!array_key_exists($var, $return)) {
self::$_matchCache[$matchKey] = false;
return false;
}
//.........这里部分代码省略.........
示例10: testAssembleResetDefaults
public function testAssembleResetDefaults()
{
$route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
$values = $route->match('news/view/id/3');
$url = $route->assemble(array('action' => null));
$this->assertSame('news/index/id/3', $url);
$url = $route->assemble(array('action' => null, 'id' => null));
$this->assertSame('news/index', $url);
}
示例11: testRouteStaticNotMatched
public function testRouteStaticNotMatched()
{
$route = new Zend_Controller_Router_Route('archive/:controller/:action/:year', array('action' => 'action'), array('year' => '\\d+'));
$values = $route->match('news/c/a/2000');
$this->assertEquals($values, false, "Failed validation");
}
示例12: testPartialMatch
public function testPartialMatch()
{
$this->markTestSkipped('Route features not ready');
$route = new Zend_Controller_Router_Route(':lang/:temp', array('lang' => 'pl'), array('temp' => '\\d+'));
$values = $route->match('en/tmp/ctrl/action/id/1', true);
$this->assertFalse($values);
$route = new Zend_Controller_Router_Route(':lang/:temp', array('lang' => 'pl'));
$values = $route->match('en/tmp/ctrl/action/id/1', true);
$this->assertType('array', $values);
$this->assertEquals('en', $values['lang']);
$this->assertEquals('tmp', $values['temp']);
$this->assertEquals(6, $values[null]);
}
示例13: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$params = array();
$Mvc = new Phorm_Mvc();
// Проверяем существование идентификатора материала в пути
// @todo Сделать возможность конфигурирования паттернов урлов материалов
if (preg_match("#^(/.*?)(/([а-яa-z0-9_-]+)\\.html)?\$#iu", $path, $pathinfo)) {
// Если мы получили идентификатор материала, то устанавливаем CategoriesController
if (isset($pathinfo[3])) {
$params["module"] = "default";
$params["controller"] = "categories";
$params["action"] = "index";
$params["resourceid"] = $pathinfo[3];
$params["categorypath"] = $pathinfo[1] == "/" ? "/" : $pathinfo[1] . "/";
$params["categorypath"] = $pathinfo[1] == "/" ? "/" : $pathinfo[1] . "/";
// Иначе получаем модуль, контроллер и действие из родительского math
} else {
$params = parent::match($path, $partial);
// Проверяем существование MVC-ресурса в базе
if ($params['mvcinfo'] = $Mvc->getMvcInfo($params)) {
$params['WidgetSetId'] = $params['mvcinfo']['widgetssetid'];
//print_r($params);
return $params;
// Если MVC-ресурс не найден, то устанавливаем CategoriesController
} else {
$params["module"] = "default";
$params["controller"] = "categories";
$params["action"] = "index";
$params["categorypath"] = preg_match("#/\$#", $pathinfo[1]) ? $pathinfo[1] : $pathinfo[1] . "/";
}
}
}
// После всех экзекуций у нас должны остаться только ресурсы для CategoriesControllerа
$Categories = new Phorm_Categories();
$Categories->setModule($params["module"]);
// Проверяем существование раздела
if ($CategoryInfo = $Categories->getCategoryInfoByPath($params["categorypath"])) {
$params["categoryinfo"] = $CategoryInfo;
$params["WidgetSetId"] = $CategoryInfo["widgetssetid"];
// Если мы на главной странице раздела и есть материал для замещения, то переопределяем идентификатор материала
if (!isset($params["resourceid"]) && $CategoryInfo["mainresourceid"] > 0) {
$params["resourceid"] = $CategoryInfo["mainresourceid"];
}
// Проверяем существование материала в текущем разделе и модуле по его идентификатору
if (isset($params["resourceid"])) {
$Resource = new Phorm_Resource();
$Resource->setModule($params["module"]);
$options = array("categoryid" => $CategoryInfo["categoryid"], "moduleid" => $CategoryInfo["moduleid"]);
if ($ResourceInfo = $Resource->getResourceInfo($params["resourceid"], $options)) {
$params["module"] = "default";
$params["controller"] = $CategoryInfo["modulecontroller"];
$params["action"] = "view";
$params["resourceinfo"] = $ResourceInfo;
$params["mvcinfo"] = $Mvc->getMvcInfo($params);
$params["WidgetSetId"] = $ResourceInfo["widgetssetid"];
//print_r($params);
return $params;
}
} else {
$params["mvcinfo"] = $Mvc->getMvcInfo($params);
//print_r($params);
return $params;
}
}
// Все, что не смогло вернуться выше, попадает в ErrorController notfoundAction
$params["module"] = "default";
$params["controller"] = "error";
$params["action"] = "notfound";
$params["mvcinfo"] = $Mvc->getMvcInfo($params);
$params["WidgetSetId"] = $params["mvcinfo"]["widgetssetid"];
return $params;
}
示例14: testAssembleWithWildcardUrlVariablesOverwriting
public function testAssembleWithWildcardUrlVariablesOverwriting()
{
$route = new Zend_Controller_Router_Route('archives/:year/:month/*', array('controller' => 'archive'));
$values = $route->match('archives/2006/07/controller/test/year/10000/sort/author');
$this->assertType('array', $values);
$this->assertSame('archive', $values['controller']);
$this->assertSame('2006', $values['year']);
$this->assertSame('07', $values['month']);
$this->assertSame('author', $values['sort']);
}
示例15: match
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path, $partial = false)
{
$path = trim($path, $this->_urlDelimiter);
$pathParts = explode($this->_urlDelimiter, $path, 2);
if (!empty($pathParts[0]) && strlen($pathParts[0]) > 1) {
foreach (self::$_locales as $locale) {
// preventing duplicate urls:
// site.com/uk and site.com/uk_UA - only one will work after next check
if (trim(Axis_Locale::getLanguageUrl($locale), '/') == $pathParts[0]) {
self::$_hasLocaleInUrl = true;
break;
}
}
}
if (self::$_hasLocaleInUrl) {
$path = sizeof($pathParts) > 1 ? $pathParts[1] : '';
$currentLocale = $pathParts[0];
} elseif (isset($this->_defaults['locale'])) {
$currentLocale = $this->_defaults['locale'];
} else {
$currentLocale = self::$_defaultLocale;
}
self::$_currentLocale = $currentLocale;
$params = parent::match($path, $partial);
if ($params) {
Axis_Area::frontend();
$params = array_merge($params, array('locale' => $currentLocale));
}
return $params;
}