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

[FrameworkBundle] Improve the DX of TemplateController when using SF 4 #24637

Merged
merged 1 commit into from
Dec 4, 2017

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Oct 19, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR symfony/symfony-docs#10320

Tiny DX improvement when using modern Symfony.

Allow to write:

# config/routes.yaml
index:
    path: /
    defaults:
      _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController'
      template: 'homepage.html.twig'

Instead of:

index:
    path: /
    defaults:
      _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction'
      template: 'homepage.html.twig'

I was thinking about doing the same for RedirectController, but it's not that easy because it contains two methods.

@chalasr chalasr added this to the 3.4 milestone Oct 19, 2017
@fabpot
Copy link
Member

fabpot commented Oct 20, 2017

Moving to 4.1. 3.4 is closed for new features.

@fabpot fabpot modified the milestones: 3.4, 4.1 Oct 20, 2017
@derrabus
Copy link
Member

@dunglas Inside a RedirectController::__invoke(), you could check if either the attribute route or path has been set on the request and call the corresponding action.

@@ -91,4 +91,9 @@ public function templateAction($template, $maxAge = null, $sharedAge = null, $pr

return $response;
}

public function __invoke($template, $maxAge = null, $sharedAge = null, $private = null)
Copy link
Member

Choose a reason for hiding this comment

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

we can now use PHP 7.1 features here

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@dunglas dunglas changed the base branch from 3.4 to master December 1, 2017 18:48
@dunglas dunglas force-pushed the invokable-template-controller branch 2 times, most recently from dbbf3c1 to c14786b Compare December 1, 2017 18:55
@dunglas dunglas force-pushed the invokable-template-controller branch from c14786b to 6d15055 Compare December 1, 2017 18:56
@dunglas
Copy link
Member Author

dunglas commented Dec 1, 2017

Failure not related

@Tobion
Copy link
Contributor

Tobion commented Dec 4, 2017

Thank you @dunglas.

@Tobion Tobion merged commit 6d15055 into symfony:master Dec 4, 2017
Tobion added a commit that referenced this pull request Dec 4, 2017
… when using SF 4 (dunglas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[FrameworkBundle] Improve the DX of TemplateController when using SF 4

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Tiny DX improvement when using modern Symfony.

Allow to write:

```yaml
# config/routes.yaml
index:
    path: /
    defaults:
      _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController'
      template: 'homepage.html.twig'
```

Instead of:

```yaml
index:
    path: /
    defaults:
      _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction'
      template: 'homepage.html.twig'
```
I was thinking about doing the same for `RedirectController`, but it's not that easy because it contains two methods.

Commits
-------

6d15055 [FrameworkBundle] Improve the DX of TemplateController when using SF 4
fabpot added a commit that referenced this pull request Jan 19, 2018
This PR was merged into the 4.1-dev branch.

Discussion
----------

[DI] Allow for invokable event listeners

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

Inspired by #24637 / #25259. This adds invokable support for event listeners :)

```yaml
Some\Foo:
    tags: [{ name: kernel.event_listener, event: kernel.request }]
```

```php
class Foo {
    public function __invoke(GetResponseEvent $event) { }
}
```

Commits
-------

fa5b7eb [DI] Allow for invokable event listeners
@fabpot fabpot mentioned this pull request May 7, 2018
@dunglas dunglas deleted the invokable-template-controller branch September 10, 2018 20:41
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Sep 11, 2018
…dunglas)

This PR was merged into the 4.1 branch.

Discussion
----------

[FrameworkBundle] Improve the DX of TemplateController

symfony/symfony#24637

Commits
-------

fca1a5b [FrameworkBundle] Improve the DX of TemplateController
yceruto added a commit that referenced this pull request Aug 23, 2019
…en using RedirectController (yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[FrameworkBundle][DX] Improving the redirect config when using RedirectController

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#12189

follow-up #24637

**Before:**
```yaml
# config/routes.yaml
doc_shortcut:
    path: /doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
    defaults:
        route: 'doc_page'

legacy_doc:
    path: /legacy/doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
    defaults:
        path: 'https://legacy.example.com/doc'
```

**After:**
```yaml
# config/routes.yaml
doc_shortcut:
    path: /doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
    defaults:
        route: 'doc_page'

legacy_doc:
    path: /legacy/doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
    defaults:
        path: 'https://legacy.example.com/doc'
```

See more before/after configs (XML, PHP) in doc PR symfony/symfony-docs#12189

Commits
-------

0ebb469 Improving redirect config when using RedirectController
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Aug 23, 2019
…en using RedirectController (yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[FrameworkBundle][DX] Improving the redirect config when using RedirectController

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#12189

follow-up symfony/symfony#24637

**Before:**
```yaml
# config/routes.yaml
doc_shortcut:
    path: /doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
    defaults:
        route: 'doc_page'

legacy_doc:
    path: /legacy/doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
    defaults:
        path: 'https://legacy.example.com/doc'
```

**After:**
```yaml
# config/routes.yaml
doc_shortcut:
    path: /doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
    defaults:
        route: 'doc_page'

legacy_doc:
    path: /legacy/doc
    controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
    defaults:
        path: 'https://legacy.example.com/doc'
```

See more before/after configs (XML, PHP) in doc PR symfony/symfony-docs#12189

Commits
-------

0ebb469 Improving redirect config when using RedirectController
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.