yiisoft / router-fastroute Goto Github PK
View Code? Open in Web Editor NEWYii Router FastRoute adapter
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
Yii Router FastRoute adapter
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
For example, Route::get('/i/{image}')->name('image')
.
Add into RouterFactory
$router = (new RouterFactory(new FastRouteFactory(), $routes))($container);
$router->addGroup('/blog', static function (RouteCollectorInterface $r) use (&$container) {
$r->addRoute(
Route::get('/index')
->to(new ActionCaller(SiteController::class, 'index', $container))
->name('blog/index')
);
});
return $router;
Go to /blog/index
Response with HTTP 200 and index page
Response with HTTP 405
Works strange with next code:
$router->addGroup('/blog', ... $r->addRoute(Route::get('/') ...) # /blog/
Performs as path /
Good day. After last releases methods generate
and generateAbsolute
was failed on that string $parameters = array_map('\strval', $parameters);
if send multilevel array like this (generated from Yiisoft\Form\FormModel attributes)
[
'Search' => [
'address.with_data' => false
'address.objects.type_ids' => [
0 => '4'
]
'address.objects.is_active' => true
'address.pageData.page.source_ids' => [
0 => '6'
]
]
]
Good afternoon. The basic implementation of UrlGeneratorInterface
lacks parameters for __construct()
. Thanks in advance
Q | A |
---|---|
Version | 1.0.? |
PHP version | |
Operating system |
Test fails:
$urlGenerator = $this->createUrlGenerator([
Route::get('/home/index')->name('index'),
]);
$urlGenerator->setLocaleParameterName('_locale');
$urlGenerator->setLocales(['uz' => 'uz-UZ', 'en' => 'en-US', 'ru' => 'ru-RU']);
$url = $urlGenerator->generate('index', ['_locale' => 'uz']);
$this->assertEquals('/uz/home/index', $url);
Route::get('/articles')->name('article')
$urlGenerator->generate('article', [], ['query' => null])
/articles
/articles?
'?' at the end url
Q | A |
---|---|
Version | 3.0.? |
PHP version | 8.0 |
Operating system | Linux |
Now use yiisoft/router
, should be yiisoft/router-fastroute
.
See docs:
Parameters should be namespaced with
vendor/package-name
config/routes.php
Route::get('/images/{file}')
->name('images')
->host('example.com'),
view
var_dump($url->generateAbsolute('images', ['file' => 'test.png']));
string(29) "//example.com/images/test.png"
string(27) "example.com/images/test.png"
Q | A |
---|---|
Version | dev |
PHP version | 8.0.0 |
Operating system | Debian 10 |
Currently Route's host isn't taken into account when matching. It should be implemented.
See https://github.com/yiisoft/router/blob/master/src/Route.php#L310
Proposal to not add not substituted arguments if they a not in route. I think this not need here, in UrlGenerator::generate()
has the separate argument for query string. If it ok, I can make PR.
router-fastroute/src/UrlGenerator.php
Lines 300 to 303 in 2a570aa
// routes
Route::get('/view/{mode}')->name('view');
$urlGenerator->setDefaultParameter('mode', 'simple');
$urlGenerator->setDefaultParameter('type', 'any');
$urlGenerator->generate('view');
/view/simple
/view/simple?type=any
Q | A |
---|---|
Version | 3.0.0 |
PHP version | 8.0 |
Operating system |
For the code below, I would expect to use the default value when I use NULL when generating.
$routes = [
Route::get('/view/{test:\w+}')->name('view')->defaults([
'test' => 'test'
]),
];
$routerCollector = $this->createRouterCollector($routes);
$url = $routerCollector->generate('view', ['test' => null]);
$this->assertEquals('/view/test', $url);
this would be particularly useful for the following uses:
$url = $routerCollector->generate('view', ['name' => $any->name ?? null]);
success
RuntimeException: Route `view` expects at least parameter values for [test], but received [test]
Q | A |
---|---|
Version | 3.0.x-dev |
PHP version | - |
Operating system | - |
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.