PageRenderTime 53ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/mock/LimeMockTemplate.php

http://github.com/bschussek/lime
PHP | 57 lines | 18 code | 6 blank | 33 comment | 0 complexity | 46cb96cd5fd1b331cb086b1500464827 MD5 | raw file
Possible License(s): ISC
  1. <?php
  2. /*
  3. * This file is part of the Lime test 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. * Reads template files and parses them with a set of template variables.
  13. *
  14. * @package Lime
  15. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  16. * @version SVN: $Id: LimeMockTemplate.php 23701 2009-11-08 21:23:40Z bschussek $
  17. */
  18. class LimeMockTemplate
  19. {
  20. private
  21. $parameters = array(),
  22. $filename = '';
  23. /**
  24. * Constructor.
  25. *
  26. * Configures this template to use the given file.
  27. *
  28. * @param string $filename
  29. */
  30. public function __construct($filename)
  31. {
  32. $this->filename = $filename;
  33. }
  34. /**
  35. * Renders the file of this template with the given parameters.
  36. *
  37. * The parameters are made available in the template and can be accessed there
  38. * as normal PHP variables. The template is parsed and the output of the
  39. * template is returned.
  40. *
  41. * @param array $parameters
  42. * @return string
  43. */
  44. public function render(array $parameters)
  45. {
  46. ob_start();
  47. extract($parameters);
  48. include $this->filename;
  49. return ob_get_clean();
  50. }
  51. }