sfPearFrontendPlugin.class.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once 'PEAR/Frontend.php';
  10. require_once 'PEAR/Frontend/CLI.php';
  11. /**
  12. * The PEAR Frontend object.
  13. *
  14. * @package symfony
  15. * @subpackage plugin
  16. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  17. * @version SVN: $Id: sfPearFrontendPlugin.class.php 9131 2008-05-21 04:12:00Z Carl.Vondrick $
  18. */
  19. class sfPearFrontendPlugin extends PEAR_Frontend_CLI
  20. {
  21. protected
  22. $dispatcher = null;
  23. /**
  24. * Sets the sfEventDispatcher object for this frontend.
  25. *
  26. * @param sfEventDispatcher $dispatcher The sfEventDispatcher instance
  27. */
  28. public function setEventDispatcher(sfEventDispatcher $dispatcher)
  29. {
  30. $this->dispatcher = $dispatcher;
  31. }
  32. public function _displayLine($text)
  33. {
  34. $this->_display($text);
  35. }
  36. public function _display($text)
  37. {
  38. $this->dispatcher->notify(new sfEvent($this, 'application.log', $this->splitLongLine($text)));
  39. }
  40. protected function splitLongLine($text)
  41. {
  42. $lines = '';
  43. foreach (explode("\n", $text) as $longline)
  44. {
  45. foreach (explode("\n", wordwrap($longline, 62)) as $line)
  46. {
  47. if ($line = trim($line))
  48. {
  49. $lines[] = $line;
  50. }
  51. }
  52. }
  53. return $lines;
  54. }
  55. }