Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static routes #101

Merged
merged 4 commits into from Apr 1, 2021
Merged

Add static routes #101

merged 4 commits into from Apr 1, 2021

Conversation

yiiliveext
Copy link
Contributor

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues #100

@Mister-42
Copy link

Mister-42 commented Mar 29, 2021

Wouldn't Route::static make more sense? Since those will not be handled by Yii, Route::get is actually not the proper call.

@yiiliveext
Copy link
Contributor Author

Wouldn't Route::static make more sense?

What do you mean?
The example from your issue

//Assets for urlGenerator, requests will not be handled by Yii
    Route::get('/images/{file}')
        ->static() 
        ->host($appParams->assetDomain)
        ->name('img'),

That's all. You can use static routes in a common routes file/array.

@Mister-42
Copy link

I meant

    //Assets for urlGenerator, requests will not be handled by Yii
    Route::static('/images/{file}')
        ->host($appParams->assetDomain)
        ->name('img'),

Sorry, I commented without enough information.

@yiiliveext
Copy link
Contributor Author

yiiliveext commented Mar 29, 2021

I meant

    //Assets for urlGenerator, requests will not be handled by Yii
    Route::static('/images/{file}')
        ->host($appParams->assetDomain)
        ->name('img'),

Sorry, I commented without enough information.

Maybe it makes sense. Need a review from more devs.

@samdark
Copy link
Member

samdark commented Mar 29, 2021

There was an ability to make URL rule with matching only or generation only in Yii 2: https://github.com/yiisoft/yii2/blob/master/framework/web/UrlRule.php#L38

I haven't personally used it myself so I'm not sure about use cases.

@yiiliveext
Copy link
Contributor Author

I meant

    //Assets for urlGenerator, requests will not be handled by Yii
    Route::static('/images/{file}')
        ->host($appParams->assetDomain)
        ->name('img'),

Done

Route::static('/')->middleware(fn () => 1);
}

public function testStaticFailWihAddAction(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testStaticFailWihAddAction(): void
public function testStaticFailWithAddAction(): void

src/Route.php Outdated
*
* @return self
*/
public static function static(string $pattern): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for a separate method. Generation-only route is the one that doesn't have action.

@samdark samdark merged commit bd7f133 into yiisoft:master Apr 1, 2021
@samdark
Copy link
Member

samdark commented Apr 1, 2021

👍

samdark pushed a commit to yiisoft/router-fastroute that referenced this pull request Apr 1, 2021
real-master-100 pushed a commit to real-master-100/router-yii that referenced this pull request Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants