btba / chat-bundle
Chat generator for Symfony applications
Installs: 34
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 18
Language:CSS
Type:symfony-bundle
Requires
- php: ^7.1.3
- liip/imagine-bundle: ^2.1
- symfony/dependency-injection: ^4.2|^5.0
- symfony/form: ^4.2|^5.0
- symfony/framework-bundle: ^4.0
- symfony/http-kernel: ^4.3.7|^5.0
- symfony/translation: ^4.2|^5.0
- symfony/twig-bridge: ^4.2|^5.0
- symfony/twig-bundle: ^4.2|^5.0
- symfony/webpack-encore-bundle: ^1.7
- symfony/yaml: ^4.0
- twig/twig: ^2.11.3|^3.0
- vich/uploader-bundle: ^1.8
Requires (Dev)
- symfony/browser-kit: ^4.4
- symfony/phpunit-bridge: ^5.0
- dev-master
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/terser-4.8.1
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/tar-4.4.19
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.8
- dev-dependabot/npm_and_yarn/websocket-extensions-0.1.4
- dev-dependabot/npm_and_yarn/jquery-3.5.0
- dev-dependabot/npm_and_yarn/acorn-6.4.1
This package is auto-updated.
Last update: 2025-03-05 07:37:34 UTC
README
Welcome to the chat bundle project !
This project aim to offer a simple chat service to any symfony application.
installation
As this project is very new, we decided not to add a receipe on Symfony Flex at the moment so the configuration must be performed manually.
register
First install the dependencies by running this comand in your repository
composer require btba/chat-bundle
and register the bundle
// config/bundles.php return [ //your bundles Btba\ChatBundle\BtbaChatBundle::class => ['all' => true] ];
config
then in your app directory add a config file. The following parameters are mandatory:
# config/packages/btba_chat.yaml btba_chat: update_interval: 1000 message_class: App\Entity\ChatMessage author_class: App\Entity\User
update_interval
refers to the time between two refresh of the chat
message_class
refers to the ORM class that host the messages (Doctrine supported)
author_class
refers to the ORM class that host the auhors (Doctrine supported)
Then register the bundle routes and change the prefix
according to your needs
# config/routes/btba_chat.yaml btba_chat: resource: '@BtbaChatBundle/Resources/config/routes.yaml' prefix: /chat-bundle/
database
In order to save authors and messages in your database you need to create at least two classes that extends the bundle model as such:
// App\Entity\User /** * @ORM\Entity(repositoryClass="App\Repository\UserRepository") */ class User extends BaseAuthor implements UserInterface { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ protected $id; /** * @ORM\Column(type="string", length=180, unique=true) */ protected $username; /** * @ORM\OneToMany(targetEntity="App\Entity\ChatMessage", mappedBy="author", cascade={"persist"}, orphanRemoval=true) */ private $messages;
// App\Entity\ChatMesssage namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Btba\ChatBundle\Model\BaseChatMessage; /** * @ORM\Entity(repositoryClass="App\Repository\ChatMessageRepository") */ class ChatMessage extends BaseChatMessage { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ protected $id; /** * @ORM\Column(type="string", length=255) */ protected $content; /** * @ORM\Column(type="datetime") */ protected $date; /** * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="messages", cascade={"persist"}) * @ORM\JoinColumn(nullable=false) */ protected $author; }
and in the message_class
repository add the following trait:
// src/Repository/ChatMessageRepository.php namespace App\Repository; use Btba\ChatBundle\Query\MessageQuery; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; class ChatMessageRepository extends ServiceEntityRepository { use MessageQuery; //your code... }
configuration is over you are good to go !
usage
To use this bundle, you need to add several component to your views.
If you're using encore, add the following assets to you're app.css
file
@import '../../vendor/btba/chat-bundle/assets/css/chat.css';
and app.js
file
import * as chat from '../../vendor/btba/chat-bundle/assets/js/chat'; //functions for the chat window management $(function(){ $("#chevron").click(function(e) { chat.changeChevron(e.target); }); $("#chat-submit").click(function(e) { chat.submitChat(e); }); });
in your view you now just have to render the following controller:
{{ render(controller('Btba\\ChatBundle\\Controller\\ChatController::show')) }}