Apache Zeta Components Manual :: File Source for url_tools.php
Source for file url_tools.php
Documentation is available at url_tools.php
* File containing the ezcUrlTools class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* Class providing methods for URL parsing.
* Static methods contained in this class:
* - parseQueryString() - It implements the functionality of the PHP function
* parse_str(), but without converting dots to underscores in parameter names.
* - getCurrentUrl() - Returns the current URL as a string from the provided
* array (by default $_SERVER).
* Parses the provided string and returns an associative array structure.
* It implements the functionality of the PHP function parse_str(), but
* without converting dots to underscores in parameter names.
* $str = 'foo[]=bar&openid.nonce=123456';
* parse_str( $str, $params );
* $params = ezcUrlTools::parseQueryString( $str );
* In the first case (parse_str()), $params will be:
* array( 'foo' => array( 'bar' ), 'openid_nonce' => '123456' );
* In the second case (ezcUrlTools::parseQueryString()), $params will be:
* array( 'foo' => array( 'bar' ), 'openid.nonce' => '123456' );
* @param array(string=>mixed) $str The string to parse
* @return array(string=>mixed)
// $params will be returned, but first we have to ensure that the dots
// are not converted to underscores
$separator =
ini_get( 'arg_separator.input' );
if ( empty( $separator ) )
// go through $params and ensure that the dots are not converted to underscores
$args =
explode( $separator, $str );
foreach ( $args as $arg )
if ( !isset
( $parts[1] ) )
if ( isset
( $params[$paramKey] ) &&
strpos( $paramKey, '_' ) !==
false )
for ( $i =
0; $i <
strlen( $paramKey ); $i++
)
$newKey .=
( $paramKey{$i} ===
'_' &&
$key{$i} ===
'.' ) ?
'.' :
$paramKey{$i};
if ( ( $pos =
array_search( $paramKey, $keys ) ) !==
false )
* Returns the current URL as a string from the array $source
* The following fields are used in building the URL:
* - HTTPS - determines the scheme ('http' or 'https'). 'https' only if
* the 'HTTPS' field is set or if it is 'on' or '1'
* - SERVER_PORT - determines if port is default (80 = do not include port)
* or not default (other than 80 = include port)
* For example, if $_SERVER has these fields:
* 'SERVER_NAME' => 'www.example.com',
* 'REQUEST_URI' => '/index.php'
* Then by calling this function (with no parameters), this URL will be
* returned: 'http://www.example.com/index.php'.
* The source of the URL parts can be changed to be other than $_SERVER by
* specifying an array parameter when calling this function.
* @todo check if REQUEST_URI works in Windows + IIS.
* - Use PHP_SELF instead?
* - Or use SCRIPT_NAME + QUERY_STRING?
* - Or even use an ISAPI filter?
* @todo check for proxy servers
* - Use $_SERVER['HTTP_X_FORWARDED_SERVER']?
* @param array(string=>mixed) $source The default array source, default $_SERVER
if ( isset
( $source['HTTPS'] ) &&
( strtolower( $source['HTTPS'] ) ===
'on' ||
$source['HTTPS'] ===
'1' ) )
$url .= isset
( $source['SERVER_NAME'] ) ?
$source['SERVER_NAME'] :
null;
if ( isset
( $source['SERVER_PORT'] ) &&
$source['SERVER_PORT'] !=
80 )
$url .=
":{$source['SERVER_PORT']}";
$url .= isset
( $source['REQUEST_URI'] ) ?
$source['REQUEST_URI'] :
null;