Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix deprecated security.context
  • Loading branch information
DenysMedvid committed Feb 26, 2016
commit 6c0d24a52b5205883e8ca383db3c7119389e8fb1
2 changes: 1 addition & 1 deletion Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</service>

<service id="fos_message.participant_provider.default" class="FOS\MessageBundle\Security\ParticipantProvider" public="false">
<argument type="service" id="security.context" />
<argument type="service" id="security.token_storage" />
</service>

<service id="fos_message.authorizer.default" class="FOS\MessageBundle\Security\Authorizer" public="false">
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/90-sending-a-message-programatically.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is probably all you will need in many cases.
To compose a message we retrieve the composer service and compose our message:

```php
$sender = $this->get('security.context')->getToken()->getUser();
$sender = $this->get('security.token_storage')->getToken()->getUser();
$threadBuilder = $this->get('fos_message.composer')->newThread();
$threadBuilder
->addRecipient($recipient) // Retrieved from your backend, your user manager or ...
Expand Down
16 changes: 6 additions & 10 deletions Security/ParticipantProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace FOS\MessageBundle\Security;

use FOS\MessageBundle\Model\ParticipantInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
* Provides the authenticated participant
Expand All @@ -13,16 +13,12 @@
*/
class ParticipantProvider implements ParticipantProviderInterface
{
/**
* The security context
*
* @var SecurityContextInterface
*/
protected $securityContext;
/** @var TokenStorageInterface */
protected $tokenStorage;

public function __construct(SecurityContextInterface $securityContext)
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->securityContext = $securityContext;
$this->tokenStorage = $tokenStorage;
}

/**
Expand All @@ -32,7 +28,7 @@ public function __construct(SecurityContextInterface $securityContext)
*/
public function getAuthenticatedParticipant()
{
$participant = $this->securityContext->getToken()->getUser();
$participant = $this->tokenStorage->getToken()->getUser();

if (!$participant instanceof ParticipantInterface) {
throw new AccessDeniedException('Must be logged in with a ParticipantInterface instance');
Expand Down