Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
<?php /** * Holds data so it can be passed around to various functions. * * Supplying the $type, $key and $bits (keyed array) will store it. Calling it * with $type and $key will retrieve everything previously stored for the * specific entry. Calling it with $type and the $key prepended with "get:" * will return all the matching keys previously set with $bits. And finally, * just calling it with no parameters will return everything stored. */ function _bit_pusher($type = '', $key = NULL, $bits = array()) { static $cache_bits = array(); $output = array(); if (!empty($type) && isset($key) && !empty($bits)) { $cache_bits[$type][$key] = isset($cache_bits[$type][$key]) ? array_merge($cache_bits[$type][$key], $bits) : $bits; } elseif (!empty($type) && isset($key)) { $key_hold = $key; $key = str_replace('get:', '', $key_hold); if ($key == $key_hold) { $output = isset($cache_bits[$type][$key]) ? $cache_bits[$type][$key] : $output; } elseif (isset($cache_bits[$type])) { foreach ($cache_bits[$type] as $id => $bits) { if (isset($bits[$key])) { if (is_array($bits[$key])) { $output = array_merge($output, $bits[$key]); } else { $output[$id] = $bits[$key]; } } } } } elseif (!empty($type)) { $output = isset($cache_bits[$type]) ? $cache_bits[$type] : $output; } else { $output = !empty($cache_bits) ? $cache_bits : $output; } return $output; }
This paste will be private.
From the Design Piracy series on my blog: