1<?php 2 3/** 4 * This file is part of Twig. 5 * 6 * (c) 2009 Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12/** 13 * @author Ricard Clau <ricard.clau@gmail.com> 14 */ 15class Twig_Extensions_Extension_Array extends Twig_Extension 16{ 17 /** 18 * {@inheritdoc} 19 */ 20 public function getFilters() 21 { 22 $filters = array( 23 new Twig_SimpleFilter('shuffle', 'twig_shuffle_filter'), 24 ); 25 26 return $filters; 27 } 28 29 /** 30 * {@inheritdoc} 31 */ 32 public function getName() 33 { 34 return 'array'; 35 } 36} 37 38/** 39 * Shuffles an array. 40 * 41 * @param array|Traversable $array An array 42 * 43 * @return array 44 */ 45function twig_shuffle_filter($array) 46{ 47 if ($array instanceof Traversable) { 48 $array = iterator_to_array($array, false); 49 } 50 51 shuffle($array); 52 53 return $array; 54} 55 56class_alias('Twig_Extensions_Extension_Array', 'Twig\Extensions\ArrayExtension', false); 57