BRICKOO::GetSingleton (since version 2.0)
Syntax
object GetSingleton ( string $objectName , array $arguments , array $decorators )
Parameters
objectName
The name of the object to retrieve the reference from.
arguments
The arguments to pass to the object constructor method.
decorators
The decorators to bind to the singleton reference.
Each decorator can have an array with array args and string type to pass constructor arguments or the decorator type.
Each decorator can have an array with array args and string type to pass constructor arguments or the decorator type.
Description
Returns an singleton reference of the requested object.
Passes the arguments to the constructor of the created reference.
Binds requested decorators to the object reference.
Note:
This method will always return the same reference from the requested object.
With BrickOO you do not have to chain classes to extend functionality, instead you can bind and unbind decorators to an new or existing singleton reference at any time.
Passes the arguments to the constructor of the created reference.
Binds requested decorators to the object reference.
Note:
This method will always return the same reference from the requested object.
With BrickOO you do not have to chain classes to extend functionality, instead you can bind and unbind decorators to an new or existing singleton reference at any time.
Return
object object Returns an singleton reference of the object requested.
Examples
<?php
class person
{
public $name;
public $age;
public function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}
public function getInformation()
{
return $this->name . ' is ' . $this->age . ' years old ';
}
}
// retrieving first singleton of person
$person_1 = BRICKOO::GetSingleton('person', array('mike', 20));
$information = $person_1->getInformation();
echo($information);
// make changes on the first singleton reference
$person_1->name = 'tom';
$person_1->age = 30;
// retrieving second singleton reference of person
// constructor arguments will NOT be executed
$person_2 = BRICKOO::GetSingleton('person', array('mike', 20));
$information = $person_2->getInformation();
echo($information);
?>
Output:
mike is 20 years old
tom is 30 years old
class person
{
public $name;
public $age;
public function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}
public function getInformation()
{
return $this->name . ' is ' . $this->age . ' years old ';
}
}
// retrieving first singleton of person
$person_1 = BRICKOO::GetSingleton('person', array('mike', 20));
$information = $person_1->getInformation();
echo($information);
// make changes on the first singleton reference
$person_1->name = 'tom';
$person_1->age = 30;
// retrieving second singleton reference of person
// constructor arguments will NOT be executed
$person_2 = BRICKOO::GetSingleton('person', array('mike', 20));
$information = $person_2->getInformation();
echo($information);
?>
Output:
mike is 20 years old
tom is 30 years old
Last change 10/16/2009