/src/cocktail/resource/php/ContainerLoader.hx

http://github.com/silexlabs/Cocktail · Haxe · 75 lines · 26 code · 8 blank · 41 comment · 0 complexity · 851c2e2c27c7d7e75cace87e211442ee MD5 · raw file

  1. /*
  2. This file is part of Silex - see http://projects.silexlabs.org/?/silex
  3. Silex is Š 2010-2011 Silex Labs and is released under the GPL License:
  4. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  7. */
  8. package cocktail.resource.php;
  9. import haxe.Http;
  10. import haxe.Log;
  11. import php.Web;
  12. import cocktail.domElement.ContainerDOMElement;
  13. import cocktail.domElement.DOMElement;
  14. import cocktail.resource.abstract.AbstractResourceLoader;
  15. import cocktail.resource.ResourceData;
  16. /**
  17. * This is the Container loader implementation for the PHP runtime. It is used to
  18. * load complex object, such as a skin formed of multiple HTML tags. It is loaded from
  19. * an HTML file
  20. *
  21. * @author Raphael HARMEL
  22. * @date 2011-08-03
  23. */
  24. class ContainerLoader extends AbstractResourceLoader
  25. {
  26. /**
  27. * class constructor
  28. */
  29. public function new()
  30. {
  31. super();
  32. }
  33. //////////////////////////////////////////////////////////////////////////////////////////
  34. // Overriden method to implement PHP specific behaviour
  35. //////////////////////////////////////////////////////////////////////////////////////////
  36. /**
  37. * Starts the file loading and converts the relative url to absolute url.
  38. * The default implementation is to load an url and return the result as an Xml.
  39. * @param url the url to load
  40. */
  41. override private function doLoad(relativeUrl:String):Void
  42. {
  43. // get server port
  44. var port:Int = untyped __var__('_SERVER', 'SERVER_PORT');
  45. // converts relative url to absolute url
  46. var absoluteUrl:String = 'http://' + Web.getHostName() + ':' + port + Web.getURI() + relativeUrl;
  47. // call parent method so that text file content is retreived and onLoadComplete callbac is called
  48. super.doLoad(absoluteUrl);
  49. }
  50. /**
  51. * When the HTML has been loaded, set the loaded HTML as the
  52. * native DOM of the Container DOMElement
  53. * Xml is used for easier data structuring
  54. * @param data the loaded HTML
  55. */
  56. override private function onLoadComplete(data:Dynamic):Void
  57. {
  58. // construction of the Xml element containing the container
  59. var domElement:ContainerDOMElement = new ContainerDOMElement(Xml.parse(data));
  60. // calls initial callback
  61. _onLoadCompleteCallback(domElement);
  62. }
  63. }