Simple list of commands to get setup quickly (perhaps not ideally) with FOSMessageBundle and FOSUserBundle, also includes config notes and doctrine entites.
The aim is to test the bundle for stability, not build a scalable web app.
FOSMessageBundle - https://github.com/FriendsOfSymfony/FOSMessageBundle
To be ran from a Symfony project - https://symfony.com/doc/current/setup.html
composer install
composer require --dev symfony/browser-kit symfony/css-selector symfony/phpunit-bridge symfony/maker-bundle symfony/web-server-bundle
composer require doctrine/doctrine-bundle doctrine/orm symfony/translation swiftmailer-bundle
composer require friendsofsymfony/user-bundle "~2.0"
composer require friendsofsymfony/message-bundle dev-master
parameters:
mailer_user: '%env(MAILERUSER)%'
locale: 'en'
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: App\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
fos_message:
db_driver: orm
thread_class: App\Entity\Thread
message_class: App\Entity\Message
Add at bottom
templating:
engines:
twig
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
fos_message:
resource: "@FOSMessageBundle/Resources/config/routing.xml"
prefix: /messaging
security:
# https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_MOD: ROLE_USER
ROLE_ADMIN: ROLE_MOD
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
in_memory: { memory: ~ }
fos_userbundle:
id: fos_user.user_provider.username_email
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register$, role: IS_AUTHENTICATED_ANONYMOUSLY }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
provider: in_memory
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
remember_me: true
logout: true
anonymous: true
remember_me:
secret: '%kernel.secret%'
lifetime: 604800 # 1 week in seconds
path: /
domain: ~
#anonymous: ~
# activate different ways to authenticate
# http_basic: ~
# https://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
# form_login: ~
# https://symfony.com/doc/current/cookbook/security/form_login_setup.html
Just make sure that DATABASE_URL
, MAILER_URL
are setup and MAILERUSER
is too.
DATABASE_URL=mysql://users:password@127.0.0.1:3306/db_name
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
MAILERUSER='test@test.com'
###< symfony/swiftmailer-bundle ###
Copy the php files into your src/Entity
folder, then run the following doctrine commands:
php bin/console doctrine:database:create
php bin/console make:migration
php bin/console doctrine:migrations:migrate
Create two users:
php bin/console fos:user:create test test@example.com p@ssword
php bin/console fos:user:create test2 test@example.com p@ssword
Run your project (and clear the cache):
php bin/console cache:clear
php bin/console server:run
The project won't have any CSS at all so use these urls to navigate:
- http://127.0.0.1:8000/login
- http://127.0.0.1:8000/logout
- http://127.0.0.1:8000/messaging
- http://127.0.0.1:8000/messaging/new
To run the tests:
php bin/phpunit vendor/friendsofsymfony/message-bundle/Tests