PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/poko/views/renderers/Php.hx

http://poko.googlecode.com/
Haxe | 80 lines | 45 code | 8 blank | 27 comment | 2 complexity | 3fe0bdf4f8b06a85eb7973bfce6425b7 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. /*
  2. * Copyright (c) 2008, TouchMyPixel & contributors
  3. * Original author : Tony Polinelli <tonyp@touchmypixel.com>
  4. * Contributers: Tarwin Stroh-Spijer
  5. * All rights reserved.
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE TOUCH MY PIXEL & CONTRIBUTERS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE TOUCH MY PIXEL & CONTRIBUTORS
  19. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  25. * THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. package poko.views.renderers;
  28. import php.FileSystem;
  29. //import poko.views.renderers.IRenderer;
  30. import poko.views.Renderable;
  31. import templo.Loader;
  32. class Php implements Renderable
  33. {
  34. public var template:String;
  35. public var data:Dynamic;
  36. public function new(?template:String )
  37. {
  38. this.template = template;
  39. data = { };
  40. }
  41. public function render():String
  42. {
  43. var tpl = "./tpl/php/" + template;
  44. if(FileSystem.exists(tpl))
  45. {
  46. untyped __call__("ob_start");
  47. untyped __call__("extract", __php__("(array)$this->data"));
  48. untyped __call__("include", tpl);
  49. var out:String = untyped __call__("ob_get_contents");
  50. untyped __call__("ob_end_clean");
  51. return out;
  52. } else {
  53. throw "Php Template is missing: " + template;
  54. return null;
  55. }
  56. return "";
  57. }
  58. public function assign(field:String, value:Dynamic):Void
  59. {
  60. Reflect.setField(data, field, value);
  61. }
  62. public static function parse(template:String, ?data:Dynamic):String
  63. {
  64. var renderer = new Php(template);
  65. renderer.data = data;
  66. return renderer.render();
  67. }
  68. public function toString():String
  69. {
  70. return "[PhpView " + template + "]";
  71. }
  72. }