Installation via utils/prepare_vendors script (recommended):
Run the project-specific script to symlink the bundle into /src/Awaresoft.
./utils/prepare_vendors
Verify symlink exists at src/Awaresoft/MessageBundle.
Manual Symlink (if not using the script):
Clone the repo into /vendor/awaresoft/message-bundle and create a symlink:
ln -s /path/to/message-bundle/src/Awaresoft /src/Awaresoft
Register the Bundle in app/AppKernel.php:
new Awaresoft\MessageBundle\AwaresoftMessageBundle(),
First Use Case: Sending a Message
Inject the message.manager service and use the API:
use Awaresoft\MessageBundle\Message\MessageManager;
class MyController extends Controller
{
public function sendMessage(MessageManager $messageManager)
{
$message = $messageManager->createMessage('email');
$message->setTo('user@example.com')
->setSubject('Hello!')
->setBody('Test message');
$messageManager->send($message);
}
}
Message Creation & Dispatch
MessageManager to create and send messages (email, SMS, etc.):
$message = $messageManager->createMessage('email', [
'template' => 'emails/welcome.twig',
'context' => ['name' => 'John']
]);
$messageManager->send($message);
Resources/views/ (e.g., emails/welcome.twig).Queue Integration
awaresoft_message.yml to use Symfony’s Messenger component:
awaresoft_message:
transport: 'doctrine://default'
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
$messageManager->send($message, ['transport' => 'async']);
Event Listeners
MessageSentEvent):
// src/Awaresoft/MessageBundle/EventListener/MyListener.php
class MyListener
{
public function onMessageSent(MessageSentEvent $event)
{
// Log or process sent messages
}
}
services.yml:
services:
my.listener:
class: AppBundle\EventListener\MyListener
tags:
- { name: kernel.event_listener, event: message.sent, method: onMessageSent }
Fixtures & Testing
doctrine-fixtures-bundle to load test messages:
// src/AppBundle/DataFixtures/ORM/LoadMessageFixture.php
public function load(ObjectManager $manager)
{
$message = $this->messageManager->createMessage('email');
$message->setTo('test@example.com');
$manager->persist($message);
$manager->flush();
}
Symlink Breakage
composer update runs, it may overwrite symlinks. Solution:
composer.json and vendor/ before symlinking.composer dump-autoload after changes.Backward Compatibility (BC) Risks
MessageManager) without version bumps.Transport Misconfigurations
awaresoft_message.yml for correct transport DSN.var/log/dev.log).Template Paths
Resources/views/ (not templates/). Fix:
# awaresoft_message.yml
templates_dir: '%kernel.project_dir%/src/Awaresoft/MessageBundle/Resources/views'
Enable Messenger Debugging
Add to config/packages/messenger.yaml:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
routing:
'Awaresoft\MessageBundle\Message\Message': async
Check failed messages in the failed_messages table (Doctrine transport).
Log Events
Enable event logging in config/packages/dev/monolog.yaml:
handlers:
message_events:
type: stream
path: '%kernel.logs_dir%/message_events.log'
channels: ['message']
Common Errors & Fixes
| Error | Solution |
|---|---|
Class not found |
Run composer dump-autoload. |
Template not found |
Verify templates_dir in config. |
Transport not configured |
Check awaresoft_message.yml transport. |
Custom Message Types
Extend Awaresoft\MessageBundle\Message\AbstractMessage:
class CustomMessage extends AbstractMessage
{
protected $customField;
// Add getters/setters
}
Register in services.yml:
services:
custom.message:
class: AppBundle\Message\CustomMessage
tags: ['awaresoft.message.type', { alias: 'custom' }]
Override Templates
Place custom templates in app/Resources/AwaresoftMessageBundle/views/ to override defaults.
Add Transport Adapters
Implement Awaresoft\MessageBundle\Transport\TransportInterface for new transports (e.g., Slack):
class SlackTransport implements TransportInterface
{
public function send(Message $message) { /* ... */ }
}
Register in services.yml:
services:
slack.transport:
class: AppBundle\Transport\SlackTransport
tags: ['awaresoft.message.transport', { alias: 'slack' }]
How can I help you explore Laravel packages today?