本文整理汇总了PHP中Symfony\Component\Routing\RouterInterface::match方法的典型用法代码示例。如果您正苦于以下问题:PHP RouterInterface::match方法的具体用法?PHP RouterInterface::match怎么用?PHP RouterInterface::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RouterInterface
的用法示例。
在下文中一共展示了RouterInterface::match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getActionForCurrentController
public function getActionForCurrentController(string $action) : string
{
$currentPath = $this->getRouterRequestContext()->getPathInfo();
$currentRoute = $this->router->match($currentPath);
list($mode, $controller) = explode('.', $currentRoute['_route'], 3);
$route = sprintf('%s.%s.%s', $mode, $controller, $action);
return $route;
}
示例2: getRefererParams
private function getRefererParams(Request $request)
{
$referer = $request->headers->get('referer');
$matchBasePath = $this->router->match('');
$baseUrl = $this->router->generate($matchBasePath['_route'], [], true);
$lastPath = substr($referer, strpos($referer, $baseUrl) + strlen($baseUrl));
return $this->router->match('/' . $lastPath);
}
示例3: getPathInfoFromMetaTagKey
/**
* @param $key
*
* @return array An array of parameters
*/
public function getPathInfoFromMetaTagKey($key)
{
$info = $this->keyGenerator->generatePathInfoFromMetaTagKey($key);
$this->router->getContext()->setMethod('GET');
if ($this->keyGenerator->isAddQueryString()) {
$info = substr($info, 0, strpos($info, '?'));
$match = $this->router->match($info);
return $match;
} else {
return $this->router->match($info);
}
}
示例4: getItemFromIri
/**
* {@inheritdoc}
*/
public function getItemFromIri($iri, $fetchData = false)
{
try {
$parameters = $this->router->match($iri);
} catch (ResourceNotFoundException $e) {
return;
}
if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
throw new \InvalidArgumentException(sprintf('No resource associated with the IRI "%s".', $iri));
}
return $this->dataProvider->getItem($resource, $parameters['id'], $fetchData);
}
示例5: match
public function match($pathInfo)
{
$baseContext = $this->router->getContext();
$request = Request::create($pathInfo);
$context = (new RequestContext())->fromRequest($request);
$context->setPathInfo($pathInfo);
try {
$this->router->setContext($context);
return $this->router->match($request->getPathInfo());
} finally {
$this->router->setContext($baseContext);
}
}
示例6: reverseTransform
/**
* @param string $value
*
* @return NodeTranslation|null
*/
public function reverseTransform($value)
{
if ("" === $value || null === $value) {
return null;
}
try {
$route = $this->router->match($value);
if (false === isset($route['_nodeTranslation']) || false === $route['_nodeTranslation'] instanceof NodeTranslation) {
throw new TransformationFailedException('Matched route has no nodeTranslation');
}
return $route['_nodeTranslation'];
} catch (RouteNotFoundException $e) {
throw new TransformationFailedException('Cannot match URL to a nodeTranslation', 0, $e);
}
}
示例7: getItemFromIri
/**
* {@inheritdoc}
*/
public function getItemFromIri($iri, $fetchData = false)
{
try {
$parameters = $this->router->match($iri);
} catch (ExceptionInterface $e) {
throw new InvalidArgumentException(sprintf('No route matches "%s".', $iri), $e->getCode(), $e);
}
if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
}
if ($item = $this->dataProvider->getItem($resource, $parameters['id'], $fetchData)) {
return $item;
}
throw new InvalidArgumentException(sprintf('Item not found for "%s".', $iri));
}
示例8: findResourceInformationFromRouter
/**
* @param $path
* @return array|null
*/
private function findResourceInformationFromRouter($path)
{
// store and reset the request method
$requestMethod = $this->getRequestMethod();
$this->setRequestMethod(Request::METHOD_GET);
try {
$parameters = $this->router->match($path);
$this->setRequestMethod($requestMethod);
} catch (ResourceNotFoundException $e) {
$this->setRequestMethod($requestMethod);
return null;
} catch (MethodNotAllowedException $e) {
$this->setRequestMethod($requestMethod);
return null;
}
if (!isset($parameters['_route'])) {
return null;
}
$route = $this->router->getRouteCollection()->get($parameters['_route']);
if (null === $route) {
return null;
}
if (!$route->hasOption(self::RESOURCE_ENTITY_CLASS_OPTION) || !$route->hasOption(self::RESOURCE_ENTITY_ID_OPTION)) {
return null;
}
if (!isset($parameters[$route->getOption(self::RESOURCE_ENTITY_ID_OPTION)])) {
return null;
}
$converter = $this->defaultConverter;
if ($route->hasOption(self::RESOURCE_CONVERTER_OPTION)) {
$converter = $route->getOption(self::RESOURCE_CONVERTER_OPTION);
}
return [$route->getOption(self::RESOURCE_ENTITY_CLASS_OPTION), $parameters[$route->getOption(self::RESOURCE_ENTITY_ID_OPTION)], $converter];
}
示例9: canonical
public function canonical($pathinfo, $uri = null)
{
if ($uri) {
if (!$this->keyGenerator->isAddQueryString()) {
//remove query string
if ($pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
}
//remove if rewrite not used
$uri = str_replace('app_dev.php/', '', $uri);
$uri = str_replace('app.php/', '', $uri);
return $uri;
}
try {
$infos = $this->router->match($pathinfo);
} catch (ResourceNotFoundException $e) {
$infos = false;
} catch (MethodNotAllowedException $e) {
$infos = false;
}
if ($infos === false) {
return;
}
if (strpos($infos['_route'], RouteLoader::ROUTE_BEGIN) === 0) {
$infos = RouteLoader::getPathinfo($infos['_route']);
}
$route = $infos['_route'];
unset($infos['_route']);
unset($infos['_controller']);
return $this->router->generate($route, $infos, true);
}
示例10: action
public function action(RouterInterface $router, RequestContext $context)
{
$request = Request::createFromGlobals();
$bPath = $context->getPathInfo();
try {
$parameters = $router->match($bPath);
var_dump($parameters);
$_controller = $parameters["_controller"];
$_controller = explode(":", $_controller);
$class = $_controller[0];
$action = strtolower($_controller[1]) . "Action";
$class = new $class();
ob_start();
if (method_exists($class, $action)) {
$class->{$action}($request, new JsonResponse());
$response = new Response(ob_get_clean());
} else {
$response = new Response('Not Found', 404);
}
} catch (ResourceNotFoundException $e) {
$response = new Response('Not Found', 404);
} catch (Exception $e) {
$response = new Response('An error occurred', 500);
}
$response->send();
}
示例11: addRootRelations
public function addRootRelations(Root $root, ClassMetadataInterface $classMetadata)
{
$prefix = $root->getPrefix();
$relations = array();
$self_args = $this->router->match($root->getPrefix());
$relations[] = new Hateoas\Relation('self', new Hateoas\Route($self_args['_route'], array(), false));
foreach ($root->getEntityNames() as $rel => $entityName) {
/** @var ClassMetadata $metadata */
$metadata = $this->entityManager->getMetadataFactory()->getMetadataFor($entityName);
$routeName = $this->routeResolver->resolveRouteName($metadata->getName(), 'cgetAction');
if ($routeName) {
$arguments = array();
foreach (self::$COLLECTION_ARGUMENTS as $argument) {
$arguments[$argument] = '{' . $argument . '}';
}
$relations[] = new Hateoas\Relation(Inflector::pluralize($rel), new Hateoas\Route($routeName, $arguments, false));
}
$routeName = $this->routeResolver->resolveRouteName($metadata->getName(), 'getAction');
if ($routeName) {
$relations[] = new Hateoas\Relation($rel, new Hateoas\Route($routeName, array('id' => "{id}"), false));
}
$routeName = $self_args['_route'] . '_schema';
if ($this->router->getRouteCollection()->get($routeName)) {
$relations[] = new Hateoas\Relation('schema:' . $rel, new Hateoas\Route($routeName, array('rel' => $rel), false));
}
}
$user = $root->getCurrentUser();
if ($user instanceof User) {
$routeName = $this->routeResolver->resolveRouteName(get_class($user), 'getAction');
if ($routeName) {
$relations[] = new Hateoas\Relation('currentUser', new Hateoas\Route($routeName, array('id' => $user->getId()), false));
}
}
return $relations;
}
示例12: getCurrentRoute
public function getCurrentRoute()
{
try {
return $this->router->match($this->router->getPathInfo());
} catch (\Exception $e) {
return array('_route' => null, '_locale' => $this->getLocale());
}
}
示例13: validate
public function validate($value, Constraint $constraint)
{
if (!preg_match('#^/[/a-z0-9-_%]*#', $value->getStaticPrefix())) {
$this->context->buildViolation($constraint->urlValidation)->setParameter('%string%', $value->getStaticPrefix())->addViolation();
}
$isUnique = true;
try {
$route = $this->router->match($value->getStaticPrefix());
if ($value->getName() && $value->getName() != $route['_route']) {
$isUnique = false;
}
} catch (ResourceNotFoundException $e) {
}
if (!$isUnique) {
$this->context->buildViolation($constraint->uniqueUrlMessage)->setParameter('%string%', $value->getStaticPrefix())->addViolation();
}
}
示例14: getCssIfMatchRoute
/**
* @param string|bool $check
* @param string $css
*
* @return null|string
*/
public function getCssIfMatchRoute($check, $css = 'active')
{
if (is_string($check)) {
$matcher = $this->router->match($this->request->getCurrentRequest()->getPathInfo());
$check = $matcher['_route'] === $check;
}
return $check ? $css : null;
}
示例15: getRouteInfoByUri
/**
* Get route info by uri
*
* @param string $uri
* @return null|string
*/
protected function getRouteInfoByUri($uri)
{
try {
$routeInfo = $this->router->match($uri);
return $routeInfo[self::ROUTE_CONTROLLER_KEY];
} catch (ResourceNotFoundException $e) {
}
return null;
}