Пример #1
0
 /**
  * Test for bug #12825 (URL parser doesn't like empty elements.)
  */
 public function testGetUnorderedParameterMissing()
 {
     $urlCfg = new ezcUrlConfiguration();
     $urlCfg->basedir = 'mydir/';
     $urlCfg->script = 'index.php';
     $urlCfg->addUnorderedParameter('language');
     // should have been http://www.example.com/mydir/index.php/(language)/en
     $url = new ezcUrl('http://www.example.com/mydir/index.php//en', $urlCfg);
     $this->assertEquals(null, $url->getParam('language'));
 }
Пример #2
0
 /**
  * parseUrl sets up the parameters list by breaking up the URL and providing some 
  * default variables.
  */
 private function parseUrl(&$parameters)
 {
     $urlConfigRoot = new ezcUrlConfiguration();
     $urlConfigRoot->script = 'index.php';
     $urlConfigRoot->addOrderedParameter('module');
     $url = new ezcUrl($_SERVER['REQUEST_URI'], $urlConfigRoot);
     $moduleIdentifier = $url->getParam('module');
     $urlConfig = $this->urlConfigs[$moduleIdentifier];
     if (!$urlConfig) {
         $urlConfig = $this->urlConfigs['notfound'];
         $url = new ezcURL('/notfound/notfound/notfound', $urlConfigRoot);
     }
     $url->applyConfiguration($urlConfig);
     // var_dump($url->params);
     $parameters = array_merge($url->getQuery(), $_POST);
     $parameters['url'] = $url;
     $parameters['method'] = strtolower($_SERVER['REQUEST_METHOD']);
     $parameters['client_ip'] = $_SERVER['REMOTE_ADDR'];
     $parameters['client_port'] = $_SERVER['REMOTE_PORT'];
     //            var_dump($url->path);
 }
Пример #3
0
<?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));
Пример #4
0
$urlCfgDefault->addOrderedParameter('section');
// create a configuration for artists
$urlCfgArtist = new ezcUrlConfiguration();
$urlCfgArtist->addOrderedParameter('section');
$urlCfgArtist->addOrderedParameter('artist_name');
// create a configuration for albums
$urlCfgAlbum = new ezcUrlConfiguration();
$urlCfgAlbum->addOrderedParameter('section');
$urlCfgAlbum->addOrderedParameter('artist_name');
$urlCfgAlbum->addOrderedParameter('album_name');
// create a configuration for music genres
$urlCfgGenre = new ezcUrlConfiguration();
$urlCfgGenre->addOrderedParameter('section');
$urlCfgGenre->addOrderedParameter('genre_name');
$url = new ezcUrl('http://mymusicsite.com/showartist/Beatles', $urlCfgDefault);
switch ($url->getParam('section')) {
    case 'showartist':
        $url->applyConfiguration($urlCfgArtist);
        $artist = $url->getParam('artist_name');
        // do stuff with $artist
        var_dump($artist);
        break;
    case 'showalbum':
        $url->applyConfiguration($urlCfgAlbum);
        $artist = $url->getParam('artist_name');
        $album = $url->getParam('album_name');
        // do stuff with $artist and $album
        var_dump($artist);
        var_dump($album);
        break;
    case 'showgenre':
Пример #5
0
<?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());