asset_aggregated_renderer.class.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Process all renderers attached in order.
  4. *
  5. * If a renderer returns an key value that has not already been set add it
  6. * to the result. Otherwise let the previous value unchanged.
  7. *
  8. * @copyright (c) 2011 University of Geneva
  9. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  10. * @author Laurent Opprecht
  11. */
  12. class AssetAggregatedRenderer extends AssetRenderer
  13. {
  14. protected $renderers = array();
  15. public function __construct($renderers)
  16. {
  17. $this->renderers = $renderers;
  18. }
  19. /**
  20. *
  21. * @return array
  22. */
  23. public function renderers()
  24. {
  25. return $this->renderers;
  26. }
  27. /**
  28. *
  29. * @param HttpResource $asset
  30. * @return array
  31. */
  32. public function render($asset)
  33. {
  34. $result = array();
  35. $plugins = self::plugins();
  36. foreach ($this->renderers as $renderer)
  37. {
  38. $data = $renderer->render($asset);
  39. $data = $data ? $data : array();
  40. foreach ($data as $key => $value)
  41. {
  42. if (!isset($result[$key]) && !empty($value))
  43. {
  44. $result[$key] = $value;
  45. }
  46. }
  47. }
  48. return $result;
  49. }
  50. }