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

Support invokable controllers #51

Closed

Conversation

kick-the-bucket
Copy link

Currently @Breadcrumb annotations are not read from invokable Controllers:

/**
 * @Breadcrumb("parent")
 */
class CallableController
{
    /**
     * @Breadcrumb("child")
     */
    public function __invoke()
    {
    }
}

@kick-the-bucket
Copy link
Author

@rvanlaak please review

composer.json Outdated
"doctrine/annotations": "^v1.7",
"doctrine/cache": "^v1.0",
"symfony/twig-bundle": "^3.4|^4.0|^5.0",
"symfony/browser-kit": "^3.4|^4.0|^5.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this dev requirement needed because of the tests? Can we prevent this from being added?

Copy link
Author

Choose a reason for hiding this comment

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

Removed, not sure why I added it

Copy link
Author

Choose a reason for hiding this comment

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

There's some Symfony dependency injection bug which prevents auto-wiring the FrameworkBundle in the older versions and I'm not sure when it was fixed. On the other hand, I'm not sure if I really need the framework bundle to run the tests

Copy link
Author

Choose a reason for hiding this comment

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

Got around it by disabling autoconfigure and autowire in src/Resources/config/services.xml

@@ -48,7 +48,7 @@ public function __construct(Reader $reader, Trail $breadcrumbTrail)
public function onKernelController(KernelEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
$controller = [$controller, '__invoke'];
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if controller isn't an array, but is something different as a callable?

Would an early return in case it isn't callable make sense?

if (!is_callable($controller)) {
    return;
}

Copy link
Author

Choose a reason for hiding this comment

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

Both constructor and setter for both events have callable type-hint for $controller, so I guess there isn't any point in such a check

Copy link
Collaborator

Choose a reason for hiding this comment

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

The check wouldn't be needed for $controller, but on the combination of [$controller, '__invoke'] as not every controller does implement that.

Copy link
Author

Choose a reason for hiding this comment

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

Added more callable type checks for what can not be handled with Doctrine annotation reader along with this check

@kick-the-bucket
Copy link
Author

The "suggest" section in composer.json can probably be amended in the same way as I did with "require-dev" in regards to "doctrine-bundle" - it's a real overkill to install the whole bundle just for the annotation reader/parser.

@kick-the-bucket
Copy link
Author

@rvanlaak what do you think about changing the "suggests" as well?

@rvanlaak
Copy link
Collaborator

@kick-the-bucket can you rebase on master?

@kick-the-bucket
Copy link
Author

kick-the-bucket commented Nov 23, 2020 via email

@rvanlaak rvanlaak added this to the 1.7 milestone Nov 15, 2021
@rvanlaak
Copy link
Collaborator

@kick-the-bucket thank you a lot for your PR, it was the inspiration for me in creating a simplified version in #71 Let me know what you think of the implementation!

Will merge the other PR for now and close this PR, so we can soon release v1.7 that supports invokable controllers.

@rvanlaak rvanlaak closed this Nov 16, 2021
@kick-the-bucket
Copy link
Author

Took some 16 months, but I guess better late, than never, right? 😅

@rvanlaak
Copy link
Collaborator

Did release v1.7.0-beta.1. Any chance to test it as well? That way we can move to a stable next release asap.

@kick-the-bucket
Copy link
Author

I have changed jobs and am no longer using this bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants