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


PHP AgaviToolkit::stringBase方法代码示例

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


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

示例1: testStringBase

 public function testStringBase()
 {
     $amount = 0;
     $this->assertEquals("string", AgaviToolkit::stringBase("stringbase", "stringother"));
     $this->assertEquals("string", AgaviToolkit::stringBase("stringbase", "stringother", $amount));
     $this->assertEquals(6, $amount);
     $this->assertEquals("hu", AgaviToolkit::stringBase("hurray", "hungry"));
     $this->assertEquals(NULL, AgaviToolkit::stringBase("astringbase", "stringother"));
 }
开发者ID:horros,项目名称:agavi,代码行数:9,代码来源:AgaviToolkitTest.php

示例2: initialize

 /**
  * Initialize the routing instance.
  *
  * @param      AgaviContext The Context.
  * @param      array        An array of initialization parameters.
  *
  * @author     David Zülke <dz@bitxtender.com>
  * @author     Veikko Mäkinen <veikko@veikkomakinen.com>
  * @author     Dominik del Bondio <ddb@bitxtender.com>
  * @since      0.11.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     parent::initialize($context, $parameters);
     $rq = $this->context->getRequest();
     $rd = $rq->getRequestData();
     // 'scheme://authority' is necessary so parse_url doesn't stumble over '://' in the request URI
     $ru = array_merge(array('path' => '', 'query' => ''), parse_url('scheme://authority' . $rq->getRequestUri()));
     if (isset($_SERVER['QUERY_STRING'])) {
         $qs = $_SERVER['QUERY_STRING'];
     } else {
         $qs = '';
     }
     // when rewriting, apache strips one (not all) trailing ampersand from the end of QUERY_STRING... normalize:
     $rewritten = preg_replace('/&+$/D', '', $qs) !== preg_replace('/&+$/D', '', $ru['query']);
     if ($this->isEnabled() && $rewritten) {
         // strip the one trailing ampersand, see above
         $queryWasEmptied = false;
         if ($ru['query'] !== '' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) {
             $ru['query'] = preg_replace('/&$/D', '', $ru['query']);
             if ($ru['query'] == '') {
                 $queryWasEmptied = true;
             }
         }
         $stripFromQuery = '&' . $ru['query'];
         if ($ru['query'] == '' && !$queryWasEmptied && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) {
             // if the query is empty, simply give apache2 nothing instead of an "&", since that could kill a real trailing ampersand in the path, as Apache strips those from the query string (which has the rewritten path), but not the request uri
             $stripFromQuery = '';
         }
         $this->input = preg_replace('/' . preg_quote($stripFromQuery, '/') . '$/D', '', $qs);
         if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache/2') !== false) {
             $sru = $_SERVER['REQUEST_URI'];
             if (($fqmp = strpos($sru, '?')) !== false && $fqmp == strlen($sru) - 1) {
                 // strip a trailing question mark, but only if it really is the query string separator (i.e. the only question mark in the URI)
                 $sru = substr($sru, 0, -1);
             } elseif ($ru['query'] !== '' || $queryWasEmptied) {
                 // if there is a trailing ampersand (in query string or path, whatever ends the URL), strip it (but just one)
                 $sru = preg_replace('/&$/D', '', $sru);
             }
             // multiple consecutive slashes got lost in our input thanks to an apache bug
             // let's fix that
             $cqs = preg_replace('#/{2,}#', '/', rawurldecode($ru['query']));
             $cru = preg_replace('#/{2,}#', '/', rawurldecode($sru));
             $tmp = preg_replace('/' . preg_quote($this->input . ($cqs != '' || $queryWasEmptied ? '?' . $cqs : ''), '/') . '$/D', '', $cru);
             $input = preg_replace('/^' . preg_quote($tmp, '/') . '/', '', $sru);
             if ($ru['query'] !== '' || $queryWasEmptied) {
                 $input = preg_replace('/' . preg_quote('?' . $ru['query'], '/') . '$/D', '', $input);
             }
             $this->input = $input;
         }
         if (!(isset($_SERVER['SERVER_SOFTWARE']) && (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache/1') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false && isset($_SERVER['UNENCODED_URL'])))) {
             // don't do that for Apache 1 or IIS 7 with URL Rewrite Module, it's already rawurldecode()d there
             $this->input = rawurldecode($this->input);
         }
         $xrup = rawurldecode($ru['path']);
         $this->basePath = $this->prefix = preg_replace('/' . preg_quote($this->input, '/') . '$/D', '', rawurldecode($ru['path']));
         // that was easy. now clean up $_GET and the Request
         $parsedRuQuery = $parsedInput = '';
         parse_str($ru['query'], $parsedRuQuery);
         parse_str($this->input, $parsedInput);
         if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
             $parsedRuQuery = AgaviWebRequest::clearMagicQuotes($parsedRuQuery);
             $parsedInput = AgaviWebRequest::clearMagicQuotes($parsedInput, false);
         }
         foreach (array_diff(array_keys($parsedInput), array_keys($parsedRuQuery)) as $unset) {
             // our element is in $_GET
             unset($_GET[$unset]);
             unset($GLOBALS['HTTP_GET_VARS'][$unset]);
             // if it is not also in $_POST, then we need to remove it from the request params
             if (!isset($_POST[$unset])) {
                 $rd->removeParameter($unset);
                 // and from $_REQUEST, too!
                 unset($_REQUEST[$unset]);
             }
         }
     } else {
         $sn = $_SERVER['SCRIPT_NAME'];
         $path = rawurldecode($ru['path']);
         $appendFrom = 0;
         $this->prefix = AgaviToolkit::stringBase($sn, $path, $appendFrom);
         $this->prefix .= substr($sn, $appendFrom);
         $this->input = substr($path, $appendFrom);
         if (!isset($_SERVER['SERVER_SOFTWARE']) || strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') === false || isset($_SERVER['HTTP_X_REWRITE_URL']) || !isset($_SERVER['GATEWAY_INTERFACE']) || strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') === false) {
             // don't do that for IIS-CGI, it's already rawurldecode()d there
             $this->input = rawurldecode($this->input);
         }
         $this->basePath = str_replace('\\', '/', dirname($this->prefix));
     }
     $this->inputParameters = $_GET;
     if (!$this->input) {
//.........这里部分代码省略.........
开发者ID:philippjenni,项目名称:icinga-web,代码行数:101,代码来源:AgaviWebRouting.class.php


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