• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utility\UrlHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Drupal\Component\Utility\UrlHelper的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper类的具体用法?PHP UrlHelper怎么用?PHP UrlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UrlHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Validate video URL.
     if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
         $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
     }
 }
开发者ID:shawnmmatthews,项目名称:gerber8,代码行数:10,代码来源:ContributeForm.php


示例2: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         $url_is_valid = TRUE;
         /** @var $link_item \Drupal\link\LinkItemInterface */
         $link_item = $value;
         $link_type = $link_item->getFieldDefinition()->getSetting('link_type');
         $url_string = $link_item->url;
         // Validate the url property.
         if ($url_string !== '') {
             try {
                 // @todo This shouldn't be needed, but massageFormValues() may not
                 //   run.
                 $parsed_url = UrlHelper::parse($url_string);
                 $url = Url::createFromPath($parsed_url['path']);
                 if ($url->isExternal() && !UrlHelper::isValid($url_string, TRUE)) {
                     $url_is_valid = FALSE;
                 } elseif ($url->isExternal() && !($link_type & LinkItemInterface::LINK_EXTERNAL)) {
                     $url_is_valid = FALSE;
                 }
             } catch (NotFoundHttpException $e) {
                 $url_is_valid = FALSE;
             } catch (MatchingRouteNotFoundException $e) {
                 $url_is_valid = FALSE;
             } catch (ParamNotConvertedException $e) {
                 $url_is_valid = FALSE;
             }
         }
         if (!$url_is_valid) {
             $this->context->addViolation($this->message, array('%url' => $url_string));
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:36,代码来源:LinkTypeConstraint.php


示例3: blockValidate

 /**
  * {@inheritdoc}
  */
 public function blockValidate($form, FormStateInterface $form_state)
 {
     // Instantiate UrlHelper object to validate the URL's.
     $url_helper = new UrlHelper();
     // Build an array of the links that need validating. If more fields are
     // added later, add another entry to the links array.
     $links = [];
     $links['pantheon_url'] = $form_state->getValue('pantheon_url');
     // Create an error variable to prevent setting the error message repeatedly.
     $error_set = FALSE;
     // Validate and set errors where appropriate.
     foreach ($links as $key => $link) {
         if ($link == '') {
             break;
         }
         $validity = $url_helper->isValid($link, TRUE);
         if ($validity != TRUE) {
             $form_state->setErrorByName($key, "The value must be a full URL similar to http://www.example.com.");
             // Using drupal_set_message because of a bug with setError that is
             // causing the form to not submit correctly, but isn't displaying
             // messages.
             if ($error_set == FALSE) {
                 drupal_set_message('All values must be full URLs of format: http://www.example.com.', 'error');
                 // Prevent the error from outputting multiple times.
                 $error_set = TRUE;
             }
         }
     }
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:32,代码来源:PantheonLinkBlock.php


示例4: execute

 /**
  * {@inheritdoc}
  */
 public function execute($object = NULL)
 {
     $url = $this->configuration['url'];
     // Leave external URLs unchanged, and assemble others as absolute URLs
     // relative to the site's base URL.
     if (!UrlHelper::isExternal($url)) {
         $parts = UrlHelper::parse($url);
         // @todo '<front>' is valid input for BC reasons, may be removed by
         //   https://www.drupal.org/node/2421941
         if ($parts['path'] === '<front>') {
             $parts['path'] = '';
         }
         $uri = 'base:' . $parts['path'];
         $options = ['query' => $parts['query'], 'fragment' => $parts['fragment'], 'absolute' => TRUE];
         // Treat this as if it's user input of a path relative to the site's
         // base URL.
         $url = $this->unroutedUrlAssembler->assemble($uri, $options);
     }
     $response = new RedirectResponse($url);
     $listener = function ($event) use($response) {
         $event->setResponse($response);
     };
     // Add the listener to the event dispatcher.
     $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:GotoAction.php


示例5: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $values['uri'] = trim($values['uri']);
     if (!UrlHelper::isValid($values['uri'], TRUE)) {
         $values['uri'] = '';
     }
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:10,代码来源:Link.php


示例6: isValid

 /**
  * {@inheritdoc}
  */
 public function isValid($path)
 {
     // External URLs and the front page are always valid.
     if ($path == '<front>' || UrlHelper::isExternal($path)) {
         return TRUE;
     }
     // Check the routing system.
     $collection = $this->routeProvider->getRoutesByPattern('/' . $path);
     if ($collection->count() == 0) {
         return FALSE;
     }
     $request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), '/' . $path);
     $request->attributes->set('_system_path', $path);
     // We indicate that a menu administrator is running the menu access check.
     $request->attributes->set('_menu_admin', TRUE);
     // Attempt to match this path to provide a fully built request to the
     // access checker.
     try {
         $request->attributes->add($this->requestMatcher->matchRequest($request));
     } catch (ParamNotConvertedException $e) {
         return FALSE;
     }
     // Consult the access manager.
     $routes = $collection->all();
     $route = reset($routes);
     return $this->accessManager->check($route, $request, $this->account);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:PathValidator.php


示例7: validateValue

 /**
  * {@inheritdoc}
  */
 public static function validateValue(array &$element, FormStateInterface $form_state, array $form)
 {
     if (!empty($element['#value'])) {
         if (!UrlHelper::isValid($element['#value'], TRUE)) {
             $form_state->setError($element, t('The entered Tumblr URI is not valid.'));
         }
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:11,代码来源:Tumblr.php


示例8: createUrlFromString

  /**
   * @param $url
   *
   * @see FillPdfLinkManipulatorInterface::parseUrlString()
   *
   * @return \Drupal\Core\Url
   */
  protected function createUrlFromString($url) {
    $url_parts = UrlHelper::parse($url);
    $path = $url_parts['path'];
    $query = $url_parts['query'];

    $link = Url::fromUri($path, ['query' => $query]);
    return $link;
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:15,代码来源:FillPdfLinkManipulator.php


示例9: validateUrl

 /**
  * Form element validation handler for #type 'url'.
  *
  * Note that #maxlength and #required is validated by _form_validate() already.
  */
 public static function validateUrl(&$element, FormStateInterface $form_state, &$complete_form)
 {
     $value = trim($element['#value']);
     $form_state->setValueForElement($element, $value);
     if ($value !== '' && !UrlHelper::isValid($value, TRUE)) {
         $form_state->setError($element, t('The URL %url is not valid.', array('%url' => $value)));
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:13,代码来源:Url.php


示例10: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (strlen($form_state->getValue('title')) < 3) {
         $form_state->setErrorByName('title', $this->t('Your name is too short.'));
     }
     if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
         $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
     }
 }
开发者ID:krabhay,项目名称:Learning-Drupal-8,代码行数:9,代码来源:ContributeForm.php


示例11: __construct

 /**
  * Constructs a new generator object.
  *
  * @param \Drupal\Core\Routing\RouteProviderInterface $provider
  *   The route provider to be searched for routes.
  * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor
  *   The path processor to convert the system path to one suitable for urls.
  * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $route_processor
  *   The route processor.
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   A request stack object.
  * @param string[] $filter_protocols
  *   (optional) An array of protocols allowed for URL generation.
  */
 public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, RequestStack $request_stack, array $filter_protocols = ['http', 'https'])
 {
     $this->provider = $provider;
     $this->context = new RequestContext();
     $this->pathProcessor = $path_processor;
     $this->routeProcessor = $route_processor;
     UrlHelper::setAllowedProtocols($filter_protocols);
     $this->requestStack = $request_stack;
 }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:23,代码来源:UrlGenerator.php


示例12: setEmbedProvider

 /**
  * {@inheritdoc}
  */
 public function setEmbedProvider($provider)
 {
     $provider_parsed = UrlHelper::parse($provider);
     $provider_parsed['query'] = array_filter($provider_parsed['query'], function ($value) {
         return $value !== '{callback}';
     });
     $provider_parsed['absolute'] = TRUE;
     $this->embed_provider = $this->urlAssembler->assemble($provider_parsed['path'], $provider_parsed);
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:12,代码来源:Embed.php


示例13: testHandleWithGetRequest

 /**
  * Tests onHandleException with a GET request.
  */
 public function testHandleWithGetRequest()
 {
     $request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
     $this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
     }));
     $event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new \Exception('foo'));
     $this->exceptionListener->onKernelException($event);
     $response = $event->getResponse();
     $this->assertEquals('GET name=druplicon&pass=12345 ', $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:ExceptionListenerTest.php


示例14: testBadProtocolStripping

 /**
  * Checks that harmful protocols are stripped.
  */
 function testBadProtocolStripping()
 {
     // Ensure that check_url() strips out harmful protocols, and encodes for
     // HTML.
     // Ensure \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() can
     // be used to return a plain-text string stripped of harmful protocols.
     $url = 'javascript:http://www.example.com/?x=1&y=2';
     $expected_plain = 'http://www.example.com/?x=1&y=2';
     $expected_html = 'http://www.example.com/?x=1&amp;y=2';
     $this->assertIdentical(check_url($url), $expected_html, 'check_url() filters a URL and encodes it for HTML.');
     $this->assertIdentical(UrlHelper::stripDangerousProtocols($url), $expected_plain, '\\Drupal\\Component\\Utility\\Url::stripDangerousProtocols() filters a URL and returns plain text.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:15,代码来源:XssUnitTest.php


示例15: render

 /**
  * Response for the xmlsitemap_engines_test.ping route.
  *
  * @throws NotFoundHttpException
  *   Throw a NotFoundHttpException if query url is not valid.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A response with 200 code if the url query is valid.
  */
 public function render()
 {
     $query = \Drupal::request()->query->get('sitemap');
     if (empty($query) || !UrlHelper::isValid($query)) {
         watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING);
         // @todo Remove this? Causes an extra watchdog error to be handled.
         throw new NotFoundHttpException();
     } else {
         watchdog('xmlsitemap', 'Recieved ping for @sitemap.', array('@sitemap' => $query));
     }
     return new Response('', 200);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:21,代码来源:XmlSitemapEnginesTestController.php


示例16: buildCancelLink

 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         // @todo Revisit this in https://www.drupal.org/node/2418219.
         $url = Url::fromUserInput('/' . $options['path'], $options);
     } else {
         $url = $form->getCancelUrl();
     }
     return ['#type' => 'link', '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button']], '#url' => $url];
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:25,代码来源:ConfirmFormHelper.php


示例17: getNextDestination

 /**
  * Returns the next redirect path in a multipage sequence.
  *
  * @param array $destinations
  *   An array of destinations to redirect to.
  *
  * @return array
  *   The next destination to redirect to.
  */
 public static function getNextDestination(array $destinations)
 {
     $next_destination = array_shift($destinations);
     if (is_array($next_destination)) {
         $next_destination['options']['query']['destinations'] = $destinations;
     } else {
         $options = UrlHelper::parse($next_destination);
         if ($destinations) {
             $options['query']['destinations'] = $destinations;
         }
         $next_destination = array($options['path'], $options);
     }
     return $next_destination;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:23,代码来源:FieldUI.php


示例18: get

 /**
  * {@inheritdoc}
  */
 public function get()
 {
     if (!isset($this->destination)) {
         $query = $this->requestStack->getCurrentRequest()->query;
         if (UrlHelper::isExternal($query->get('destination'))) {
             $this->destination = '/';
         } elseif ($query->has('destination')) {
             $this->destination = $query->get('destination');
         } else {
             $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()))]);
         }
     }
     return $this->destination;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:RedirectDestination.php


示例19: buildCancelLink

 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         $link = array('#href' => $options['path'], '#options' => $options);
     } elseif ($route = $form->getCancelRoute()) {
         $link = $route->toRenderArray();
     }
     $link['#type'] = 'link';
     $link['#title'] = $form->getCancelText();
     return $link;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:26,代码来源:ConfirmFormHelper.php


示例20: buildCancelLink

 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         // @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
         //   resolved.
         $url = Url::fromUri('base://' . $options['path'], $options);
     } else {
         $url = $form->getCancelUrl();
     }
     return ['#type' => 'link', '#title' => $form->getCancelText(), '#url' => $url];
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:ConfirmFormHelper.php



注:本文中的Drupal\Component\Utility\UrlHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utility\Xss类代码示例发布时间:2022-05-23
下一篇:
PHP Utility\Unicode类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap