Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?php
  2. // src/YourApp/Bundle/YourBundle/Twig/ToArrayExtension.php
  3.  
  4. namespace Appcito\Bundle\CoreBundle\Twig;
  5.  
  6. /**
  7. * A simple twig extension that adds a to_array filter
  8. * It will convert an object to array so that you can iterate over it's properties
  9. */
  10. class ToArrayExtension extends \Twig_Extension
  11. {
  12. public function getFilters()
  13. {
  14. return array(
  15. new \Twig_SimpleFilter('to_array', array($this, 'to_array')),
  16. );
  17. }
  18.  
  19. public function to_array($object)
  20. {
  21. return get_object_vars($object);
  22. }
  23.  
  24. public function getName()
  25. {
  26. return 'to_array_extension';
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement