public function testAssemblyWithHostnameAndTransparent()
 {
     $chain = new RouterChainRule();
     $host = RouterHostnameRule::create(':subdomain.example.com')->setDefaults(array('subdomain' => 'www'));
     $transparent = RouterTransparentRule::create(':bar/:area/:action')->setDefaults(array('bar' => 'barvalue', 'area' => 'controller', 'action' => 'create'));
     $chain->chain($host)->chain($transparent);
     $this->assertEquals('http://www.example.com/', $chain->assembly());
     $this->assertEquals('http://www.example.com/barvalue/controller/misc', $chain->assembly(array('action' => 'misc')));
     $this->assertEquals('http://www.example.com/barvalue/misc', $chain->assembly(array('area' => 'misc')));
     $this->assertEquals('http://www.example.com/misc', $chain->assembly(array('bar' => 'misc')));
 }
 public function testAssemblingWithHostnameAndTransparentWithBaseUrl()
 {
     $base = 'http://www.example.com/~users/public/www/';
     $hostname = RouterHostnameRule::create(':subdomain.example.com')->setDefaults(array('subdomain' => 'www'));
     $transparent = RouterTransparentRule::create('/company/:id')->setRequirements(array('id' => '\\d+'));
     $chain = RouterChainRule::create()->chain($hostname)->chain($transparent);
     $this->router->setBaseUrl(HttpUrl::create()->parse($base));
     $this->router->addRoute('chain', $chain);
     $this->assertEquals('http://test.example.com/~users/public/www/company/123', $this->router->assembly(array('subdomain' => 'test', 'id' => 123), 'chain'));
 }
 public function testPartialMatch()
 {
     $this->markTestSkipped('Route features not ready');
     $route = RouterTransparentRule::create(':lang/:temp')->setDefaults(array('lang' => 'pl'))->setRequirements(array('temp' => '\\d+'));
     $values = $route->match($this->buildRequest('http://localhost/en/tmp/ctrl/action/id/1'));
     $this->assertFalse($values);
     $route = RouterTransparentRule::create(':lang/:temp')->setDefaults(array('lang' => 'pl'));
     $values = $route->match($this->buildRequest('http://localhost/en/tmp/ctrl/action/id/1'));
     $this->assertInternalType('array', $values);
     $this->assertEquals('en', $values['lang']);
     $this->assertEquals('tmp', $values['temp']);
     $this->assertEquals(6, $values[null]);
 }
Пример #4
0
<?php

/**
 * $Id$
 **/
require '../../../config.inc.php';
define('DEFAULT_CONTROLLER', 'main');
try {
    $request = HttpRequest::create()->setGet($_GET)->setPost($_POST)->setCookie($_COOKIE)->setServer($_SERVER)->setFiles($_FILES);
    $controllerName = DEFAULT_CONTROLLER;
    RouterRewrite::me()->setBaseUrl(HttpUrl::create()->parse(PATH_WEB))->addRoute('default', RouterTransparentRule::create(':area/*')->setDefaults(array('area' => DEFAULT_CONTROLLER)))->route($request);
    if ($request->hasGetVar('area') && ClassUtils::isClassName($_GET['area']) && defined('PATH_CONTROLLERS') && is_readable(PATH_CONTROLLERS . $request->getGetVar('area') . EXT_CLASS)) {
        $controllerName = $request->getGetVar('area');
    } elseif ($request->hasAttachedVar('area') && ClassUtils::isClassName($request->getAttachedVar('area')) && defined('PATH_CONTROLLERS') && is_readable(PATH_CONTROLLERS . $request->getAttachedVar('area') . EXT_CLASS)) {
        $controllerName = $request->getAttachedVar('area');
    }
    $controller = new $controllerName();
    $modelAndView = $controller->handleRequest($request);
    $view = $modelAndView->getView();
    $model = $modelAndView->getModel();
    $prefix = PATH_WEB . '?area=';
    if (!$view) {
        $view = $controllerName;
    } elseif (is_string($view) && $view == 'error') {
        $view = new RedirectView($prefix);
    } elseif ($view instanceof RedirectToView) {
        $view->setPrefix($prefix);
    }
    if (!$view instanceof View) {
        $viewName = $view;
        $view = PhpViewResolver::create(PATH_TEMPLATES, EXT_TPL)->resolveViewName($viewName);