I have been studying the Registry class provided by the book PHP 5 social Networking. It is not clear exactly what it is doing. The usual Registry design pattern is something like the one presented in PHP Registry Pattern. This is one seems different:
class Registry {
/**
* Array of objects
*/
private $objects;
/**
* Array of settings
*/
private $settings;
public function __construct() {
}
/**
* Create a new object and store it in the registry
* @param String $object the object file prefix
* @param String $key pair for the object
* @return void
*/
public function createAndStoreObject( $object, $key )
{
require_once( $object . '.class.php' );
$this->objects[ $key ] = new $object( $this );
}
/**
* Get an object from the registries store
* @param String $key the objects array key
* @return Object
*/
public function getObject( $key )
{
return $this->objects[ $key ];
}
}
I am not able to understand the structure "new $object( $this )" which belongs to the function "createAndStoreObject( $object, $key )".
Inside the index.php, this class is used like this:
require('registry/registry.class.php');
$registry = new Registry();
$registry->createAndStoreObject( 'mysqldb', 'db' );
include(FRAMEWORK_PATH . 'config.php'); // Config.php contains the database configuration
// create a database connection
$registry->getObject('db')->newConnection( $configs['db_host_sn'], $configs['db_user_sn'], $configs['db_pass_sn'], $configs['db_name_sn']);
// store settings in our registry
$settingsSQL = "SELECT `key`, `value` FROM settings"; // settings is a table previously defined
$registry->getObject('db')->executeQuery( $settingsSQL );
while( $setting = $registry->getObject('db')->getRows() )
{
$registry->storeSetting( $setting['value'], $setting['key'] );
}
Or
$registry->createAndStoreObject( 'urlprocessor', 'url' );
$registry->getObject('url')->getURLData();
0) What does it mean that "$this"?
1) Can one explain me this kind of structure in the index file?
2) Is there any readable book that I can use to understand this kind of advanced php?