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


PHP Uri::setPath方法代码示例

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


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

示例1: parse

 /**
  * Parses the string and returns the {@link Uri}.
  * 
  * Parses the string and returns the {@link Uri}. If parsing fails, null is returned.
  * 
  * @param String $string The url.
  * 
  * @return \Bumble\Uri\Uri The Uri object.
  */
 public function parse($string)
 {
     $data = parse_url($string);
     //helper function gets $a[$k], checks if exists
     function get($a, $k)
     {
         if (array_key_exists($k, $a)) {
             return empty($a[$k]) ? null : $a[$k];
         }
         return null;
     }
     if ($data === null) {
         return null;
     }
     $uri = new Uri();
     $uri->setProtocol(get($data, 'scheme'));
     $uri->setUsername(get($data, 'user'));
     $uri->setPassword(get($data, 'pass'));
     $uri->setHost(get($data, 'host'));
     $uri->setPort(get($data, 'port'));
     $uri->setPath(get($data, 'path'));
     $uri->setQuery(get($data, 'query'));
     $uri->setAnchor(get($data, 'anchor'));
     return $uri;
 }
开发者ID:Attibee,项目名称:Bumble-Uri,代码行数:34,代码来源:Tokenizer.php

示例2: testSetPath

 /**
  * @covers MediaCore\Uri::setPath
  */
 public function testSetPath()
 {
     $url = 'http://example.com/path/to/directory';
     $uri = new Uri($url);
     $uri->setPath('/subdirectory');
     $expectedValue = '/subdirectory';
     $this->assertEquals($expectedValue, $uri->getPath());
 }
开发者ID:mediacore,项目名称:mediacore-client-php,代码行数:11,代码来源:UriTest.php

示例3: testSetGetPath

 public function testSetGetPath()
 {
     $path = 'this/is/another/path/with-file.other';
     $this->uri->setPath($path);
     $this->assertEquals($path, $this->uri->getPath());
     $this->assertEquals('this/is/another/path', $this->uri->getDirname());
     $this->assertEquals('with-file.other', $this->uri->getBasename());
     $this->assertEquals('with-file', $this->uri->getFilename());
     $this->assertEquals('other', $this->uri->getExtension());
     $this->uri->setPath('');
     $this->assertEquals('', $this->uri->getDirname());
     $this->assertEquals('', $this->uri->getBasename());
     $this->assertEquals('', $this->uri->getFilename());
     $this->assertEquals('', $this->uri->getExtension());
 }
开发者ID:codeblanche,项目名称:web,代码行数:15,代码来源:UriTest.php

示例4: parse

 public function parse($str)
 {
     $uri = new Uri();
     $matched = preg_match('/^(?:([a-z\\.-]+):\\/\\/)?' . '(?:([^:]+)(?::(\\S+))?@)?' . '(' . '(?:[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})' . '|(?:(?:(?:[^\\.:\\/\\s-]+)(?:-[^\\.:\\/\\s-]+)*\\.)+)(?:[^?\\/:\\.]+)' . ')' . '(?::([0-9]+))?' . '(' . '\\/(?:[^#?\\/\\s.]+\\/?)*' . '(?:[^\\.\\s]*\\.[^#?\\s]+)?' . ')?' . '(\\?(?:[a-z0-9%-]+(?:=[a-z0-9%-]+)?)(?:&(?:[a-z0-9%-]+(?:=[a-z0-9%-]+)?))*)?' . '(?:\\#([a-z0-9&=-]+))?' . '$/ixSs', $str, $data);
     if (!$matched) {
         return null;
     }
     $protocol = isset($data[1]) && !empty($data[1]) ? $data[1] : null;
     $username = isset($data[2]) && !empty($data[2]) ? $data[2] : null;
     $password = isset($data[3]) && !empty($data[3]) ? $data[3] : null;
     $domain = trim($data[4], '.');
     //domain always exists
     $port = isset($data[6]) && !empty($data[6]) ? $data[6] : null;
     $path = isset($data[7]) && !empty($data[7]) ? $data[7] : null;
     $query = isset($data[8]) && !empty($data[8]) ? ltrim($data[8], '?') : null;
     $anchor = isset($data[9]) && !empty($data[9]) ? $data[9] : null;
     //the entire ip/domain is caught as one piece.. was easier than regexing it
     //so we tld is null for ip
     //and we separate tld/domain for the domain version
     if (is_numeric(str_replace('.', '', $domain))) {
         //ip is not the right length
         if (count(explode('.', $domain)) != 4) {
             return null;
         }
         $tld = null;
     } else {
         $tld = end(explode('.', $domain));
         $domain = implode('.', explode('.', $domain, -1));
     }
     $uri->setProtocol($protocol);
     $uri->setUsername($username);
     $uri->setPassword($password);
     $uri->setDomain($domain);
     $uri->setTld($tld);
     $uri->setPort($port);
     $uri->setPath($path);
     $uri->setQuery($query);
     $uri->setAnchor($anchor);
     return $uri;
 }
开发者ID:Attibee,项目名称:defunct-dont-use,代码行数:40,代码来源:UriParser.php

示例5: rewrite


//.........这里部分代码省略.........
         $seo = new Seo($this->registry);
         switch ($uri->getVar('route')) {
             case 'common/home':
                 $is_home = true;
                 break;
             case 'product/product':
                 if ($this->config->get('config_seo_category')) {
                     if ($uri->getVar('path') and $this->config->get('config_seo_category') == 'last') {
                         $categories = explode('_', $uri->getVar('path'));
                         $categories = array(end($categories));
                     } else {
                         $categories = array();
                         $category_id = $seo->getCategoryIdBySortOrder($uri->getVar('product_id'));
                         if (!is_null($category_id)) {
                             $categories = $seo->getParentCategoriesIds($category_id);
                             $categories[] = $category_id;
                             if ($this->config->get('config_seo_category') == 'last') {
                                 $categories = array(end($categories));
                             }
                         }
                     }
                     foreach ($categories as $category) {
                         $alias = $seo->getAlias($category, 'category');
                         if ($alias) {
                             $url .= '/' . $alias;
                         }
                     }
                     $uri->delVar('path');
                 }
                 if ($uri->getVar('product_id')) {
                     $alias = $seo->getAlias($uri->getVar('product_id'), 'product');
                     if ($alias) {
                         $url .= '/' . $alias;
                     }
                     $uri->delVar('product_id');
                     $uri->delVar('manufacturer_id');
                     $uri->delVar('path');
                     $uri->delVar('search');
                 }
                 break;
             case 'product/category':
                 if ($uri->getVar('path')) {
                     $categories = explode('_', $uri->getVar('path'));
                     foreach ($categories as $category) {
                         $alias = $seo->getAlias($category, 'category');
                         if ($alias) {
                             $url .= '/' . $alias;
                         }
                     }
                     $uri->delVar('path');
                 }
                 break;
             case 'information/information':
                 if ($uri->getVar('information_id')) {
                     $alias = $seo->getAlias($uri->getVar('information_id'), 'information');
                     if ($alias) {
                         $url .= '/' . $alias;
                     }
                     $uri->delVar('information_id');
                 }
                 break;
             case 'product/manufacturer/info':
                 if ($uri->getVar('manufacturer_id')) {
                     $alias = $seo->getAlias($uri->getVar('manufacturer_id'), 'manufacturer');
                     if ($alias) {
                         $url .= '/' . $alias;
                     }
                     $uri->delVar('manufacturer_id');
                 }
                 break;
             default:
                 if (!$this->seoDisabled($uri->getVar('route'))) {
                     $url = '/' . $uri->getVar('route');
                 }
                 break;
         }
         $uri->delVar('route');
     }
     if ($url or $is_home) {
         // Add language code to URL
         if ($this->config->get('config_seo_lang_code')) {
             $url = '/' . $this->session->data['language'] . $url;
         }
         $uri->delVar('lang');
         // Append the suffix if enabled
         if ($this->config->get('config_seo_suffix') && !$is_home) {
             $url .= '.html';
         }
         $path = $uri->getPath();
         if ($is_home or $this->config->get('config_seo_rewrite')) {
             $path = str_replace('index.php/', '', $path);
             $path = str_replace('index.php', '', $path);
         }
         $path .= $url;
         $uri->setPath($path);
         return $uri->toString();
     } else {
         return $link;
     }
 }
开发者ID:hoanglehuu,项目名称:arastta,代码行数:101,代码来源:route.php


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