本文整理汇总了PHP中Symfony\Component\Routing\Route::addRequirements方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::addRequirements方法的具体用法?PHP Route::addRequirements怎么用?PHP Route::addRequirements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::addRequirements方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load($resource, $type = null)
{
if (true === $this->loaded) {
throw new \RuntimeException('Do not add this loader twice');
}
$routes = new RouteCollection();
$contextConfigLoader = $this->contextConfigLoader;
foreach ($contextConfigLoader->getRouting() as $routing) {
foreach ($routing as $id => $info) {
if (array_key_exists('pattern', $info)) {
$route = new Route($info['pattern']);
// merge options and defaults
if (array_key_exists('defaults', $info)) {
$route->addDefaults($info['defaults']);
}
if (array_key_exists('options', $info)) {
$route->addOptions($info['options']);
}
if (array_key_exists('requirements', $info)) {
$route->addRequirements($info['requirements']);
}
}
$routes->add($id, $route);
}
}
return $routes;
}
示例2: getRevisionRevertRoute
/**
* Gets the entity revision revert route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionRevertRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('revision-revert-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('revision-revert-form'));
$route->addDefaults(['_form' => '\\Drupal\\entity\\Form\\RevisionRevertForm', 'title' => 'Revert to earlier revision']);
$route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.update"]);
$route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
return $route;
}
}
示例3: getRevisionViewRoute
/**
* Gets the entity revision view route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionViewRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('revision')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('revision'));
$route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionController::view', '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title']);
$route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.view"]);
$route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
return $route;
}
}
示例4: route
/**
* Add an endpiont/application to the server
* @param string $path The URI the client will connect to
* @param ComponentInterface $controller Your application to server for the route. If not specified, assumed to be for a WebSocket
* @param array $allowedOrigins An array of hosts allowed to connect (same host by default), ['*'] for any
* @param string $httpHost Override the $httpHost variable provided in the __construct
* @return ComponentInterface|WsServer
*/
public function route($path, ComponentInterface $controller, array $allowedOrigins = array(), $httpHost = null)
{
if ($controller instanceof HttpServerInterface || $controller instanceof WsServer) {
$decorated = $controller;
} elseif ($controller instanceof WampServerInterface) {
$decorated = new WsServer(new WampServer($controller));
} elseif ($controller instanceof MessageComponentInterface) {
$decorated = new WsServer($controller);
} else {
$decorated = $controller;
}
if ($httpHost === null) {
$httpHost = $this->httpHost;
}
$allowedOrigins = array_values($allowedOrigins);
if (0 === count($allowedOrigins)) {
$allowedOrigins[] = $httpHost;
}
if ('*' !== $allowedOrigins[0]) {
$decorated = new OriginCheck($decorated, $allowedOrigins);
}
$route = null;
if ($path instanceof Route) {
$route = $path;
$route->setDefault('_controller', $decorated);
} else {
$route = new Route($path, array('_controller' => $decorated));
}
if ('*' !== $httpHost) {
$route->addRequirements(array('Origin' => $httpHost));
$route->setHost($httpHost);
}
$this->routes->add('rr-' . ++$this->_routeCounter, $route);
return $decorated;
}
示例5: processRoute
/**
* {@inheritdoc}
*/
public function processRoute(Route $route)
{
$route->addRequirements(array('_access' => 'TRUE'));
}
示例6: addLocaleToRoute
/**
* Adds the locale to the route if prepend_locale is enabled.
*
* @param Route $route The route
*/
private function addLocaleToRoute(Route $route)
{
if ($this->prependLocale) {
$route->setPath('/{_locale}' . $route->getPath());
$route->addRequirements(['_locale' => '[a-z]{2}(\\-[A-Z]{2})?']);
} else {
$route->addDefaults(['_locale' => null]);
}
}
示例7: addRequirements
/**
* Adds requirements.
*
* This method implements a fluent interface.
*
* @param array $requirements The requirements
*
* @return Route The current Route instance
*/
public function addRequirements(array $requirements)
{
parent::addRequirements($requirements);
$this->_addHeaderRequirements();
return $this;
}