LimeParserRaw.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class LimeParserRaw extends LimeParser
  12. {
  13. protected
  14. $suppressedMethods = array(),
  15. $error = false;
  16. public function __construct(LimeOutputInterface $output, array $suppressedMethods = array())
  17. {
  18. parent::__construct($output);
  19. $this->suppressedMethods = $suppressedMethods;
  20. }
  21. public function parse($data)
  22. {
  23. $this->buffer .= $data;
  24. $lines = explode("\n", $this->buffer);
  25. while ($line = array_shift($lines))
  26. {
  27. if (!empty($line))
  28. {
  29. $this->error = false;
  30. set_error_handler(array($this, 'failedUnserialize'));
  31. list($method, $arguments) = unserialize($line);
  32. restore_error_handler();
  33. if ($this->error)
  34. {
  35. // prepend the line again, maybe we can unserialize later
  36. array_unshift($lines, $line);
  37. break;
  38. }
  39. if (!in_array($method, $this->suppressedMethods))
  40. {
  41. foreach ($arguments as &$argument)
  42. {
  43. if (is_string($argument))
  44. {
  45. $argument = stripcslashes($argument);
  46. }
  47. }
  48. call_user_func_array(array($this->output, $method), $arguments);
  49. }
  50. }
  51. }
  52. $this->buffer = implode("\n", $lines);
  53. $this->clearErrors();
  54. }
  55. public function done()
  56. {
  57. return empty($this->buffer);
  58. }
  59. public function failedUnserialize()
  60. {
  61. $this->error = true;
  62. }
  63. }