Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Mercure] Add the component#28877
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
javiereguiluz commentedOct 15, 2018
If this component is accepted, I wonder if we should rename it to a more generic name describing its purpose instead of using the name of the provider used. Laravel for example calls this "Broadcasting" and Rails calls it "ActionCable". Thanks! |
dunglas commentedOct 15, 2018
@javiereguiluz actually, this is not an abstraction layer but an implementation of the protocol (like HttpFoundation implements the HTTP protocol or WebLink implements Web Linking). |
| </xsd:complexType> | ||
| <xsd:complexTypename="mercure_hub"> | ||
| <xsd:attributename="name"type="xsd:string" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
that one should be marked as required, as it is the key in the map
| <xsd:complexTypename="mercure_hub"> | ||
| <xsd:attributename="name"type="xsd:string" /> | ||
| <xsd:attributename="url"type="xsd:string"use="required" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
that one should not be required, as it is not required in all XML files being merged together (it is required in the merged config, not in each source config)
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsdShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| private$jwtProvider; | ||
| private$httpClient; | ||
| publicfunction__construct(string$publishEndpoint,callable$jwtProvider,callable$httpClient =null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I suggest adding some phpdoc describing the expected signature of these callables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Possibly in the format used by Psalm and PHPStan IIRC which have the most chance becoming the standard.
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsdShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
s7anley commentedOct 23, 2018
I'm just curious why Mercure should be part of Framework bundle? Why not integrate it by own bundle? |
dunglas commentedOct 23, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@s7anley I've no strong opinion about that. I added it to FrameworkBundle because it's what we do most of the time, but not all times (SecurityBundle, WebServerBundle...). Extracting it in a custom bundle will also allow to extract the library out of |
dunglas commentedOct 28, 2018
The component, and the related bundle, are now available as standalone packages: |
Uh oh!
There was an error while loading.Please reload this page.
Last week, I introducedthe Mercure protocol as well asa reference implementation of a mercure hub.
Mercure allows to push updates from servers to clients, through a hub. It usesserver-sent events, so it passes through all firewalls, works even with very old browsers, is super efficient when using HTTP/2 and is natively supported in all major browsers (no SDK required).Try the demo.
For instance, Mercure allows to automatically and instantly update all currently connected clients (web apps, mobile apps...) every time a resource is modified, created or deleted (e.g. when a
POSTrequest occurs).This PR introduce a new component, allowing to use Mercure in Symfony projects in a very convenient way.
Minimal example
Here we use the Messenger component to dispatch the update. It means that the request to the Mercure hub can be sent synchronously (by default), or asynchronously in a worker if you configure a transport such as RabbitMQ or Reddis.
The corresponding config:
Subscribing to several topics
Mercure allows to subscribe to several topics, and to topics matching a given pattern:
Making the Hub auto-discoverable
Mercure can leverage the web linking RFC to advertise available hubs to the clients:
In the previous example, the Symfony WebLink Component is used to generate the appropriate
Linkheader. The hub can then be discovered usingsome lines of JS.Requires#28875.
Authorization
Mercure also allows to securely dispatch updates only to users having a specific username, role or group... you name it. To do so, you just have to set a JSON Web Token containing the list of targets in a claim named
mercureTargets. This token must be stored in a cookie namedmercureAuthorization(the protocol also allows to transmit the JWT using OAuth, OpenID Connect, and any other transport).That's all! Only users having one of the specified targets will receive the update. In this example,
lcobucci/jwtis used, but feel free to use any other library to generate the token.To use the authorization feature, the hub and the Symfony app must be served from the same domain name (can be different subdomains).