No problem.
PHP Code:
class DataSource
{
var $connections = array();
function DataSource()
{
}
function &getConnection($dsn)
{
$this =& DataSource::_getInstance();
if (! isset($this->connections[$dsn]))
{
include_once('Connection.class.php');
$url = parse_url($dsn);
$this->connections[$dsn] =& new Connection(
(isset($url['scheme']) ? $url['scheme'] : ''),
(isset($url['host']) ? $url['host'] : 'localhost') .
(isset($url['port']) ? ':' . $url['port'] : ''),
(isset($url['path']) ? substr($url['path'], 1) : ''),
(isset($url['user']) ? $url['user'] : ''),
(isset($url['pass']) ? $url['pass'] : ''));
}
return $this->connections[$dsn];
}
function &_getInstance()
{
static $instance;
if (is_null($instance))
{
$instance = new DataSource();
}
return $instance;
}
}
I don't use ArrayList anymore (in favor of regular ol' arrays), and I've refactored out all references to it, but here it is anyway:
PHP Code:
class ArrayList
{
var $arr;
function ArrayList()
{
if (func_num_args() == 1)
{
$this->arr = ArrayList::valueOf(func_get_arg(0));
}
}
function add($index, &$element)
{
$this->arr = array_splice($this->arr, $index, 0, array($element));
}
function addAll($index, &$list)
{
$this->arr = array_splice($this->arr, $index, 0, $list->toArray());
}
function append(&$element)
{
$this->arr[] =& $element;
}
function appendAll(&$list)
{
$this->arr = array_merge($this->arr, $list->toArray());
}
function clear()
{
unset($this->arr);
$this->arr = array();
}
function contains(&$element)
{
return in_array($element, $this->arr, TRUE);
}
function containsAll(&$list)
{
foreach ($list->toArray() as $element)
{
if (! in_array($element, $this->arr, TRUE))
{
return FALSE;
}
}
return TRUE;
}
function &get($index)
{
return $this->arr[$index];
}
function &getFirst()
{
return $this->arr[0];
}
function &getLast()
{
return $this->arr[count($this->arr) - 1];
}
function indexOf(&$element)
{
$index = array_search($element, $this->arr);
if ($index !== FALSE)
{
return $index;
}
return -1;
}
function isEmpty()
{
return (count($this->arr) == 0);
}
function &iterator()
{
return $this->listIterator(0);
}
function lastIndexOf(&$element)
{
$pos = array_search($element, array_reverse($this->arr));
if ($pos !== FALSE)
{
return count($this->arr) - 1 - $pos;
}
return -1;
}
function &listIterator($fromIndex = 0)
{
include_once('ArrayListIterator.class.php');
return new ArrayListIterator($this, $fromIndex);
}
function prepend(&$element)
{
array_unshift($this->arr, array($element));
}
function prependAll(&$list)
{
array_unshift($this->arr, $list->toArray());
}
function &remove($index)
{
$element =& $this->arr[$index];
array_splice($this->arr, $index, 1);
return $element;
}
function removeAll(&$list)
{
$size = count($this->arr);
$list = $list->toArray();
$this->arr = array_diff($this->arr, $list);
return (count($this->arr) != $size);
}
function &removeFirst()
{
$element =& $this->arr[0];
array_shift($this->arr);
return $element;
}
function &removeLast()
{
$element =& $this->arr[$this->size() - 1];
array_pop($this->arr);
return $element;
}
function removeRange($fromIndex, $toIndex)
{
array_splice($this->arr, $fromIndex, $toIndex - $fromIndex);
}
function retainAll(&$list)
{
$size = count($this->arr);
$list = $list->toArray();
$this->arr = array_intersect($this->arr, $list);
return (count($this->arr) != $size);
}
function &set($index, &$element)
{
$oldElement =& $this->get($index);
$this->arr[$index] =& $element;
return $oldElement;
}
function size()
{
return count($this->arr);
}
function &subList($fromIndex, $toIndex)
{
$fromIndex = (int) $fromIndex;
$toIndex = (int) $toIndex;
if ($toIndex < $fromIndex)
{
return NULL;
}
return new ArrayList(array_slice($this->arr, $fromIndex, $toIndex - $fromIndex));
}
function &toArray()
{
return $this->arr;
}
function valueOf($arg)
{
if (is_object($arg) && method_exists($arg, 'toArray'))
{
return array_values($arg->toArray());
}
return array_values((array) $arg);
}
}
Bookmarks