Helper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Helper;
  11. /**
  12. * Helper is the base class for all helper classes.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. abstract class Helper implements HelperInterface
  17. {
  18. protected $helperSet = null;
  19. /**
  20. * Sets the helper set associated with this helper.
  21. *
  22. * @param HelperSet $helperSet A HelperSet instance
  23. */
  24. public function setHelperSet(HelperSet $helperSet = null)
  25. {
  26. $this->helperSet = $helperSet;
  27. }
  28. /**
  29. * Gets the helper set associated with this helper.
  30. *
  31. * @return HelperSet A HelperSet instance
  32. */
  33. public function getHelperSet()
  34. {
  35. return $this->helperSet;
  36. }
  37. /**
  38. * Returns the length of a string, using mb_strlen if it is available.
  39. *
  40. * @param string $string The string to check its length
  41. *
  42. * @return integer The length of the string
  43. */
  44. protected function strlen($string)
  45. {
  46. if (!function_exists('mb_strlen')) {
  47. return strlen($string);
  48. }
  49. if (false === $encoding = mb_detect_encoding($string)) {
  50. return strlen($string);
  51. }
  52. return mb_strlen($string, $encoding);
  53. }
  54. }