/** * Returns the URL registerd as $name prepended to $suffix. * * Example: * <code> * ezcUrlCreator::registerUrl( 'map', '/images/geo?xsize=450&ysize=450&zoom=4' ); * echo ezcUrlCreator::prependUrl( 'map', 'map_sweden.gif' ); * </code> * will output: * /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4 * * @throws ezcUrlNotRegisteredException * if $name is not registered * @param string $name The name associated with the URL that will be appended with $suffix * @param string $suffix The string which will be appended to the URL * @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(); }
public function testSetUnorderedParameterAggregateArrayMultipleMultiple() { $urlCfg = new ezcUrlConfiguration(); $urlCfg->addUnorderedParameter('param2', ezcUrlConfiguration::AGGREGATE_ARGUMENTS); $url = new ezcUrl('http://www.example.com', $urlCfg); $expected = 'http://www.example.com/(param2)/x/y/(param2)/z/t'; $url->setParam('param2', array(array('x', 'y'), array('z', 't'))); $this->assertEquals($expected, $url->buildUrl()); $this->assertEquals(array(array('x', 'y'), array('z', 't')), $url->getParam('param2')); }
<?php require_once 'tutorial_autoload.php'; // create an ezcUrlConfiguration object $urlCfg = new ezcUrlConfiguration(); // set the basedir and script values $urlCfg->basedir = 'mydir'; $urlCfg->script = 'index.php'; // define delimiters for unordered parameter names $urlCfg->unorderedDelimiters = array('(', ')'); // define ordered parameters $urlCfg->addOrderedParameter('section'); $urlCfg->addOrderedParameter('group'); $urlCfg->addOrderedParameter('category'); $urlCfg->addOrderedParameter('subcategory'); // define unordered parameters $urlCfg->addUnorderedParameter('game', ezcUrlConfiguration::MULTIPLE_ARGUMENTS); // create a new ezcUrl object from a string url and use the above $urlCfg $url = new ezcUrl('http://www.example.com/mydir/index.php/groups/Games/Adventure/Adult/(game)/Larry/7', $urlCfg); // get the parameter values from the url var_dump($url->getParam('section')); var_dump($url->getParam('group')); var_dump($url->getParam('category')); var_dump($url->getParam('subcategory')); var_dump($url->getParam('game')); // output the url (index.php will not be there) var_dump($url->buildUrl()); // output the url (with index.php included) var_dump($url->buildUrl(true));
<?php require_once 'tutorial_autoload.php'; // create an ezcUrlConfiguration object $urlCfg = new ezcUrlConfiguration(); // single parameter value $urlCfg->addUnorderedParameter('param1'); $url = new ezcUrl('http://www.example.com/(param1)/x/(param1)/y/z', $urlCfg); var_dump($url->getParam('param1')); // will output "y" // multiple parameter values $urlCfg->addUnorderedParameter('param1', ezcUrlConfiguration::MULTIPLE_ARGUMENTS); $url = new ezcUrl('http://www.example.com/(param1)/x/(param1)/y/z', $urlCfg); var_dump($url->getParam('param1')); // will output array( "y", "z" ) // multiple parameter values with aggregation $urlCfg->addUnorderedParameter('param1', ezcUrlConfiguration::AGGREGATE_ARGUMENTS); $url = new ezcUrl('http://www.example.com/(param1)/x/(param1)/y/z', $urlCfg); var_dump($url->getParam('param1')); // will output array( array( "x" ), array( "y", "z" ) ) // output the url (it will be similar to the input url) var_dump($url->buildUrl());
/** * Set up the process * * @param chkStructUriOptions $uriOptions * @see iBenchmarkable::setUp() */ public function setUp( $uriOptions = null ) { $urlBuilder = new ezcUrl(); if( isset( $uriOptions ) ) $this->uriOptions = $uriOptions; //mandatory: if( isset( $uriOptions ) ) { if( isset( $uriOptions->host ) ) $urlBuilder->host = $uriOptions->host; if( isset( $uriOptions->path ) ) $urlBuilder->path = $uriOptions->path; } $urlBuilder->scheme = 'http'; //optionnals: if( isset( $uriOptions->scheme ) ) { $urlBuilder->scheme = $uriOptions->scheme; } if( isset( $uriOptions->basedir ) ) { $urlBuilder->basedir = $uriOptions->basedir; } if( isset( $uriOptions->query ) ) { $urlBuilder->query = $uriOptions->query; } $this->url = $urlBuilder->buildUrl( false ); }