This bundle depends on faye-app.
composer require cravler/faye-app-bundle:4.x-dev
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
This bundle should be automatically enabled by Flex.
In case you don't use Flex, you'll need to manually enable the bundle by
adding the following line in the config/bundles.php file of your project:
<?php
// config/bundles.php
return [
// ...
Cravler\FayeAppBundle\CravlerFayeAppBundle::class => ['all' => true],
];
# config/routes.yaml
cravler_faye_app:
resource: "@CravlerFayeAppBundle/Resources/config/routing.php"
To include the relevant javascript libraries necessary for FayeApp, add these to your root layout file.
<!-- .../Acme/DemoBundle/Resources/views/layout.html.twig -->
<script type="text/javascript" src="..."></script>
{{ faye_app_javascript() }}
<?php
// .../Acme/DemoBundle/EntryPoint/Example.php
namespace Acme\DemoBundle\EntryPoint;
use Cravler\FayeAppBundle\EntryPoint\AbstractEntryPoint;
class Example extends AbstractEntryPoint
{
public function getId(): string
{
return 'acme-demo.example';
}
}
<!-- .../Acme/DemoBundle/Resources/config/services.xml -->
<services>
...
<service id="Acme\DemoBundle\EntryPoint\Example"
autoconfigure="true"
autowire="true"
public="false"
/>
...
</services>
<script type="text/javascript">
var exampleEntryPoint = FayeApp.createEntryPoint('acme-demo.example');
var subscription = exampleEntryPoint.subscribe('/foo', function(message) {
console.log('[foo] Handle message: ', message);
});
subscription.then(function() {
console.log('[foo] Subscription is now active!');
}, function(error) {
console.log('[foo] Subscription problem: ' + error.message);
});
</script>
<script type="text/javascript">
var exampleEntryPoint = FayeApp.createEntryPoint('acme-demo.example');
var publication = exampleEntryPoint.publish('/foo', { text: 'Hi there' });
publication.then(function() {
console.log('[foo] Message received by server!');
}, function(error) {
console.log('[foo] There was a problem: ' + error.message);
});
</script>
The default configuration for the bundle looks like this:
cravler_faye_app:
example: false
user_provider: false #security.user.provider.concrete.[provider_name]
route_url_prefix: /faye-app
use_request_uri: false
secret: ThisTokenIsNotSoSecretChangeIt
app:
scheme: ~
host: 127.0.0.1
port: ~
mount: /pub-sub
options: {}
This bundle is under the MIT license. See the complete license in the bundle:
LICENSE
How can I help you explore Laravel packages today?