LimeTools.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. /**
  12. * Provides static utility methods.
  13. *
  14. * @package Lime
  15. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  16. * @version SVN: $Id: LimeTools.php 23864 2009-11-13 18:06:20Z bschussek $
  17. */
  18. abstract class LimeTools
  19. {
  20. /**
  21. * Indents every line of the given string for the given number of spaces
  22. * (except for the first line, which is not indented).
  23. *
  24. * @param string $text The input string
  25. * @param integer $numberOfSpaces The number of spaces for indenting the
  26. * input string
  27. * @return string The indented string
  28. */
  29. public static function indent($text, $numberOfSpaces)
  30. {
  31. $indentation = str_repeat(' ', $numberOfSpaces);
  32. $lines = explode("\n", $text);
  33. for ($i = 0, $c = count($lines); $i < $c; ++$i)
  34. {
  35. $lines[$i] = $indentation.$lines[$i];
  36. }
  37. return implode("\n", $lines);
  38. }
  39. }