2015-08-09 69 views
0

據Symfony的3.0版本The Symfony\Component\Security\Core\SecurityContext begining將被刪除。這已經在這裏討論:Symfony 2 SecurityContext class deprecated安全註釋和Symfony的分量安全核心 SecurityContext中,此類已廢棄

我的symfony報告以下錯誤:

Error: The Symfony\Component\Security\Core\SecurityContext class is deprecated since version 2.6 and will be removed in 3.0. Use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage or Symfony\Component\Security\Core\Authorization\AuthorizationChecker instead.

我使用annotations symfony的管理我的安全角色如

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; // Security annotation bundle 

    /** 
* @Route("/account/list", name="Account_list") 
* @Security("has_role('ROLE_USER')") 
*/ 

我應該如何切換到非折舊類?

無論是使用在錯誤結果中列出的類:

[Semantical Error] The annotation "@Security" in method AppBundle\Controller\AccountController::listAction() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /var/www/gra.investmentopportunities.pl/src/AppBundle/Controller/ (which is being imported from "/var/www/gra.investmentopportunities.pl/app/config/routing.yml").

+1

您仍然應該使用'Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Security'註釋。您確定此棄用警告是由於註釋引起的嗎?不應該有任何的警告只是從使用'@ Security'標籤在它自己的,因爲這承諾 - https://github.com/sensiolabs/SensioFrameworkExtraBundle/commit/675a6ea953c46721e57d692d17bb8d4a734b92f8 – qooplmao

回答

2

通過觀察the code它看起來像@security.context用盡直到v3.0.4。從那時起,@security.token_storage@security.authorization_checker也被注入了,如果它們存在的話,它們將被用來代替@security.context

從這些事實中採取我只能假設使用v3.0.5之前的SensioFrameworkExtraBundle版本。

如果你在你的composer.jsonsensio/framework-extra-bundle: ~3.0那麼你可以運行composer.phar update sensio/framework-extra-bundle它應該把它最新的,擺脫了棄用警告。

+0

感謝您的諮詢。我已經檢查過作曲家,並且我目前使用sensio/framework-extra-bundle的3.0.9版本。問題是我應該在腳本標題中使用什麼命令來使註釋生效? (請參閱上面的更新代碼)。 – Abdel5