Concrete classes for Doctrine ORM
September 7, 2016 ยท View on GitHub
This page lists some example implementations of FOSMessageBundle models for the Doctrine ORM.
Given the examples below with their namespaces and class names, you need to configure FOSMessageBundle to tell them about these classes.
Add the following to your app/config/config.yml file.
# app/config/config.yml
fos_message:
db_driver: orm
thread_class: AppBundle\Entity\Thread
message_class: AppBundle\Entity\Message
Continue with the installation
Message class
<?php
// src/AppBundle/Entity/Message.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use FOS\MessageBundle\Entity\Message as BaseMessage;
/**
* @ORM\Entity
*/
class Message extends BaseMessage
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(
* targetEntity="AppBundle\Entity\Thread",
* inversedBy="messages"
* )
* @var \FOS\MessageBundle\Model\ThreadInterface
*/
protected $thread;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @var \FOS\MessageBundle\Model\ParticipantInterface
*/
protected $sender;
/**
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\MessageMetadata",
* mappedBy="message",
* cascade={"all"}
* )
* @var MessageMetadata[]|Collection
*/
protected $metadata;
}
MessageMetadata class
<?php
// src/AppBundle/Entity/MessageMetadata.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\MessageBundle\Entity\MessageMetadata as BaseMessageMetadata;
/**
* @ORM\Entity
*/
class MessageMetadata extends BaseMessageMetadata
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(
* targetEntity="AppBundle\Entity\Message",
* inversedBy="metadata"
* )
* @var \FOS\MessageBundle\Model\MessageInterface
*/
protected $message;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @var \FOS\MessageBundle\Model\ParticipantInterface
*/
protected $participant;
}
Thread class
<?php
// src/AppBundle/Entity/Thread.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use FOS\MessageBundle\Entity\Thread as BaseThread;
/**
* @ORM\Entity
*/
class Thread extends BaseThread
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @var \FOS\MessageBundle\Model\ParticipantInterface
*/
protected $createdBy;
/**
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\Message",
* mappedBy="thread"
* )
* @var Message[]|Collection
*/
protected $messages;
/**
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\ThreadMetadata",
* mappedBy="thread",
* cascade={"all"}
* )
* @var ThreadMetadata[]|Collection
*/
protected $metadata;
}
ThreadMetadata class
<?php
// src/AppBundle/Entity/ThreadMetadata.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\MessageBundle\Entity\ThreadMetadata as BaseThreadMetadata;
/**
* @ORM\Entity
*/
class ThreadMetadata extends BaseThreadMetadata
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(
* targetEntity="AppBundle\Entity\Thread",
* inversedBy="metadata"
* )
* @var \FOS\MessageBundle\Model\ThreadInterface
*/
protected $thread;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @var \FOS\MessageBundle\Model\ParticipantInterface
*/
protected $participant;
}