All pastes #591694 Raw Edit

Mine

public text v1 · immutable
#591694 ·published 2007-06-27 10:37 UTC
rendered paste body
<?php

error_reporting ( E_ALL & E_STRICT );
/*
 * @date 		Jun 27, 2007
 * @author	Berry Langerak <berry@qsp.nl>
 * @package	
 */
class ServiceLocator
{
	static private $objects;
	
	private function __construct ()
	{
	}
	
	static public function register ( $name, $object )
	{
		if ( is_object ( $object ) === false )
		{
			die ( 'Only objectz plz. \'kthnx.' );
		}
		self::$objects[$name] = $object;
	}
	
	static public function get ( $name )
	{
		if ( isset ( self::$objects[$name] ) ) 
		{
			return self::$objects[$name];
		}
		else
		{
			return false;
		}
	}

}

class mysqlConnection
{
	private $host;

	public function __construct ( $host, $user, $pass, $name )
	{
		$this -> host = $host;
	}

	public function getHost ()
	{
		return $this -> host;
	}

}

class ActiveRecordFinder
{
	private $connection;
	
	static public function getById ( $entity, $id )
	{
		// Nu hebben we dus geen $connection.
		$connection = ServiceLocator::get ( 'connection' );
		// en nu wel.

		return $connection -> getHost ();
	}

}

$connection = new mysqlConnection ( 'localhost', 'user', 'pass', 'dbname' );
ServiceLocator::register ( 'connection', $connection );

echo ActiveRecordFinder::getById ( 'test', 1 );


?>