Source for file DpProperties.php
Documentation is available at DpProperties.php
* The DutchPIPE property and coinherit system which all objects extend on
* DutchPIPE version 0.4; PHP version 5
* LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
* If you did not receive a copy of the DutchPIPE license, you can obtain one at
* http://dutchpipe.org/license/1_0.txt or by sending a note to
* license@dutchpipe.org, in which case you will be mailed a copy immediately.
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Subversion: $Id: DpProperties.php 278 2007-08-19 22:52:25Z ls $
* @link http://dutchpipe.org/manual/package/DutchPIPE
* The DutchPIPE property and coinherit system which all objects extend on
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Release: 0.2.1
* @link http://dutchpipe.org/manual/package/DutchPIPE
* Generic property array for dynamic, simple vars
private $mProperties = array();
* Coinherited objects (for simulated coinherits)
* Sets the value of a DutchPIPE property using PHP member overloading
* @param string $nm name of property
* @param string $val value of property
public function __set($nm, $val)
//echo "__set($nm, $val) called... ";
* If a special array is given as constructed by the new_dp_property()
* method, initializes a new DutchPIPE property
&& 'new_dp_property' === $val[0]) {
//echo "Initialized new property $nm.\n";
if (!isset ($this->mProperties[$nm]) &&
foreach ($this->mCoinherits as $coinherit) {
if (isset ($coinherit->{$nm})) {
$coinherit->{'set' . ucfirst($nm)}($val);
$this->mProperties[$nm] = array($val[1], $val[2], $val[3]);
* If $nm is 'foo' and the method 'setFoo()' is defined,
* $this->foo = ... will use that method to set the value;
* All member setters and most setter method calls will have
* only one argument and this is the fastest way to handle the
* Handle method setters with multiple arguments
if (isset ($this->mProperties[$nm])) {
/* If no setter is defined, just stores the new value */
if (is_null($this->mProperties[$nm][1])) {
$this->mProperties[$nm][0] = $val;
/* If the setter is FALSE this property is read-only */
if (FALSE === $this->mProperties[$nm][1]) {
/* Use the setter function */
$this->{$this->mProperties[$nm][1]}($val);
if (isset ($this->mCoinherits) && !is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
if (isset ($coinherit->{$nm})) {
$coinherit->{$nm} = $val;
// echo dp_text("Invalid __set, %s not defined.\n", $nm);
// Should throw error in future.
* Gets the value of a DutchPIPE property using PHP member overloading
* @param string $nm name of property
* @return mixed value of property
public function __get($nm)
//echo "__get($nm) called\n";
// Only find dp properties in main object, ordinary members are found
// without using this method:
if (isset ($this->mProperties[$nm])) {
$rval = $this->{'get' . ucfirst($nm)}();
if (is_null($this->mProperties[$nm][2])) {
return is_array($this->mProperties[$nm][0])
? (array) $this->mProperties[$nm][0]
: $this->mProperties[$nm][0];
$rval = $this->{$this->mProperties[$nm][2]}();
// Find both dp properties and ordinary members in coinherits:
if (!is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
if (isset ($coinherit->{$nm})) {
return $coinherit->{$nm};
// echo dp_text("Invalid __get, %s not defined.\n", $nm);
// Should throw error in future.
* Determines if a property is defined in this object using PHP member overloading
* @param string $nm name of property
* @return boolean TRUE if property exists and not NULL, FALSE otherwise
//echo "__isset($nm) called...";
// Only find dp properties in main object, ordinary members are found
// without using this method:
if (isset ($this->mProperties[$nm])) {
// Find both dp properties and ordinary members in coinherits:
if (!is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
if (isset ($coinherit->{$nm})) {
//echo "Found $nm in coinherit\n";
* Unsets the given DutchPIPE property using PHP member overloading
* @param string $nm name of property
//echo "__unset($nm) called\n";
// Only find dp properties in main object, ordinary members are found
// without using this method:
if (isset ($this->mProperties[$nm])
&& FALSE !== $this->mProperties[$nm][1]) {
unset ($this->mProperties[$nm]);
// Find both dp properties and ordinary members in coinherits:
if (!is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
if (isset ($coinherit->{$nm})) {
unset ($coinherit->{$nm});
* Handles set and get methods for properties using PHP member overloading
* @param string $nm name of property
public function __call($name, $params)
//echo "__call($name, $params) called\n";
//echo "params:\n"; print_r($params);
//echo $part1 . '---' . $part2 . "\n";
if (isset ($this->mProperties[$part2])) {
if (count($params) <= 1) {
// Find both dp properties and ordinary members in coinherits:
if (!is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
//echo dp_text("Invalid __call, method %s does not exist.\n", $name);
* Determines if a property is defined in this object
* Same as isset($ob->{$nm}), except that this method returns TRUE
* for properties set to NULL.
* @param string $nm name of property
* @return boolean TRUE if property exists, FALSE otherwise
// First look for property in main object:
if (isset ($this->mProperties[$nm])) {
// ... then search for property in coinherits:
if (!is_null($this->mCoinherits)) {
foreach ($this->mCoinherits as $coinherit) {
* Directly set the value of an existing DutchPIPE property
* @param string $nm name of property
* @param string $val value of property
if (isset ($this->mProperties[$nm])) {
$this->mProperties[$nm][0] = $val;
* Directly retrieve the value of an existing DutchPIPE property
* @param string $nm name of property
* @return mixed value of property
return !isset ($this->mProperties[$nm]) ? NULL
: $this->mProperties[$nm][0];
* "Coinherit" a class located at the given pathname
* @param string $pathname path to code from universe base path
$this->mCoinherits = array();
} elseif (isset ($this->mCoinherit[$pathname])) {
$classname = explode("/", $pathname);
$object = new $classname($this);
$this->mCoinherits[$pathname] = & $object;
* Removes properties and coinherits
* Called by DpObject::removeDpObject, unsets all properties and coinherits.
* This makes sure all object pointers are removed and object can be removed
* from memory by PHP's cleanup mechanism.
* @see DpObject::removeDpObject
if (!is_null($this->mCoinherits)) {
for ($i = 0, $sz = count($this->mCoinherits); $i < $sz; $i++ ) {
$this->mCoinherits[$i] = NULL;
unset ($this->mCoinherits[$i]);
for ($i = 0, $sz = count($this->mProperties); $i < $sz; $i++ ) {
$this->mProperties[$i] = NULL;
unset ($this->mProperties[$i]);
$this->mCoinherits = NULL;
unset ($this->mCoinherits);
|