/** * onBeforeRouting * * @param Event $event * * @return void * * @throws \Exception */ public function onBeforeRouting(Event $event) { $app = Ioc::getApplication(); $uri = $app->initUri(); $uri = new Uri(strtolower($uri->full)); $host = $uri->getHost(); $host = explode('.', $host); array_pop($host); array_pop($host); $alias = implode('.', $host); $alias = trim(str_replace('.', '', $alias)); // If is main domain but logged in, go to admin if (!$alias && UserHelper::isLogin()) { $app->set('client', 'admin'); return; } // Has subdomain, means it is users' blog if ($alias) { $blogMapper = new DataMapper('blogs'); $blog = $blogMapper->findOne(['alias' => $alias]); if ($blog->isNull()) { throw new \Exception('Blog not found', 404); } Ioc::getContainer('front')->set('current.blog', $blog); $app->set('client', 'front'); return; } // Main domain, got to site $app->set('client', 'site'); }
/** * Method to test match(). * * @param string $url * @param string $pattern * @param string $method * @param boolean $expected * @param integer $line * * @return void * * @covers Windwalker\Router\Route::match * * @dataProvider matchCases */ public function testMatch($url, $pattern, $method, $expected, $line) { $uri = new Uri($url); $host = $uri->getHost(); $scheme = $uri->getScheme(); $port = $uri->getPort() ?: 80; $config = array('name' => 'flower', 'pattern' => $pattern, 'variables' => array('_controller' => 'FlowerController', 'id' => 1), 'method' => array('GET', 'PUT'), 'host' => 'windwalker.com', 'scheme' => 'http', 'port' => 80, 'sslPort' => 443, 'requirements' => array('id' => '\\d+')); $route = new \Windwalker\Router\Route($config['name'], $config['pattern'], $config['variables'], $config['method'], $config); $result = $this->instance->setRoutes(array($route))->match($uri->getPath(), $method, array('host' => $host, 'scheme' => $scheme, 'port' => $port)); $this->assertEquals($expected, !empty($result), 'Match fail, case on line: ' . $line); }
/** * Test the setHost method. * * @return void * * @since 1.0 * @covers Windwalker\Uri\Uri::setHost */ public function testSetHost() { $this->object->setHost('www.example.org'); $this->assertThat($this->object->getHost(), $this->equalTo('www.example.org')); }