当前位置: 首页>>代码示例>>PHP>>正文


PHP Context::getURLhost方法代码示例

本文整理汇总了PHP中thebuggenie\core\framework\Context::getURLhost方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::getURLhost方法的具体用法?PHP Context::getURLhost怎么用?PHP Context::getURLhost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thebuggenie\core\framework\Context的用法示例。


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

示例1: generate

 /**
  * Generate a url based on a route
  *
  * @param string $name The route key
  * @param array $params key=>value pairs of route parameters
  * @param boolean $relative Whether to generate an url relative to web root or an absolute
  *
  * @return string
  */
 public function generate($name, $params = array(), $relative = true, $querydiv = '/', $divider = '/', $equals = '/')
 {
     if (mb_substr($name, 0, 1) == '@') {
         $name = mb_substr($name, 1);
         $details = explode('?', $name);
         $name = array_shift($details);
         if (count($details)) {
             $param_details = array_shift($details);
             $param_details = explode('&', $param_details);
             foreach ($param_details as $detail) {
                 $param_detail = explode('=', $detail);
                 if (count($param_detail) > 1) {
                     $params[$param_detail[0]] = $param_detail[1];
                 }
             }
         }
     }
     if (!isset($this->routes[$name])) {
         Logging::log("The route '{$name}' does not exist", 'routing', Logging::LEVEL_FATAL);
         throw new \Exception("The route '{$name}' does not exist");
     }
     list($url, , $names, $names_hash, $action, $module, , $options, , ) = $this->routes[$name];
     $defaults = array('action' => $action, 'module' => $module);
     $params = self::arrayDeepMerge($defaults, $params);
     if (array_key_exists('csrf_enabled', $options) && $options['csrf_enabled']) {
         $params['csrf_token'] = Context::generateCSRFtoken();
     }
     // all params must be given
     foreach ($names as $tmp) {
         if (!isset($params[$tmp]) && !isset($defaults[$tmp])) {
             throw new \Exception(sprintf('Route named "%s" have a mandatory "%s" parameter', $name, $tmp));
         }
     }
     // in PHP 5.5, preg_replace with /e modifier is deprecated; preg_replace_callback is recommended
     $callback = function ($matches) use($params) {
         return array_key_exists($matches[1], $params) ? urlencode($params[$matches[1]]) : $matches[0];
     };
     $real_url = preg_replace_callback('/\\:([^\\/]+)/', $callback, $url);
     // we add all other params if *
     if (mb_strpos($real_url, '*')) {
         $tmp = array();
         foreach ($params as $key => $value) {
             if (isset($names_hash[$key]) || isset($defaults[$key])) {
                 continue;
             }
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     if (is_array($v)) {
                         foreach ($v as $vk => $vv) {
                             if (is_array($vv)) {
                                 foreach ($vv as $vvk => $vvv) {
                                     $tmp[] = "{$key}[{$k}][{$vk}][{$vvk}]" . $equals . urlencode($vvv);
                                 }
                             } else {
                                 $tmp[] = "{$key}[{$k}][{$vk}]" . $equals . urlencode($vv);
                             }
                         }
                     } else {
                         $tmp[] = "{$key}[{$k}]" . $equals . urlencode($v);
                     }
                 }
             } else {
                 $tmp[] = urlencode($key) . $equals . urlencode($value);
             }
         }
         $tmp = implode($divider, $tmp);
         if (mb_strlen($tmp) > 0) {
             $tmp = $querydiv . $tmp;
         }
         $real_url = preg_replace('/\\/\\*(\\/|$)/', "{$tmp}\$1", $real_url);
     }
     // strip off last divider character
     if (mb_strlen($real_url) > 1) {
         $real_url = rtrim($real_url, $divider);
     }
     if (!$relative) {
         return Context::getURLhost() . Context::getStrippedWebroot() . $real_url;
     }
     return Context::getStrippedWebroot() . $real_url;
 }
开发者ID:RTechSoft,项目名称:thebuggenie,代码行数:89,代码来源:Routing.php

示例2: runDoLogin

 /**
  * Do login (AJAX call)
  *
  * @Route(name="login", url="/do/login")
  * @AnonymousRoute
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runDoLogin(framework\Request $request)
 {
     $i18n = framework\Context::getI18n();
     $options = $request->getParameters();
     $forward_url = framework\Context::getRouting()->generate('home');
     if ($request->hasParameter('persona') && $request['persona'] == 'true') {
         $url = 'https://verifier.login.persona.org/verify';
         $assert = filter_input(INPUT_POST, 'assertion', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
         //Use the $_POST superglobal array for PHP < 5.2 and write your own filter
         $params = 'assertion=' . urlencode($assert) . '&audience=' . urlencode(framework\Context::getURLhost() . ':80');
         $ch = curl_init();
         $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params);
         curl_setopt_array($ch, $options);
         $result = curl_exec($ch);
         curl_close($ch);
         $details = json_decode($result);
         $user = null;
         if ($details->status == 'okay') {
             $user = entities\User::getByEmail($details->email);
             if ($user instanceof entities\User) {
                 framework\Context::getResponse()->setCookie('tbg3_password', $user->getPassword());
                 framework\Context::getResponse()->setCookie('tbg3_username', $user->getUsername());
                 framework\Context::getResponse()->setCookie('tbg3_persona_session', true);
                 $user->setOnline();
                 $user->save();
                 return $this->renderJSON(array('status' => 'login ok', 'redirect' => in_array($request['referer_route'], array('home', 'login'))));
             }
         }
         if (!$user instanceof entities\User) {
             $this->getResponse()->setHttpStatus(401);
             $this->renderJSON(array('message' => $this->getI18n()->__('Invalid login')));
         }
         return;
     }
     if (framework\Settings::isOpenIDavailable()) {
         $openid = new \LightOpenID(framework\Context::getRouting()->generate('login_page', array(), false));
     }
     if (framework\Settings::isOpenIDavailable() && !$openid->mode && $request->isPost() && $request->hasParameter('openid_identifier')) {
         $openid->identity = $request->getRawParameter('openid_identifier');
         $openid->required = array('contact/email');
         $openid->optional = array('namePerson/first', 'namePerson/friendly');
         return $this->forward($openid->authUrl());
     } elseif (framework\Settings::isOpenIDavailable() && $openid->mode == 'cancel') {
         $this->error = framework\Context::getI18n()->__("OpenID authentication cancelled");
     } elseif (framework\Settings::isOpenIDavailable() && $openid->mode) {
         try {
             if ($openid->validate()) {
                 if ($this->getUser()->isAuthenticated() && !$this->getUser()->isGuest()) {
                     if (tables\OpenIdAccounts::getTable()->getUserIDfromIdentity($openid->identity)) {
                         framework\Context::setMessage('openid_used', true);
                         throw new \Exception('OpenID already in use');
                     }
                     $user = $this->getUser();
                 } else {
                     $user = entities\User::getByOpenID($openid->identity);
                 }
                 if ($user instanceof entities\User) {
                     $attributes = $openid->getAttributes();
                     $email = array_key_exists('contact/email', $attributes) ? $attributes['contact/email'] : null;
                     if (!$user->getEmail()) {
                         if (array_key_exists('contact/email', $attributes)) {
                             $user->setEmail($attributes['contact/email']);
                         }
                         if (array_key_exists('namePerson/first', $attributes)) {
                             $user->setRealname($attributes['namePerson/first']);
                         }
                         if (array_key_exists('namePerson/friendly', $attributes)) {
                             $user->setBuddyname($attributes['namePerson/friendly']);
                         }
                         if (!$user->getNickname() || $user->isOpenIdLocked()) {
                             $user->setBuddyname($user->getEmail());
                         }
                         if (!$user->getRealname()) {
                             $user->setRealname($user->getBuddyname());
                         }
                         $user->save();
                     }
                     if (!$user->hasOpenIDIdentity($openid->identity)) {
                         tables\OpenIdAccounts::getTable()->addIdentity($openid->identity, $user->getID());
                     }
                     framework\Context::getResponse()->setCookie('tbg3_password', $user->getPassword());
                     framework\Context::getResponse()->setCookie('tbg3_username', $user->getUsername());
                     $user->setOnline();
                     $user->save();
                     if ($this->checkScopeMembership($user)) {
                         return true;
                     }
                     return $this->forward(framework\Context::getRouting()->generate(framework\Settings::get('returnfromlogin')));
                 } else {
                     $this->error = framework\Context::getI18n()->__("Didn't recognize this OpenID. Please log in using your username and password, associate it with your user account in your account settings and try again.");
                 }
             } else {
//.........这里部分代码省略.........
开发者ID:nrensen,项目名称:thebuggenie,代码行数:101,代码来源:Main.php


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