Skip to content

Commit 4e6c19e

Browse files
committed
Add support of Symfony 3 and drop Symfony < 2.7
1 parent cdfee5e commit 4e6c19e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+432
-171
lines changed

.travis.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
language: php
22

3-
php:
4-
- 5.3
5-
- 5.4
6-
- 5.5
7-
- 5.6
8-
- hhvm
3+
sudo: false
94

10-
env:
11-
- SYMFONY_VERSION=2.1.*
12-
- SYMFONY_VERSION=2.2.*
13-
- SYMFONY_VERSION=2.3.*
14-
- SYMFONY_VERSION=dev-master
5+
branches:
6+
only:
7+
- master
8+
9+
matrix:
10+
include:
11+
- php: 5.3
12+
env:
13+
- deps=low
14+
- SYMFONY_VERSION=2.7.*
15+
- php: 5.4
16+
env:
17+
- deps=high
18+
- SYMFONY_VERSION=2.7.*
19+
- php: 5.5
20+
env:
21+
- deps=low
22+
- SYMFONY_VERSION=2.8.*
23+
- php: 5.6
24+
env:
25+
- deps=high
26+
- SYMFONY_VERSION=3.0.*
27+
- php: 7.0
28+
env:
29+
- deps=low
30+
- SYMFONY_VERSION=3.1.*
31+
- php: 7.1
32+
env:
33+
- deps=high
34+
- SYMFONY_VERSION=3.1.*
1535

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

2041
script: phpunit --coverage-text
2142

2243
notifications:
2344
email:
2445
25-
26-
matrix:
27-
allow_failures:
28-
- env: SYMFONY_VERSION=dev-master
29-
- php: 5.6
30-
- php: hhvm

Controller/MessageController.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
namespace FOS\MessageBundle\Controller;
44

5-
use Symfony\Component\DependencyInjection\ContainerAware;
5+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
67
use Symfony\Component\HttpFoundation\RedirectResponse;
78
use FOS\MessageBundle\Provider\ProviderInterface;
89
use Symfony\Component\HttpFoundation\Response;
910

10-
class MessageController extends ContainerAware
11+
class MessageController implements ContainerAwareInterface
1112
{
13+
/**
14+
* @var ContainerInterface
15+
*/
16+
protected $container;
17+
1218
/**
1319
* Displays the authenticated participant inbox
1420
*
@@ -55,7 +61,7 @@ public function deletedAction()
5561
* Displays a thread, also allows to reply to it
5662
*
5763
* @param string $threadId the thread id
58-
*
64+
*
5965
* @return Response
6066
*/
6167
public function threadAction($threadId)
@@ -100,9 +106,9 @@ public function newThreadAction()
100106

101107
/**
102108
* Deletes a thread
103-
*
109+
*
104110
* @param string $threadId the thread id
105-
*
111+
*
106112
* @return RedirectResponse
107113
*/
108114
public function deleteAction($threadId)
@@ -116,9 +122,9 @@ public function deleteAction($threadId)
116122

117123
/**
118124
* Undeletes a thread
119-
*
125+
*
120126
* @param string $threadId
121-
*
127+
*
122128
* @return RedirectResponse
123129
*/
124130
public function undeleteAction($threadId)
@@ -155,4 +161,12 @@ protected function getProvider()
155161
{
156162
return $this->container->get('fos_message.provider');
157163
}
164+
165+
/**
166+
* {@inheritdoc}
167+
*/
168+
public function setContainer(ContainerInterface $container = null)
169+
{
170+
$this->container = $container;
171+
}
158172
}

DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getConfigTreeBuilder()
5050
->addDefaultsIfNotSet()
5151
->children()
5252
->scalarNode('factory')->defaultValue('fos_message.new_thread_form.factory.default')->cannotBeEmpty()->end()
53-
->scalarNode('type')->defaultValue('fos_message.new_thread_form.type.default')->cannotBeEmpty()->end()
53+
->scalarNode('type')->defaultValue('FOS\MessageBundle\FormType\NewThreadMessageFormType')->cannotBeEmpty()->end()
5454
->scalarNode('handler')->defaultValue('fos_message.new_thread_form.handler.default')->cannotBeEmpty()->end()
5555
->scalarNode('name')->defaultValue('message')->cannotBeEmpty()->end()
5656
->scalarNode('model')->defaultValue('FOS\MessageBundle\FormModel\NewThreadMessage')->end()
@@ -60,7 +60,7 @@ public function getConfigTreeBuilder()
6060
->addDefaultsIfNotSet()
6161
->children()
6262
->scalarNode('factory')->defaultValue('fos_message.reply_form.factory.default')->cannotBeEmpty()->end()
63-
->scalarNode('type')->defaultValue('fos_message.reply_form.type.default')->cannotBeEmpty()->end()
63+
->scalarNode('type')->defaultValue('FOS\MessageBundle\FormType\ReplyMessageFormType')->cannotBeEmpty()->end()
6464
->scalarNode('handler')->defaultValue('fos_message.reply_form.handler.default')->cannotBeEmpty()->end()
6565
->scalarNode('name')->defaultValue('message')->cannotBeEmpty()->end()
6666
->scalarNode('model')->defaultValue('FOS\MessageBundle\FormModel\ReplyMessage')->end()

DependencyInjection/FOSMessageExtension.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FOS\MessageBundle\DependencyInjection;
44

5+
use FOS\MessageBundle\Util\LegacyFormHelper;
56
use Symfony\Component\Config\Definition\Processor;
67
use Symfony\Component\DependencyInjection\Reference;
78
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -23,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container)
2324
if (!in_array(strtolower($config['db_driver']), array('orm', 'mongodb'))) {
2425
throw new \InvalidArgumentException(sprintf('Invalid db driver "%s".', $config['db_driver']));
2526
}
27+
2628
$loader->load(sprintf('%s.xml', $config['db_driver']));
2729
$loader->load('config.xml');
2830
$loader->load('form.xml');
@@ -51,10 +53,34 @@ public function load(array $configs, ContainerBuilder $container)
5153
$container->setAlias('fos_message.spam_detector', $config['spam_detector']);
5254
$container->setAlias('fos_message.twig_extension', $config['twig_extension']);
5355

54-
$container->setAlias('fos_message.new_thread_form.type', $config['new_thread_form']['type']);
56+
// BC management
57+
$newThreadFormType = $config['new_thread_form']['type'];
58+
$replyFormType = $config['reply_form']['type'];
59+
60+
if (!class_exists($newThreadFormType)) {
61+
@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);
62+
63+
// Old syntax (service reference)
64+
$container->setAlias('fos_message.new_thread_form.type', $newThreadFormType);
65+
} else {
66+
// New syntax (class name)
67+
$container->getDefinition('fos_message.new_thread_form.factory.default')
68+
->replaceArgument(1, $newThreadFormType);
69+
}
70+
71+
if (!class_exists($replyFormType)) {
72+
@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);
73+
74+
// Old syntax (service reference)
75+
$container->setAlias('fos_message.reply_form.type', $replyFormType);
76+
} else {
77+
// New syntax (class name)
78+
$container->getDefinition('fos_message.reply_form.factory.default')
79+
->replaceArgument(1, $replyFormType);
80+
}
81+
5582
$container->setAlias('fos_message.new_thread_form.factory', $config['new_thread_form']['factory']);
5683
$container->setAlias('fos_message.new_thread_form.handler', $config['new_thread_form']['handler']);
57-
$container->setAlias('fos_message.reply_form.type', $config['reply_form']['type']);
5884
$container->setAlias('fos_message.reply_form.factory', $config['reply_form']['factory']);
5985
$container->setAlias('fos_message.reply_form.handler', $config['reply_form']['handler']);
6086

Document/Message.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class Message extends BaseMessage
1010
* Tells if the message is spam or flood
1111
* This denormalizes Thread.isSpam
1212
*
13-
* @var boolean
13+
* @var bool
1414
*/
1515
protected $isSpam = false;
1616

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

2525
/**
26-
* @param boolean $isSpam
26+
* @param bool $isSpam
2727
*/
2828
public function setIsSpam($isSpam)
2929
{
30-
$this->isSpam = (boolean) $isSpam;
30+
$this->isSpam = (bool) $isSpam;
3131
}
3232

3333
/*

Document/Thread.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function addParticipant(ParticipantInterface $participant)
7979
* Tells if the user participates to the conversation
8080
*
8181
* @param ParticipantInterface $participant
82-
* @return boolean
82+
* @return bool
8383
*/
8484
public function isParticipant(ParticipantInterface $participant)
8585
{

DocumentManager/MessageManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function markAsUnreadByParticipant(ReadableInterface $readable, Participa
8484
*
8585
* @param ThreadInterface $thread
8686
* @param ParticipantInterface $participant
87-
* @param boolean $isRead
87+
* @param bool $isRead
8888
*/
8989
public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead)
9090
{
@@ -98,7 +98,7 @@ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, Partic
9898
*
9999
* @param MessageInterface $message
100100
* @param ParticipantInterface $participant
101-
* @param boolean $isRead
101+
* @param bool $isRead
102102
*/
103103
protected function markIsReadByParticipant(MessageInterface $message, ParticipantInterface $participant, $isRead)
104104
{
@@ -112,7 +112,7 @@ protected function markIsReadByParticipant(MessageInterface $message, Participan
112112
* by updating directly the storage
113113
*
114114
* @param ParticipantInterface $participant
115-
* @param boolean $isRead
115+
* @param bool $isRead
116116
* @param \Closure $condition
117117
*/
118118
protected function markIsReadByCondition(ParticipantInterface $participant, $isRead, \Closure $condition)
@@ -132,7 +132,7 @@ protected function markIsReadByCondition(ParticipantInterface $participant, $isR
132132
}
133133

134134
$queryBuilder
135-
->field('metadata.$.isRead')->set((boolean) $isRead)
135+
->field('metadata.$.isRead')->set((bool) $isRead)
136136
->getQuery(array('multiple' => true))
137137
->execute();
138138

EntityManager/MessageManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function markAsUnreadByParticipant(ReadableInterface $readable, Participa
9797
*
9898
* @param ThreadInterface $thread
9999
* @param ParticipantInterface $participant
100-
* @param boolean $isRead
100+
* @param bool $isRead
101101
*/
102102
public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead)
103103
{
@@ -111,7 +111,7 @@ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, Partic
111111
*
112112
* @param MessageInterface $message
113113
* @param ParticipantInterface $participant
114-
* @param boolean $isRead
114+
* @param bool $isRead
115115
*/
116116
protected function markIsReadByParticipant(MessageInterface $message, ParticipantInterface $participant, $isRead)
117117
{

FormFactory/AbstractMessageFormFactory.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractMessageFormFactory
2323
/**
2424
* The message form type
2525
*
26-
* @var AbstractType
26+
* @var AbstractType|string
2727
*/
2828
protected $formType;
2929

@@ -41,8 +41,16 @@ abstract class AbstractMessageFormFactory
4141
*/
4242
protected $messageClass;
4343

44-
public function __construct(FormFactoryInterface $formFactory, AbstractType $formType, $formName, $messageClass)
44+
public function __construct(FormFactoryInterface $formFactory, $formType, $formName, $messageClass)
4545
{
46+
if (!is_string($formType) && !$formType instanceof AbstractType) {
47+
throw new \InvalidArgumentException(sprintf(
48+
'Form type provided is not valid (class name or instance of %s expected, %s given)',
49+
'Symfony\Component\Form\AbstractType',
50+
is_object($formType) ? get_class($formType) : gettype($formType)
51+
));
52+
}
53+
4654
$this->formFactory = $formFactory;
4755
$this->formType = $formType;
4856
$this->formName = $formName;
@@ -56,6 +64,8 @@ public function __construct(FormFactoryInterface $formFactory, AbstractType $for
5664
*/
5765
protected function createModelInstance()
5866
{
59-
return new $this->messageClass();
67+
$class = $this->messageClass;
68+
69+
return new $class();
6070
}
6171
}

0 commit comments

Comments
 (0)