本文整理汇总了PHP中lithium\net\http\Router::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::connect方法的具体用法?PHP Router::connect怎么用?PHP Router::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\net\http\Router
的用法示例。
在下文中一共展示了Router::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
Router::reset();
foreach ($this->_routes as $route) {
Router::connect($route);
}
}
示例2: tearDown
/**
* Clean up after the test.
*
* @return void
*/
public function tearDown()
{
Router::connect(null);
$this->_routes->each(function ($route) {
Router::connect($route);
});
unset($this->html);
}
示例3: teardown
function teardown()
{
Router::reset();
foreach ($this->_routes as $route) {
Router::connect($route);
}
unset($this->analytics);
}
示例4: setUp
public function setUp()
{
$this->html = new Html();
$this->mock = new MockHtml();
Router::connect('/test/{:args}', array('controller' => '\\lithium\\test\\Controller'));
Router::connect('/test', array('controller' => '\\lithium\\test\\Controller'));
$this->request = new Request(array('base' => null, 'env' => array('PHP_SELF' => '/', 'DOCUMENT_ROOT' => '/')));
}
示例5: setUp
/**
* Initialize test by creating a new object instance with a default context.
*/
public function setUp()
{
Router::connect('/{:controller}/{:action}/{:args}');
$this->request = new Request();
$this->request->params = ['controller' => 'post', 'action' => 'index'];
$this->request->persist = ['controller'];
$this->context = new MockRenderer(['request' => $this->request]);
}
示例6: testRun
public function testRun()
{
Router::connect('/', array('controller' => 'test', 'action' => 'test'));
$request = new Request();
$request->url = '/';
MockDispatcher::run($request);
$result = end(MockDispatcher::$dispatched);
$expected = array('controller' => 'test', 'action' => 'test');
$this->assertEqual($expected, $result->params);
}
示例7: setUp
/**
* Initialize test by creating a new object instance with a default context.
*/
public function setUp()
{
Router::connect('/{:controller}/{:action}/{:id}.{:type}', array('id' => null));
Router::connect('/{:controller}/{:action}/{:args}');
$request = new Request();
$request->params = array('controller' => 'posts', 'action' => 'index');
$request->persist = array('controller');
$this->context = new MockFormRenderer(compact('request'));
$this->form = new Form(array('context' => $this->context));
$this->base = $this->context->request()->env('base') . '/';
}
示例8: setUp
public function setUp()
{
$this->_routes = Router::get();
Router::reset();
Router::connect('/{:controller}/{:action}/page/{:page:[0-9]+}');
$request = new Request();
$request->params = array('controller' => 'posts', 'action' => 'index');
$request->persist = array('controller');
$this->context = new MockRenderer(compact('request'));
$this->pagination = new Pagination(array('context' => $this->context));
}
示例9: testConfigManipulation
public function testConfigManipulation()
{
$config = MockDispatcher::config();
$expected = array('rules' => array());
$this->assertEqual($expected, $config);
MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
MockDispatcher::run(new Request(array('url' => '/')));
$result = end(MockDispatcher::$dispatched);
$expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
$this->assertEqual($expected, $result->params);
}
示例10: tearDown
/**
* Clean up after the test.
*/
public function tearDown()
{
Router::reset();
foreach ($this->_routes as $scope => $routes) {
Router::scope($scope, function () use($routes) {
foreach ($routes as $route) {
Router::connect($route);
}
});
}
unset($this->html);
}
示例11: testUrlAutoEscaping
/**
* Tests that URLs are properly escaped by the URL handler.
*/
public function testUrlAutoEscaping()
{
Router::connect('/{:controller}/{:action}/{:id}');
$this->assertEqual('/<foo>/<bar>', $this->subject->url('/<foo>/<bar>'));
$result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
$this->assertEqual('/controller/action/<script />', $result);
$this->subject = new Simple(array('response' => new Response(), 'view' => new View(), 'request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local')))));
$this->assertEqual('/<foo>/<bar>', $this->subject->url('/<foo>/<bar>'));
$result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
$this->assertEqual('/controller/action/<script />', $result);
$result = $this->subject->url(array('Posts::index', '?' => array('foo' => 'bar', 'baz' => 'dib')));
$this->assertEqual('/posts?foo=bar&baz=dib', $result);
}
示例12: _restoreCtrlContext
protected function _restoreCtrlContext()
{
Router::reset();
foreach ($this->_context['routes'] as $scope => $routes) {
Router::scope($scope, function () use($routes) {
foreach ($routes as $route) {
Router::connect($route);
}
});
}
foreach ($this->_context['scopes'] as $scope => $attachment) {
Router::attach($scope, $attachment);
}
Router::scope($this->_context['scope']);
}
示例13: array
// TODO: See why this isn't catching in the Minerva library routes...
// This should already be set...
Router::connect('/minerva_gallery/admin/{:controller}/{:action}/{:args}', array('admin' => 'admin', 'library' => 'minerva_gallery', 'controller' => 'items', 'action' => 'index'));
// JSON Routes
Router::connect('/minerva_gallery/{:controller}/{:action}.json', array('library' => 'minerva_gallery', 'controller' => 'items', 'type' => 'json'));
Router::connect('/minerva_gallery/{:controller}/{:action}/{:args}.json', array('library' => 'minerva_gallery', 'controller' => 'items', 'type' => 'json'));
// Route for reading a gallery (note the "document_type" parameter)
Router::connect('/gallery/read/{:url}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'read'));
// Route for listing all galleries
Router::connect('/gallery/index', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
// Pagination for galleries (default limit is 10)
Router::connect('/gallery/index/page:{:page:[0-9]+}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
Router::connect('/gallery/index/page:{:page:[0-9]+}/limit:{:limit:[0-9]+}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
// Yes, you can render "static" pages from the library as well by using the "view" action,
// Templates from: /libraries/minerva_gallery/views/pages/static/template-name.html.php
Router::connect('/gallery', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'view', 'home'));
Router::connect('/gallery/view/{:args}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'view', 'home'));
// NOTE: /gallery route could also be reached via the default Minerva route: /minerva/plugin/minerva_gallery
// Also: /minerva/plugin/minerva_gallery/pages/read/document == /gallery/read/{:url}
// TODO? Do galleries also need comments? Should there be a unified comments library now?
// Router::connect('/gallery/comments/{:action}.json', array('library' => 'minerva_gallery', 'controller' => 'comments', 'type' => 'json'));
// Router::connect('/gallery/comments/{:action}/{:args}.json', array('library' => 'minerva_gallery', 'controller' => 'comments', 'type' => 'json'));
// SWEEPSTAKES LIBRARY SPECIFIC ROUTES (Routed to look like it belongs to Minerva. Library added as with 'minerva_plugin' => true, so it will follow the render paths.)
/*
Router::connect("/minerva/gallery/admin/{:controller}/{:action}/{:url}", array('admin' => 'admin', 'library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
Router::connect("/minerva/gallery/{:controller}/{:action}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
Router::connect("/minerva/gallery/{:controller}/{:action}/{:args}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
Router::connect("/minerva/gallery/{:controller}/{:action}/{:url}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
* */
示例14: testConfigManipulation
public function testConfigManipulation()
{
$config = MockDispatcher::config();
$expected = array('rules' => array());
$this->assertEqual($expected, $config);
MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
MockDispatcher::run(new Request(array('url' => '/')));
$result = end(MockDispatcher::$dispatched);
$expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
$this->assertEqual($expected, $result->params);
MockDispatcher::config(array('rules' => array('action' => array('action' => function ($params) {
return Inflector::camelize(strtolower($params['action']), false);
}))));
MockDispatcher::$dispatched = array();
Router::reset();
Router::connect('/', array('controller' => 'test', 'action' => 'TeST-camelize'));
MockDispatcher::run(new Request(array('url' => '/')));
$result = end(MockDispatcher::$dispatched);
$expected = array('action' => 'testCamelize', 'controller' => 'Test');
$this->assertEqual($expected, $result->params);
MockDispatcher::config(array('rules' => function ($params) {
if (isset($params['admin'])) {
return array('special' => array('action' => 'special_{:action}'));
}
return array();
}));
MockDispatcher::$dispatched = array();
Router::reset();
Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
Router::connect('/special', array('controller' => 'test', 'action' => 'test', 'admin' => true, 'special' => true));
MockDispatcher::run(new Request(array('url' => '/')));
$result = end(MockDispatcher::$dispatched);
$expected = array('action' => 'test', 'controller' => 'Test', 'admin' => true);
$this->assertEqual($expected, $result->params);
MockDispatcher::run(new Request(array('url' => '/special')));
$result = end(MockDispatcher::$dispatched);
$expected = array('action' => 'special_test', 'controller' => 'Test', 'admin' => true, 'special' => true);
$this->assertEqual($expected, $result->params);
}
示例15: array
Router::connect('/{:library}/profile/trace/{:file}', array('file' => 'latest'), function ($request) {
// If for some reason a profile session is active, do NOT run the code in this route.
// It would cause some pretty big issues =)
if (isset($_GET['XDEBUG_PROFILE']) || isset($_COOKIE['XDEBUG_PROFILE'])) {
echo 'You can\'t attempt to get the latest profile information while the profiler is active.';
return false;
}
// webgrind bootstrap/config process
require LITHIUM_APP_PATH . '/libraries/li3_perf/extensions/webgrind/library/bootstrap.php';
$trace_files = FileHandler::getInstance()->getTraceList(1);
if (is_array($trace_files)) {
$dataFile = $trace_files[0]['filename'];
// I've seen this work before and then sometimes not...Sometimes it needs the slash. Weird.
if (!file_exists(Webgrind::$config->xdebugOutputDir . $dataFile)) {
$dataFile = '/' . $dataFile;
}
$costFormat = Webgrind::$config->defaultCostformat;
$reader = FileHandler::getInstance()->getTraceReader($dataFile, $costFormat);
$result = array();
$functions = array();
$shownTotal = 0;
$breakdown = array('internal' => 0, 'procedural' => 0, 'class' => 0, 'include' => 0);
$functionCount = $reader->getFunctionCount();
$result['moodpik'] = array('function_calls' => 0, 'total_cost' => 0);
for ($i = 0; $i < $functionCount; $i++) {
$functionInfo = $reader->getFunctionInfo($i);
//var_dump($functionInfo['functionName']);
if (strstr($functionInfo['functionName'], 'moodpik\\')) {
$result['moodpik']['function_calls']++;
$result['moodpik']['total_cost'] += $functionInfo['summedSelfCost'];
}
$isInternal = strpos($functionInfo['functionName'], 'php::') !== false;
if ($isInternal) {
if (get('hideInternals', false)) {
continue;
}
$breakdown['internal'] += $functionInfo['summedSelfCost'];
$humanKind = 'internal';
} elseif (false !== strpos($functionInfo['functionName'], 'require_once::') || false !== strpos($functionInfo['functionName'], 'require::') || false !== strpos($functionInfo['functionName'], 'include_once::') || false !== strpos($functionInfo['functionName'], 'include::')) {
$breakdown['include'] += $functionInfo['summedSelfCost'];
$humanKind = 'include';
} elseif (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
$breakdown['class'] += $functionInfo['summedSelfCost'];
$humanKind = 'class';
} else {
$breakdown['procedural'] += $functionInfo['summedSelfCost'];
$humanKind = 'procedural';
}
$shownTotal += $functionInfo['summedSelfCost'];
$functions[$i] = $functionInfo;
$functions[$i]['nr'] = $i;
$functions[$i]['humanKind'] = $humanKind;
}
usort($functions, 'costCmp');
$remainingCost = $shownTotal * get('showFraction');
$result['functions'] = array();
foreach ($functions as $function) {
$remainingCost -= $function['summedSelfCost'];
$function['file'] = urlencode($function['file']);
$result['functions'][] = $function;
if ($remainingCost < 0) {
break;
}
}
$result['summedInvocationCount'] = $reader->getFunctionCount();
$result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
$result['dataFile'] = $dataFile;
$result['invokeUrl'] = $reader->getHeader('cmd');
$result['runs'] = $reader->getHeader('runs');
$result['breakdown'] = $breakdown;
$result['mtime'] = date(Webgrind::$config->dateFormat, filemtime(Webgrind::$config->xdebugOutputDir . '/' . $dataFile));
$creator = preg_replace('/[^0-9\\.]/', '', $reader->getHeader('creator'));
$result['linkToFunctionLine'] = version_compare($creator, '2.1') > 0;
var_dump($result);
exit;
}
});