Skip to content

Commit

Permalink
Add support of Symfony 3 and drop Symfony < 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalopin committed Sep 4, 2016
1 parent cdfee5e commit 4e6c19e
Show file tree
Hide file tree
Showing 41 changed files with 432 additions and 171 deletions.
51 changes: 33 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
sudo: false

env:
- SYMFONY_VERSION=2.1.*
- SYMFONY_VERSION=2.2.*
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=dev-master
branches:
only:
- master

matrix:
include:
- php: 5.3
env:
- deps=low
- SYMFONY_VERSION=2.7.*
- php: 5.4
env:
- deps=high
- SYMFONY_VERSION=2.7.*
- php: 5.5
env:
- deps=low
- SYMFONY_VERSION=2.8.*
- php: 5.6
env:
- deps=high
- SYMFONY_VERSION=3.0.*
- php: 7.0
env:
- deps=low
- SYMFONY_VERSION=3.1.*
- php: 7.1
env:
- deps=high
- SYMFONY_VERSION=3.1.*

before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
- composer update --dev
- if [[ $deps = high ]]; then composer update --no-progress --ansi; fi
- if [[ $deps = low ]]; then composer update --no-progress --ansi --prefer-lowest --prefer-stable; fi

script: phpunit --coverage-text

notifications:
email:
- [email protected]

matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
- php: 5.6
- php: hhvm
28 changes: 21 additions & 7 deletions Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace FOS\MessageBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\MessageBundle\Provider\ProviderInterface;
use Symfony\Component\HttpFoundation\Response;

class MessageController extends ContainerAware
class MessageController implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
protected $container;

/**
* Displays the authenticated participant inbox
*
Expand Down Expand Up @@ -55,7 +61,7 @@ public function deletedAction()
* Displays a thread, also allows to reply to it
*
* @param string $threadId the thread id
*
*
* @return Response
*/
public function threadAction($threadId)
Expand Down Expand Up @@ -100,9 +106,9 @@ public function newThreadAction()

/**
* Deletes a thread
*
*
* @param string $threadId the thread id
*
*
* @return RedirectResponse
*/
public function deleteAction($threadId)
Expand All @@ -116,9 +122,9 @@ public function deleteAction($threadId)

/**
* Undeletes a thread
*
*
* @param string $threadId
*
*
* @return RedirectResponse
*/
public function undeleteAction($threadId)
Expand Down Expand Up @@ -155,4 +161,12 @@ protected function getProvider()
{
return $this->container->get('fos_message.provider');
}

/**
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('factory')->defaultValue('fos_message.new_thread_form.factory.default')->cannotBeEmpty()->end()
->scalarNode('type')->defaultValue('fos_message.new_thread_form.type.default')->cannotBeEmpty()->end()
->scalarNode('type')->defaultValue('FOS\MessageBundle\FormType\NewThreadMessageFormType')->cannotBeEmpty()->end()
->scalarNode('handler')->defaultValue('fos_message.new_thread_form.handler.default')->cannotBeEmpty()->end()
->scalarNode('name')->defaultValue('message')->cannotBeEmpty()->end()
->scalarNode('model')->defaultValue('FOS\MessageBundle\FormModel\NewThreadMessage')->end()
Expand All @@ -60,7 +60,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('factory')->defaultValue('fos_message.reply_form.factory.default')->cannotBeEmpty()->end()
->scalarNode('type')->defaultValue('fos_message.reply_form.type.default')->cannotBeEmpty()->end()
->scalarNode('type')->defaultValue('FOS\MessageBundle\FormType\ReplyMessageFormType')->cannotBeEmpty()->end()
->scalarNode('handler')->defaultValue('fos_message.reply_form.handler.default')->cannotBeEmpty()->end()
->scalarNode('name')->defaultValue('message')->cannotBeEmpty()->end()
->scalarNode('model')->defaultValue('FOS\MessageBundle\FormModel\ReplyMessage')->end()
Expand Down
30 changes: 28 additions & 2 deletions DependencyInjection/FOSMessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FOS\MessageBundle\DependencyInjection;

use FOS\MessageBundle\Util\LegacyFormHelper;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand All @@ -23,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container)
if (!in_array(strtolower($config['db_driver']), array('orm', 'mongodb'))) {
throw new \InvalidArgumentException(sprintf('Invalid db driver "%s".', $config['db_driver']));
}

$loader->load(sprintf('%s.xml', $config['db_driver']));
$loader->load('config.xml');
$loader->load('form.xml');
Expand Down Expand Up @@ -51,10 +53,34 @@ public function load(array $configs, ContainerBuilder $container)
$container->setAlias('fos_message.spam_detector', $config['spam_detector']);
$container->setAlias('fos_message.twig_extension', $config['twig_extension']);

$container->setAlias('fos_message.new_thread_form.type', $config['new_thread_form']['type']);
// BC management
$newThreadFormType = $config['new_thread_form']['type'];
$replyFormType = $config['reply_form']['type'];

if (!class_exists($newThreadFormType)) {
@trigger_error('Using a service reference in configuration key "fos_message.new_thread_form.type" is deprecated since version 1.2 and will be removed in 2.0. Use the class name of your form type instead.', E_USER_DEPRECATED);

// Old syntax (service reference)
$container->setAlias('fos_message.new_thread_form.type', $newThreadFormType);
} else {
// New syntax (class name)
$container->getDefinition('fos_message.new_thread_form.factory.default')
->replaceArgument(1, $newThreadFormType);
}

if (!class_exists($replyFormType)) {
@trigger_error('Using a service reference in configuration key "fos_message.reply_form.type" is deprecated since version 1.2 and will be removed in 2.0. Use the class name of your form type instead.', E_USER_DEPRECATED);

// Old syntax (service reference)
$container->setAlias('fos_message.reply_form.type', $replyFormType);
} else {
// New syntax (class name)
$container->getDefinition('fos_message.reply_form.factory.default')
->replaceArgument(1, $replyFormType);
}

$container->setAlias('fos_message.new_thread_form.factory', $config['new_thread_form']['factory']);
$container->setAlias('fos_message.new_thread_form.handler', $config['new_thread_form']['handler']);
$container->setAlias('fos_message.reply_form.type', $config['reply_form']['type']);
$container->setAlias('fos_message.reply_form.factory', $config['reply_form']['factory']);
$container->setAlias('fos_message.reply_form.handler', $config['reply_form']['handler']);

Expand Down
6 changes: 3 additions & 3 deletions Document/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class Message extends BaseMessage
* Tells if the message is spam or flood
* This denormalizes Thread.isSpam
*
* @var boolean
* @var bool
*/
protected $isSpam = false;

Expand All @@ -23,11 +23,11 @@ abstract class Message extends BaseMessage
protected $unreadForParticipants = array();

/**
* @param boolean $isSpam
* @param bool $isSpam
*/
public function setIsSpam($isSpam)
{
$this->isSpam = (boolean) $isSpam;
$this->isSpam = (bool) $isSpam;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion Document/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function addParticipant(ParticipantInterface $participant)
* Tells if the user participates to the conversation
*
* @param ParticipantInterface $participant
* @return boolean
* @return bool
*/
public function isParticipant(ParticipantInterface $participant)
{
Expand Down
8 changes: 4 additions & 4 deletions DocumentManager/MessageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function markAsUnreadByParticipant(ReadableInterface $readable, Participa
*
* @param ThreadInterface $thread
* @param ParticipantInterface $participant
* @param boolean $isRead
* @param bool $isRead
*/
public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead)
{
Expand All @@ -98,7 +98,7 @@ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, Partic
*
* @param MessageInterface $message
* @param ParticipantInterface $participant
* @param boolean $isRead
* @param bool $isRead
*/
protected function markIsReadByParticipant(MessageInterface $message, ParticipantInterface $participant, $isRead)
{
Expand All @@ -112,7 +112,7 @@ protected function markIsReadByParticipant(MessageInterface $message, Participan
* by updating directly the storage
*
* @param ParticipantInterface $participant
* @param boolean $isRead
* @param bool $isRead
* @param \Closure $condition
*/
protected function markIsReadByCondition(ParticipantInterface $participant, $isRead, \Closure $condition)
Expand All @@ -132,7 +132,7 @@ protected function markIsReadByCondition(ParticipantInterface $participant, $isR
}

$queryBuilder
->field('metadata.$.isRead')->set((boolean) $isRead)
->field('metadata.$.isRead')->set((bool) $isRead)
->getQuery(array('multiple' => true))
->execute();

Expand Down
4 changes: 2 additions & 2 deletions EntityManager/MessageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function markAsUnreadByParticipant(ReadableInterface $readable, Participa
*
* @param ThreadInterface $thread
* @param ParticipantInterface $participant
* @param boolean $isRead
* @param bool $isRead
*/
public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead)
{
Expand All @@ -111,7 +111,7 @@ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, Partic
*
* @param MessageInterface $message
* @param ParticipantInterface $participant
* @param boolean $isRead
* @param bool $isRead
*/
protected function markIsReadByParticipant(MessageInterface $message, ParticipantInterface $participant, $isRead)
{
Expand Down
16 changes: 13 additions & 3 deletions FormFactory/AbstractMessageFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class AbstractMessageFormFactory
/**
* The message form type
*
* @var AbstractType
* @var AbstractType|string
*/
protected $formType;

Expand All @@ -41,8 +41,16 @@ abstract class AbstractMessageFormFactory
*/
protected $messageClass;

public function __construct(FormFactoryInterface $formFactory, AbstractType $formType, $formName, $messageClass)
public function __construct(FormFactoryInterface $formFactory, $formType, $formName, $messageClass)
{
if (!is_string($formType) && !$formType instanceof AbstractType) {
throw new \InvalidArgumentException(sprintf(
'Form type provided is not valid (class name or instance of %s expected, %s given)',
'Symfony\Component\Form\AbstractType',
is_object($formType) ? get_class($formType) : gettype($formType)
));
}

$this->formFactory = $formFactory;
$this->formType = $formType;
$this->formName = $formName;
Expand All @@ -56,6 +64,8 @@ public function __construct(FormFactoryInterface $formFactory, AbstractType $for
*/
protected function createModelInstance()
{
return new $this->messageClass();
$class = $this->messageClass;

return new $class();
}
}
Loading

0 comments on commit 4e6c19e

Please sign in to comment.