Path

ez components / documentation / api reference / 2007.1 / url


eZ Components 2007.1

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.
ezcUrlConfiguration read/write  $configuration
The URL configuration defined for this URL, 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], [$configuration = null] )
Constructs a new ezcUrl object from the string $url.
public void applyConfiguration( $configuration )
Applies the URL configuration $configuration 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 the URL configuration.
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 the URL configuration.
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 $configuration = null] )
Constructs a new ezcUrl object from the string $url.
If the $configuration parameter is provided, then it will apply the configuration to the URL by calling applyConfiguration().

Parameters

Name Type Description
$url string A string URL from which to construct the URL object
$configuration ezcUrlConfiguration An optional URL configuration used when parsing and building the URL

applyConfiguration

void applyConfiguration( ezcUrlConfiguration $configuration )
Applies the URL configuration $configuration to the current url.
It fills the arrays $basedir, $script, $params and $uparams with values from $path.
It also sets the property configuration to the value of $configuration.

Parameters

Name Type Description
$configuration ezcUrlConfiguration An URL configuration used in parsing

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 the URL configuration.

Parameters

Name Type Description
$name string The name of the parameter for which to return the value

Throws

ClassDescription
ezcUrlNoConfigurationException if an URL configuration is not defined
ezcUrlInvalidParameterException if the specified parameter is not defined in the URL configuration

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(string) $config, int $index )
Returns ordered parameters from the $path array.

Parameters

Name Type Description
$config array(string) An array of ordered parameters names, from the URL configuration used in parsing
$index int The index in the URL path part from where to start the matching of $config

parseUnorderedParameters

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

Parameters

Name Type Description
$config array(string) An array of unordered parameters names, from the URL configuration used in parsing
$index int The index in the URL path part from where to start the matching of $config

setParam

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

Parameters

Name Type Description
$name string The name of the parameter to set
$value string The new value of the parameter

Throws

ClassDescription
ezcUrlNoConfigurationException if an URL configuration is not defined
ezcUrlInvalidParameterException if the specified parameter is not defined in the URL configuration

setQuery

void setQuery( array(string=>mixed) $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 array(string=>mixed) The new value of the query part

__toString

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

Last updated: Thu, 01 Nov 2007