UserHelper.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Symfony\Framework\WebBundle\Helper;
  3. use Symfony\Components\Templating\Helper\Helper;
  4. use Symfony\Framework\WebBundle\User;
  5. /*
  6. * This file is part of the Symfony framework.
  7. *
  8. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9. *
  10. * This source file is subject to the MIT license that is bundled
  11. * with this source code in the file LICENSE.
  12. */
  13. /**
  14. * UserHelper.
  15. *
  16. * @package Symfony
  17. * @subpackage Framework_WebBundle
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. */
  20. class UserHelper extends Helper
  21. {
  22. protected $user;
  23. /**
  24. * Constructor.
  25. *
  26. * @param Request $request A Request instance
  27. */
  28. public function __construct(User $user)
  29. {
  30. $this->user = $user;
  31. }
  32. /**
  33. * Returns a user attribute
  34. *
  35. * @param string $name The attribute name
  36. * @param mixed $default The default value
  37. *
  38. * @return mixed
  39. */
  40. public function getAttribute($name, $default = null)
  41. {
  42. return $this->user->getAttribute($name, $default);
  43. }
  44. /**
  45. * Returns the user locale
  46. *
  47. * @return string
  48. */
  49. public function getLocale()
  50. {
  51. return $this->user->getLocale();
  52. }
  53. public function getFlash($name, $default = null)
  54. {
  55. return $this->user->getFlash($name, $default);
  56. }
  57. public function hasFlash($name)
  58. {
  59. return $this->user->hasFlash($name);
  60. }
  61. /**
  62. * Returns the canonical name of this helper.
  63. *
  64. * @return string The canonical name
  65. */
  66. public function getName()
  67. {
  68. return 'user';
  69. }
  70. }