PageRenderTime 70ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/micromvc4/Class/Core/View.php

http://github.com/eryx/php-framework-benchmark
PHP | 68 lines | 31 code | 9 blank | 28 comment | 0 complexity | 4c7b5250d5736d950604fd4dee0ec596 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  1. <?php
  2. /**
  3. * View
  4. *
  5. * Provides fetching of HTML template files
  6. *
  7. * @package MicroMVC
  8. * @author http://github.com/tweetmvc/tweetmvc-app
  9. * @copyright (c) 2011 MicroMVC Framework
  10. * @license http://micromvc.com/license
  11. ********************************** 80 Columns *********************************
  12. */
  13. namespace Core;
  14. class View
  15. {
  16. private $__view = NULL;
  17. /**
  18. * Returns a new view object for the given view.
  19. *
  20. * @param string $file the view file to load
  21. * @param string $module name (blank for current theme)
  22. */
  23. public function __construct($file)
  24. {
  25. $this->__view = $file;
  26. }
  27. /**
  28. * Set an array of values
  29. *
  30. * @param array $array of values
  31. */
  32. public function set($array)
  33. {
  34. foreach($array as $k => $v)
  35. {
  36. $this->$k = $v;
  37. }
  38. }
  39. /**
  40. * Return the view's HTML
  41. *
  42. * @return string
  43. */
  44. public function __toString()
  45. {
  46. try {
  47. ob_start();
  48. extract((array) $this);
  49. require SP . "View/" . $this->__view . EXT;
  50. return ob_get_clean();
  51. }
  52. catch(\Exception $e)
  53. {
  54. Error::exception($e);
  55. return '';
  56. }
  57. }
  58. }
  59. // END