Path

ez components / documentation / api reference / 2006.2 / url


eZ Components 2006.2

Url: ezcUrl

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcUrl

ezcUrl stores an URL both absolute and relative and contains methods to retrieve the various parts of the URL and to manipulate them. [source]
Example of use:
 1.  // create an ezcUrlConfiguration object
 2.   $urlCfg new ezcUrlConfiguration();
 3.  // set the basedir and script values
 4.   $urlCfg->basedir 'mydir';
 5.  $urlCfg->script 'index.php';
 6.  
 7.  // define delimiters for unordered parameter names
 8.   $urlCfg->unorderedDelimiters array'('')' );
 9.  
10.  // define ordered parameters
11.   $urlCfg->addOrderedParameter'section' );
12.  $urlCfg->addOrderedParameter'group' );
13.  $urlCfg->addOrderedParameter'category' );
14.  $urlCfg->addOrderedParameter'subcategory' );
15.  
16.  // define unordered parameters
17.   $urlCfg->addUnorderedParameter'game'ezcUrlConfiguration::MULTIPLE_ARGUMENTS );
18.  
19.  // create a new ezcUrl object from a string url and use the above $urlCfg
20.   $url new ezcUrl'http://www.example.com/mydir/index.php/groups/Games/Adventure/Adult/(game)/Larry/7'$urlCfg );
21.  
22.  // to get the parameter values from the url use $url->getParam():
23.   $section =  $url->getParam'section' )// will be "groups"
24.   $group $url->getParam'group' )// will be "Games"
25.   $category $url->getParam'category' )// will be "Adventure"
26.   $subcategory $url->getParam'subcategory' )// will be "Adult"
26.   $game $url->getParam'game' )// will be array( "Larry", "7" )

Properties

string read/write  $basedir
Base directory or null.
string read/write  $fragment
Anchor or null.
string read/write  $host
Hostname or null
string read/write  $params
Complete ordered parameters as array.
string read/write  $pass
Password or null.
string read/write  $path
Complete path as an array.
string read/write  $port
Port or null.
string read/write  $query
Complete query string as an associative array.
string read/write  $scheme
Protocol or null.
string read/write  $script
Script name or null.
string read/write  $uparams
Complete unordered parameters as associative array.
string read/write  $user
User or null.

Method Summary

public ezcUrl __construct( [$url = null], [$urlCfg = null] )
Constructs a new ezcUrl object from the string $url.
public void applyConfiguration( $urlCfg )
Applies the configuration $urlCfg to the current url.
public string buildUrl( )
Returns this URL as a string.
public mixed getParam( $name )
Returns the specified parameter from the url based on $urlCfg.
public array(string=>mixed) getQuery( )
Returns the query elements as an associative array.
public bool isRelative( )
Returns true if this URL is relative and false if the URL is absolute.
public array(string=>mixed) parseOrderedParameters( $config, $index )
Returns ordered parameters from the $path array.
public array(string=>mixed) parseUnorderedParameters( $config, $index )
Returns unordered parameters from the $path array.
public void setParam( $name, $value )
Sets the specified parameter in the url based on $urlCfg.
public void setQuery( $query )
Set the query elements using the associative array provided.
public string __toString( )
Returns this URL as a string by calling buildUrl().

Methods

__construct

ezcUrl __construct( [string $url = null], [ezcUrlConfiguration $urlCfg = null] )
Constructs a new ezcUrl object from the string $url.

Parameters

Name Type Description
$url string  
$urlCfg ezcUrlConfiguration  

applyConfiguration

void applyConfiguration( ezcUrlConfiguration $urlCfg )
Applies the configuration $urlCfg to the current url.
It fills the arrays $basedir, $script, $params and $uparams with values from $path.

Parameters

Name Type Description
$urlCfg ezcUrlConfiguration  

buildUrl

string buildUrl( )
Returns this URL as a string.
The query part of the URL is build with http_build_query() which encodes the query in a similar way to urlencode().

getParam

mixed getParam( string $name )
Returns the specified parameter from the url based on $urlCfg.

Parameters

Name Type Description
$name string  

Throws

ClassDescription
ezcUrlNoConfigurationException if an $urlCfg is not defined
ezcUrlInvalidParameterException if the specified parameter is not defined in $urlCfg

getQuery

array(string=>mixed) getQuery( )
Returns the query elements as an associative array.
Example: for 'http://www.example.com/mydir/shop?content=view&products=10' returns array( 'content' => 'view', 'products' => '10' )

isRelative

bool isRelative( )
Returns true if this URL is relative and false if the URL is absolute.

parseOrderedParameters

array(string=>mixed) parseOrderedParameters( array(int=>string) $config, int $index )
Returns ordered parameters from the $path array.

Parameters

Name Type Description
$config array(int=>string)  
$index int  

parseUnorderedParameters

array(string=>mixed) parseUnorderedParameters( array(int=>string) $config, int $index )
Returns unordered parameters from the $path array.

Parameters

Name Type Description
$config array(int=>string)  
$index int  

setParam

void setParam( string $name, string $value )
Sets the specified parameter in the url based on $urlCfg.

Parameters

Name Type Description
$name string  
$value string  

Throws

ClassDescription
ezcUrlNoConfigurationException if an $urlCfg is not defined
ezcUrlInvalidParameterException if the specified parameter is not defined in $urlCfg

setQuery

void setQuery( string $query )
Set the query elements using the associative array provided.
Example: for 'http://www.example.com/mydir/shop' and $query = array( 'content' => 'view', 'products' => '10' ) then 'http://www.example.com/mydir/shop?content=view&products=10'

Parameters

Name Type Description
$query string  

__toString

string __toString( )
Returns this URL as a string by calling buildUrl().

Last updated: Thu, 01 Nov 2007