Beispiel #1
0
<?php

use Carrot\DependencyInjection\Reference, Carrot\DependencyInjection\Injector\ConstructorInjector, Carrot\DependencyInjection\Injector\ProviderInjector, Carrot\DependencyInjection\Injector\CallbackInjector;
use Carrot\Routing\HTTPURI;
# Set up autoloader
$autoloader = (require 'autoloader.php');
$autoloader->register();
$uri = new HTTPURI('http', $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI'], $_GET);
echo '<pre>$_GET = ', var_dump($_GET), '</pre>';
echo '<pre>', var_dump($uri->getScheme()), '</pre>';
echo '<pre>', var_dump($uri->getScheme()), '</pre>';
echo '<pre>', var_dump($uri->pathMatches('/^\\/bläh/u')), '</pre>';
?>
<a href="<?php 
echo $uri->get();
?>
"><?php 
echo $uri->get();
?>
</a>
<?php 
exit;
# Test URI
$string = 'http://www.ics.uci.edu/pub/ietf/uri/?br%C3%BCk=blük#Related';
//$string = 'xmpp:user@host/resource';
preg_match_all('/^(([^:\\/?#]+):)?(\\/\\/([^\\/?#]*))?([^?#]*)(\\\\?([^#]*))?(#(.*))?/', $string, $matches);
echo '<pre>', var_dump($matches), '</pre>';
echo '<pre>', var_dump(substr($matches[7][0], 1)), '</pre>';
parse_str(substr($matches[7][0], 1), $get);
echo '<pre>PARSE_STR = ', var_dump($get), '</pre>';
?>
 /**
  * Test the getters and setters with unicode (UTF-8) arguments.
  *
  */
 public function testUnicodeGettersAndSetters()
 {
     $queryArray = array('wört' => 'schlossbrücker', 'café' => 'sûr=!', '←ĊÃÂşŝőÐΞφ❡⠿' => '㈱グカ゚ㄤㄦㄜㄠ', 'a̢̱̠̼̐͊͋͗ͤ͑͘͝͡' => 'b̜̭̞̱̲̰̋̌̿͘');
     $queryAsString = 'wört=schlossbrücker&café=sûr=!&←ĊÃÂşŝőÐΞφ❡⠿=㈱グカ゚ㄤㄦㄜㄠ&a̢̱̠̼̐͊͋͗ͤ͑͘͝͡=b̜̭̞̱̲̰̋̌̿͘';
     $path = 'b̜̭̞̱̲̰̋̌̿͘/őÐΞφ/㈱グカ゚ㄤ/café';
     $fragment = 'jdf̸̪̫̫̮͐̽̓͂dЄӦӥӢՊ';
     $uri = new HTTPURI('https', 'example.net', $path, $queryArray, $fragment);
     $this->assertEquals('https', $uri->getScheme());
     $this->assertEquals('example.net', $uri->getAuthority());
     $this->assertEquals('/' . $path, $uri->getPath());
     $this->assertEquals($queryArray, $uri->getQueryAsArray());
     $this->assertEquals($queryAsString, urldecode($uri->getQueryAsString()));
     $fullURI = urldecode($uri->get());
     $this->assertEquals($fullURI, "https://example.net/{$path}?{$queryAsString}#{$fragment}");
     $uri->setPath('グカ゚café/ŝőa̢̱̠̼̐͊͋͗ͤ͑͘͝͡ÐΞ/←ĊÃ/');
     $uri->setQuery(array('1' => 'jdf̸̪̫̫̮͐̽̓͂dЄӦӥӢ'));
     $uri->setFragment('schlossbrücker');
     $this->assertEquals('/グカ゚café/ŝőa̢̱̠̼̐͊͋͗ͤ͑͘͝͡ÐΞ/←ĊÃ/', $uri->getPath());
     $this->assertEquals(array('1' => 'jdf̸̪̫̫̮͐̽̓͂dЄӦӥӢ'), $uri->getQueryAsArray());
     $this->assertEquals('1=jdf̸̪̫̫̮͐̽̓͂dЄӦӥӢ', urldecode($uri->getQueryAsString()));
     $this->assertEquals('schlossbrücker', $uri->getFragment());
     $uri->setPath('/%E3%82%B0%E3%82%AB%E3%82%9Acaf%C3%A9/%E2%86%90%C4%8A%C3%83/', FALSE);
     $uri->setFragment('f%C3%A4hrrader', FALSE);
     $this->assertEquals('/グカ゚café/←ĊÃ/', $uri->getPath());
     $this->assertEquals('fährrader', $uri->getFragment());
 }