本文整理汇总了PHP中Symfony\Component\Routing\Route::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getDefault方法的具体用法?PHP Route::getDefault怎么用?PHP Route::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTitle
/**
* {@inheritdoc}
*/
public function getTitle(Request $request, Route $route)
{
$route_title = NULL;
// A dynamic title takes priority. Route::getDefault() returns NULL if the
// named default is not set. By testing the value directly, we also avoid
// trying to use empty values.
if ($callback = $route->getDefault('_title_callback')) {
$callable = $this->controllerResolver->getControllerFromDefinition($callback);
$arguments = $this->controllerResolver->getArguments($request, $callable);
$route_title = call_user_func_array($callable, $arguments);
} elseif ($title = $route->getDefault('_title')) {
$options = array();
if ($context = $route->getDefault('_title_context')) {
$options['context'] = $context;
}
$args = array();
if ($raw_parameters = $request->attributes->get('_raw_variables')) {
foreach ($raw_parameters->all() as $key => $value) {
$args['@' . $key] = $value;
$args['%' . $key] = $value;
}
}
if ($title_arguments = $route->getDefault('_title_arguments')) {
$args = array_merge($args, (array) $title_arguments);
}
// Fall back to a static string from the route.
$route_title = $this->t($title, $args, $options);
}
return $route_title;
}
示例2: buildForPreprocessor
public function buildForPreprocessor(Request $request, Route $preprocessorRoute)
{
// NO RabbitMQ case here: preprocessor are called synchronously.
// Localhost case
if ($preprocessorRoute->getDefault('_http_host') === $request->getHttpHost()) {
$this->logger->info("InternalForwarder built for preprocessor: Localhost forwarder.", ['host' => $request->getHttpHost()]);
return $this->container->get('prestashop.public_writer.protocol.internal_forwarder.localhost');
}
// HTTP forward case
if ($this->container->has('prestashop.saas.protocol.internal_forwarder.http')) {
$this->logger->info("InternalForwarder built for forward: HTTP forwarder.", ['host' => $preprocessorRoute->getDefault('_http_host')]);
return $this->container->get('prestashop.saas.protocol.internal_forwarder.http');
}
// Error case: localhost case was not matching, but there is no other forwarder available.
$this->logger->error("InternalForwarder built for preprocessor: NO forwarder found to reach distant host.", ['host' => $request->getHttpHost()]);
throw new \ErrorException("InternalForwarder building for preprocessor: NO forwarder found to reach distant host: " . $request->getHttpHost());
}
示例3: checkForRole
/**
* @param Route $route
* @param UserVO $user
* @throws MethodNotAllowedException
*/
protected function checkForRole(Route $route, UserVO $user)
{
if ($route->hasDefault('_role')) {
$role = $route->getDefault('_role');
if (!in_array($role, $user->roles)) {
throw new MethodNotAllowedException([], sprintf('Need role %s', $role));
}
}
}
示例4: access
/**
* Checks new registrations are permitted on an event.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, RegistrationTypeInterface $registration_type = NULL)
{
if ($event = $route->getDefault('event')) {
$context = ['event' => $route_match->getParameter($event)];
$access_control_handler = $this->entityManager->getAccessControlHandler('registration');
return $access_control_handler->createAccess($registration_type, $account, $context, TRUE);
}
return AccessResult::forbidden();
}
示例5: convertController
private function convertController(Route $route)
{
$nameParser = $this->getContainer()->get('controller_name_converter');
if ($route->hasDefault('_controller')) {
try {
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
} catch (\InvalidArgumentException $e) {
}
}
}
示例6: access
/**
* Checks that an entity is an event type.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
{
if ($event = $route->getDefault('event')) {
$event = $route_match->getParameter($event);
if ($event instanceof EntityInterface) {
return AccessResult::allowedIf($this->eventManager->isEvent($event));
}
}
return AccessResult::neutral();
}
示例7: access
/**
* Checks access to the overview based on permissions and translatability.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, AccountInterface $account)
{
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($route->getDefault('plugin_id'));
$this->sourceLanguage = $this->languageManager->getLanguage($mapper->getLangcode());
// Allow access to the translation overview if the proper permission is
// granted, the configuration has translatable pieces, and the source
// language is not locked if it is present.
$source_language_access = is_null($this->sourceLanguage) || !$this->sourceLanguage->isLocked();
$access = $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && $source_language_access;
return AccessResult::allowedIf($access)->cachePerRole();
}
示例8: access
public function access(Route $route, RouteMatch $match, AccountInterface $account)
{
$tempstore_id = $route->getDefault('tempstore_id');
$id = $match->getParameter($route->getRequirement('_ctools_access'));
if ($tempstore_id && $id) {
$cached_values = $this->getTempstore()->get($tempstore_id)->get($id);
if (!empty($cached_values['access']) && $cached_values['access'] instanceof CToolsAccessInterface) {
return $cached_values['access']->access($account);
}
}
return AccessResult::forbidden();
}
示例9: access
/**
* Checks access to the overview based on permissions and translatability.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return string
* A \Drupal\Core\Access\AccessInterface constant value.
*/
public function access(Route $route, Request $request, AccountInterface $account)
{
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($route->getDefault('plugin_id'));
$mapper->populateFromRequest($request);
$this->sourceLanguage = $mapper->getLanguageWithFallback();
// Allow access to the translation overview if the proper permission is
// granted, the configuration has translatable pieces, and the source
// language is not locked.
$access = $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && !$this->sourceLanguage->locked;
return $access ? static::ALLOW : static::DENY;
}
示例10: isEditFormPage
/**
* Determines if a given route is the edit-form for an entity.
*
* @param \Symfony\Component\Routing\Route $route
* The route definition.
*
* @return bool
* Returns TRUE if the route is the edit form of an entity, FALSE otherwise.
*/
protected function isEditFormPage(Route $route)
{
if ($default = $route->getDefault('_entity_form')) {
// If no operation is provided, use 'default'.
$default .= '.default';
list($entity_type_id, $operation) = explode('.', $default);
if (!$this->entityManager->hasDefinition($entity_type_id)) {
return FALSE;
}
$entity_type = $this->entityManager->getDefinition($entity_type_id);
return $operation == 'edit' && $entity_type && $entity_type->isRevisionable();
}
}
示例11: generateI18nPatterns
/**
* {@inheritDoc}
*/
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = array();
foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) {
// Check if translation exists in the translation catalogue to avoid errors being logged by
// the new LoggingTranslator of Symfony 2.6. However, the LoggingTranslator did not implement
// the interface until Symfony 2.6.5, so an extra check is needed.
if ($this->translator instanceof TranslatorBagInterface || $this->translator instanceof LoggingTranslator) {
// Check if route is translated.
if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) {
// No translation found.
$i18nPattern = $route->getPath();
} else {
// Get translation.
$i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale);
}
} else {
// if no translation exists, we use the current pattern
if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) {
$i18nPattern = $route->getPath();
}
}
///////////////////////////////////////
// Begin customizations
// prefix with zikula module url if requested
if ($route->hasDefault('_zkModule')) {
$module = $route->getDefault('_zkModule');
$zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix');
if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) {
$untranslatedPrefix = $this->getModUrlString($module);
if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($module))) {
$prefix = $this->translator->trans($untranslatedPrefix, [], strtolower($module), $locale);
} else {
$prefix = $untranslatedPrefix;
}
$i18nPattern = "/" . $prefix . $i18nPattern;
}
}
// End customizations
///////////////////////////////////////
// prefix with locale if requested
if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) {
$i18nPattern = '/' . $locale . $i18nPattern;
if (null !== $route->getOption('i18n_prefix')) {
$i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern;
}
}
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例12: processRoute
private function processRoute(Route $importedRoute, $serviceName, $controllerClass)
{
$controllerName = $importedRoute->getDefault('_controller');
if ($this->containsClassNameNotServiceName($controllerName)) {
// service has already been assigned to this controller -> skip
return;
}
$controllerClassLength = strlen($controllerClass);
$controllerClassFromName = substr($controllerName, 0, $controllerClassLength);
if ($controllerClassFromName !== $controllerClass) {
throw new \InvalidArgumentException('Something is wrong with controller class: ' . $controllerClass);
}
$importedRoute->setDefault('_controller', $this->getServiceControllerName($serviceName, $controllerName, $controllerClassLength));
}
示例13: getNameFromController
/**
* @param Route $route
*
* @return string
*/
protected function getNameFromController(Route $route)
{
$result = $route->getDefault('_controller');
if (!empty($result)) {
if (false !== ($pos = strpos($result, 'Controller::'))) {
$result = substr($result, 0, $pos);
}
if (false !== ($pos = strrpos($result, '\\'))) {
$result = substr($result, $pos + 1);
}
$result = strtolower($result);
}
return $result;
}
示例14: isGranted
public function isGranted(Route $route, User $user)
{
if ($Ctrl = $route->getDefault('_controller')) {
$Ctrl = str_replace(array('Bundle', 'Controller', 'Action'), '', $Ctrl);
list(, $Bundle, , $C) = explode("\\", strtolower($Ctrl));
list($Controller, $Action) = explode("::", $C);
}
foreach ($user->getRoles() as $Role) {
if ($Role->isGranted($Bundle, $Controller, $Action) === TRUE) {
return TRUE;
}
}
return FALSE;
}
示例15: handle
/**
* {@inheritdoc}
*/
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
{
if ($route->getOption('group') !== DictionaryEntityRouteOptionsResolver::ROUTE_GROUP) {
return;
}
$pluralAlias = $route->getDefault(DictionaryEntityRouteOptionsResolver::ENTITY_ATTRIBUTE);
if (!$pluralAlias) {
return;
}
$className = $this->entityAliasResolver->getClassByPluralAlias($pluralAlias);
$pluralName = $this->entityClassNameProvider->getEntityClassPluralName($className);
if ($pluralName) {
$annotation->setDescription(strtr(static::DESCRIPTION_TEMPLATE, ['{plural_name}' => $pluralName]));
$annotation->setDocumentation(strtr(static::DOCUMENTATION_TEMPLATE, ['{plural_name}' => $pluralName]));
} else {
$annotation->setDescription(strtr(static::FALLBACK_DESCRIPTION_TEMPLATE, ['{class}' => $className]));
$annotation->setDocumentation(strtr(static::FALLBACK_DOCUMENTATION_TEMPLATE, ['{class}' => $className]));
}
}