public function listingFor($items, \Closure $callback, $attributes = array(), $element = 'ul', $childElement = 'li')
		{

			// Create the element
			$list = \HtmlObject\Element::$element('', $attributes);

			// Get closure info
			$closureMethod = Reflection::getClosureMethod($callback);
			$closureArgs = Reflection::getClosureParams($closureMethod);

			// Loop through items
			$index = 0;
			foreach ($items as $item) {

				// Invoke the closure
				$li = Reflection::invokeClosure($callback, 
					array($index, $item), 
					array($item));

				// Is it an element?
				if (is_string($li)) {

					// Create li containing that...
					$realLi = \HtmlObject\Element::$childElement($li);
					$list->addChild($realLi);

				} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {

					// An li tag?
					if ($li->getTag() !== $childElement) {

						// Wrap it!
						$realLi = \HtmlObject\Element::$childElement($li);
						$list->addChild($realLi);

					} else {

						// Add it as it is
						$list->addChild($li);

					}

				} else {

					// Not good.
					throw new \Exception("The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML.", 1);
					
				}



				$index++;
			}
			return $list;

		}
public function listingFor($items, \Closure $callback, $attributes = array(), $element = 'ul', $childElement = 'li')
		{

			// Create the element
			$list = \HtmlObject\Element::$element('', $attributes);

			// Get closure info
			$closureMethod = Reflection::getClosureMethod($callback);
			$closureArgs = Reflection::getClosureParams($closureMethod);

			// Loop through items
			$index = 0;
			foreach ($items as $item) {

				// Invoke the closure
				$li = Reflection::invokeClosure($callback, 
					array($index, $item), 
					array($item));

				// Is it an element?
				if (is_string($li)) {

					// Create li containing that...
					$realLi = \HtmlObject\Element::$childElement($li);
					$list->addChild($realLi);

				} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {

					// An li tag?
					if ($li->getTag() !== $childElement) {

						// Wrap it!
						$realLi = \HtmlObject\Element::$childElement($li);
						$list->addChild($realLi);

					} else {

						// Add it as it is
						$list->addChild($li);

					}

				} else {

					// Not good.
					throw new \Exception("The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML.", 1);
					
				}



				$index++;
			}
			return $list;

		}
public function listingFor ( $ items , \ Closure $ callback , $ attributes = array ( ) , $ element = 'ul' , $ childElement = 'li' ) { // Create the element $ list = \ HtmlObject \ Element :: $ element ( '' , $ attributes ) ; // Get closure info $ closureMethod = Reflection :: getClosureMethod ( $ callback ) ; $ closureArgs = Reflection :: getClosureParams ( $ closureMethod ) ; // Loop through items $ index = 0 ; foreach ( $ items as $ item ) { // Invoke the closure $ li = Reflection :: invokeClosure ( $ callback , array ( $ index , $ item ) , array ( $ item ) ) ; // Is it an element? if ( is_string ( $ li ) ) { // Create li containing that... $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } elseif ( is_subclass_of ( $ li , "\\HtmlObject\\Traits\\Tag" ) ) { // An li tag? if ( $ li -> getTag ( ) !== $ childElement ) { // Wrap it! $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } else { // Add it as it is $ list -> addChild ( $ li ) ; } } else { // Not good. throw new \ Exception ( "The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML." , 1 ) ; } $ index ++ ; } return $ list ; }
Create a listing for the given array of items, using a callback for each item

For example, in a view you might do:
<code>
$this->html->listingFor($this->people, function($person) {
return $person->name;
});
</code>
<code>
<ul>
<li>John Doe</li>
<li>Phil Spector</li>
</ul>
</code>
<br>

Or a little more complex:
<code>
$this->html->listingFor($this->people, function($index, $person) {
return $this->html->link($person, $index . ": " . $person->name);
});
</code>
<code>
<ul>
<li><a href="/people/1">0: John Doe</a></li>
<li><a href="/people/2">1: Phil Spector</a></li>
</ul>
</code>
<br>

And, if you want to modify the list item itself:
<code>
$this->html->listingFor($this->people, function($person) {
return $this->html->li($person->name, array("class" => "person " . $person->gender));
});
</code>
<code>
<ul>
<li class="person male">John Doe</li>
<li class="person female">Jane Doe</li>
</ul>
</code>

@param  array        Array of items to iterate
@param  \Closure 	The callback function to call for each item
@param  array        Array of HTML attributes to apply to the listing
@param  string   	The HTML element for the list
@param  string   	The HTML element for the items
@return \HtmlObject\Element
Create a listing for the given array of items using a callback for each item