public function testPerformance()
 {
     $config['router.routing_table']['protocol'] = 'rewrite';
     // 初始化LtUrl
     $url = new LtUrl();
     $url->configHandle->addConfig($config);
     $url->init();
     // 初始化结束
     // 测试生成超链接
     $href = $url->generate('news', 'list', array('catid' => 4, 'page' => 10));
     $this->assertEquals('/news-list-catid-4-page-10.html', $href);
     /**
      * 运行 10,000 次,要求在1秒内运行完
      */
     $base_memory_usage = memory_get_usage();
     $times = 10000;
     $startTime = microtime(true);
     for ($i = 0; $i < $times; $i++) {
         $url->generate('news', 'list', array('catid' => 4, 'page' => 10));
     }
     $endTime = microtime(true);
     $totalTime = round($endTime - $startTime, 6);
     $averageTime = round($totalTime / $times, 6);
     $memory_usage = memory_get_usage() - $base_memory_usage;
     $averageMemory = formatSize($memory_usage / $times);
     $memory_usage = formatSize($memory_usage);
     if (LOTUS_UNITTEST_DEBUG) {
         echo "\n----------------------Url-----------------------------\n";
         echo "times      \t{$times}\n";
         echo "totalTime   \t{$totalTime}s\taverageTime   \t{$averageTime}s\n";
         echo "memoryUsage \t{$memory_usage}\taverageMemory \t{$averageMemory}";
         echo "\n---------------------------------------------------------\n";
     }
     $this->assertTrue(1 > $totalTime);
 }
 public function testRewrite()
 {
     $config['router.routing_table']['protocol'] = 'REWRITE';
     $configHandle = new LtConfig();
     $configHandle->addConfig($config);
     $url = new LtUrl();
     $url->configHandle = $configHandle;
     $url->init();
     $params = array('id' => 123456, 'page' => '12', 'q-/key' => '空 -/格');
     $url->baseUrl = 'http://localhost';
     $link = $url->generate('goods', 'detail', $params);
     $this->assertEquals('http://localhost/goods-detail-id-123456-page-12-q%FF/key-%E7%A9%BA%20%FF%2F%E6%A0%BC.html', $link);
     $url->baseUrl = 'http://127.0.0.1';
     $link = $url->generate('goods', 'detail', $params);
     $this->assertEquals('http://127.0.0.1/goods-detail-id-123456-page-12-q%FF/key-%E7%A9%BA%20%FF%2F%E6%A0%BC.html', $link);
 }
Exemple #3
0
<?php 
$lotusHome = substr(__FILE__, 0, strpos(__FILE__, "example")) . '/';
include $lotusHome . "runtime/Config.php";
include $lotusHome . "runtime/Store.php";
include $lotusHome . "runtime/StoreMemory.php";
include $lotusHome . "runtime/Url/Url.php";
$config['router.routing_table'] = array('pattern' => ":module-:action-ak47-*", 'default' => array('module' => 'default', 'action' => 'index'), 'reqs' => array('module' => '[a-zA-Z0-9\\.\\-_]+', 'action' => '[a-zA-Z0-9\\.\\-_]+'), 'varprefix' => ':', 'delimiter' => '-', 'postfix' => '.html', 'protocol' => 'STANDARD');
// 初始化LtUrl
$url = new LtUrl();
$url->configHandle->addConfig($config);
$url->init();
$href = $url->generate('news', 'list', array('catid' => 4, 'page' => 10));
echo $href;
Exemple #4
0
$configHandle = new LtConfig();
$configHandle->addConfig($config);
$router = new LtRouter();
$router->configHandle = $configHandle;
$router->init();
$url = new LtUrl();
$url->configHandle = $configHandle;
$url->init();
$params = array('id' => 123456, 'page' => '12', 'q-/key' => '空 -/格');
$url->baseUrl = 'http://127.0.0.1';
$link1 = $url->generate('news', 'top');
$url->baseUrl = 'http://localhost';
$link2 = $url->generate('goods', 'detail', $params);
$url->baseUrl = 'http://127.0.0.1';
$link3 = $url->getLink('goods', 'detail', $params);
$url2 = new LtUrl();
// $url2->withPath = false; //是否包含相对路径
$url2->init();
$link4 = $url2->generate('default', 'index', $params, null, 'standard');
$link5 = $url2->generate('default', 'index', $params, null, 'path_info');
$link6 = $url2->generate('default', 'index', $params, null, 'rewrite');
$get = var_export($_GET, true);
$post = var_export($_POST, true);
if (isset($_SERVER['SERVER_PROTOCOL'])) {
    echo <<<END
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Welcome LotusPHP</title>
<style>
 /**
  * 重定向到module action
  *
  * @param string $module
  * @param string $action
  * @param array $args
  */
 protected function redirect($module, $action, $args = array())
 {
     $url = new LtUrl();
     $url->init();
     header('location:' . $url->generate($module, $action, $args));
     exit;
 }