string)
*/
private static $urls = array();
/**
* Registers $url as $name in the urls list.
*
* If $name is already registered, it will be overwritten.
*
* @param string $name
* @param string $url
*/
public static function registerUrl( $name, $url )
{
self::$urls[$name] = $url;
}
/**
* Returns the url registerd as $name prepended to $suffix.
*
* Example:
*
* ezcUrlCreator::registerUrl( 'map', '/images/geo?xsize=450&ysize=450&zoom=4' );
* echo ezcUrlCreator::prependUrl( 'map', 'map_sweden.gif' );
*
* will output:
* /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4
*
* @throws ezcUrlNotRegisteredException
* if $name is not registered
* @param string $name
* @param string $suffix
* @return string
*/
public static function prependUrl( $name, $suffix )
{
if ( !isset( self::$urls[$name] ) )
{
throw new ezcUrlNotRegisteredException( $name );
}
$url = new ezcUrl( self::$urls[$name] );
$url->path = array_merge( $url->path, explode( '/', $suffix ) );
return $url->buildUrl();
}
/**
* Returns the url registered as $name.
*
* This function accepts a variable number of arguments like the sprintf()
* function. If you specify more than 1 arguments when calling this
* function, the registered url will be formatted using those arguments
* similar with the sprintf() function.
* Example:
*
* ezcUrlCreator::registerUrl( 'map', '/images/geo/%s?xsize=%d&ysize=%d&zoom=%d' );
* echo ezcUrlCreator::getUrl( 'map', 'map_sweden.gif', 450, 450, 4 );
*
* will output:
* /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4
*
* @throws ezcUrlNotRegisteredException
* if $name is not registered
* @param string $name
* @param ... mixed args
* @return string
*/
public static function getUrl( $name )
{
if ( !isset( self::$urls[$name] ) )
{
throw new ezcUrlNotRegisteredException( $name );
}
if ( func_num_args() > 1 )
{
$args = func_get_args();
// get rid of the first argument ($name)
unset( $args[0] );
return vsprintf( self::$urls[$name], $args );
}
return self::$urls[$name];
}
}
?>