Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#216 Login/register    Go to Bottom
Go to Top

Source for file DpProperties.php

Documentation is available at DpProperties.php

  1. <?php
  2. /**
  3.  * The DutchPIPE property and coinherit system which all objects extend on
  4.  *
  5.  * DutchPIPE version 0.4; PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  8.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  9.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  10.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  11.  *
  12.  * @package    DutchPIPE
  13.  * @subpackage dpuniverse_std
  14.  * @author     Lennert Stock <ls@dutchpipe.org>
  15.  * @copyright  2007 Lennert Stock
  16.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  17.  * @version    Subversion: $Id: DpProperties.php 278 2007-08-19 22:52:25Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  */
  20.  
  21. /**
  22.  * The DutchPIPE property and coinherit system which all objects extend on
  23.  *
  24.  * @package    DutchPIPE
  25.  * @subpackage dpuniverse_std
  26.  * @author     Lennert Stock <ls@dutchpipe.org>
  27.  * @copyright  2007 Lennert Stock
  28.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  29.  * @version    Release: 0.2.1
  30.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  31.  */
  32. {
  33.     /**
  34.      * Generic property array for dynamic, simple vars
  35.      *
  36.      * @var         type 
  37.      * @access      private
  38.      */
  39.     private $mProperties array();
  40.  
  41.     /**
  42.      * Coinherited objects (for simulated coinherits)
  43.      */
  44.     private $mCoinherits;
  45.  
  46.     /**
  47.      * Sets the value of a DutchPIPE property using PHP member overloading
  48.      *
  49.      * @access     private
  50.      * @param      string    $nm        name of property
  51.      * @param      string    $val       value of property
  52.      */
  53.     public function __set($nm$val)
  54.     {
  55.         //echo "__set($nm, $val) called... ";
  56.         /*
  57.          * If a special array is given as constructed by the new_dp_property()
  58.          * method, initializes a new DutchPIPE property
  59.          */
  60.         if (is_array($val&& === count($val)
  61.                 && 'new_dp_property' === $val[0]{
  62.             //echo "Initialized new property $nm.\n";
  63.  
  64.             if (!isset($this->mProperties[$nm]&&
  65.                     !is_null($this->mCoinherits)) {
  66.                 foreach ($this->mCoinherits as $coinherit{
  67.                     if (isset($coinherit->{$nm})) {
  68.                         $coinherit->{'set' ucfirst($nm)}($val);
  69.                         return;
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             $this->mProperties[$nmarray($val[1]$val[2]$val[3]);
  75.             return;
  76.         }
  77.  
  78.         /*
  79.          * If $nm is 'foo' and the method 'setFoo()' is defined,
  80.          * $this->foo = ... will use that method to set the value;
  81.          */
  82.         if (method_exists($this($setter 'set' ucfirst($nm)))) {
  83.             if (func_num_args(<= 2{
  84.                 /*
  85.                  * All member setters and most setter method calls will have
  86.                  * only one argument and this is the fastest way to handle the
  87.                  * call.
  88.                  */
  89.                 $this->{$setter}($val);
  90.             else {
  91.                 /*
  92.                  * Handle method setters with multiple arguments
  93.                  */
  94.                 $args func_get_args();
  95.                 call_user_func_array(array(&$this$setter),
  96.                     array_slice($args1));
  97.             }
  98.  
  99.             return;
  100.         }
  101.  
  102.         if (isset($this->mProperties[$nm])) {
  103.             /* If no setter is defined, just stores the new value */
  104.             if (is_null($this->mProperties[$nm][1])) {
  105.                 $this->mProperties[$nm][0$val;
  106.                 return;
  107.             }
  108.             /* If the setter is FALSE this property is read-only */
  109.             if (FALSE === $this->mProperties[$nm][1]{
  110.                 return;
  111.             }
  112.  
  113.             /* Use the setter function */
  114.             if (func_num_args(<= 2{
  115.                 $this->{$this->mProperties[$nm][1]}($val);
  116.             else {
  117.                 $args func_get_args();
  118.                 call_user_func_array(array(&$this$this->mProperties[$nm][1]),
  119.                     array_slice($args1));
  120.             }
  121.             return;
  122.         }
  123.  
  124.         if (isset($this->mCoinherits&& !is_null($this->mCoinherits)) {
  125.                 foreach ($this->mCoinherits as $coinherit{
  126.                     if (isset($coinherit->{$nm})) {
  127.                     $coinherit->{$nm$val;
  128.                     return;
  129.                 }
  130.             }
  131.         }
  132.  
  133.         // echo dp_text("Invalid __set, %s not defined.\n", $nm);
  134.         // Should throw error in future.
  135.         }
  136.  
  137.     /**
  138.      * Gets the value of a DutchPIPE property using PHP member overloading
  139.      *
  140.      * @access     private
  141.      * @param      string    $nm        name of property
  142.      * @return     mixed     value of property
  143.      */
  144.     public function __get($nm)
  145.     {
  146.         //echo "__get($nm) called\n";
  147.  
  148.         // Only find dp properties in main object, ordinary members are found
  149.         // without using this method:
  150.         if (isset($this->mProperties[$nm])) {
  151.             if (method_exists($this'get' ucfirst($nm))) {
  152.                 if (func_num_args(<= 1{
  153.                     $rval $this->{'get' ucfirst($nm)}();
  154.                 else {
  155.                     $args func_get_args();
  156.                     $rval call_user_func_array(array(&$this'get' ucfirst($nm)),
  157.                         array_slice($args1));
  158.                 }
  159.                 return $rval;
  160.             }
  161.  
  162.             if (is_null($this->mProperties[$nm][2])) {
  163.                 return is_array($this->mProperties[$nm][0])
  164.                     ? (array)$this->mProperties[$nm][0]
  165.                     : $this->mProperties[$nm][0];
  166.             }
  167.  
  168.             if (func_num_args(<= 2{
  169.                 $rval $this->{$this->mProperties[$nm][2]}();
  170.             else {
  171.                 $args func_get_args();
  172.                 $rval call_user_func_array(array(&$this,
  173.                     $this->mProperties[$nm][2])array_slice($args1));
  174.             }
  175.             return $rval;
  176.         }
  177.  
  178.         // Find both dp properties and ordinary members in coinherits:
  179.         if (!is_null($this->mCoinherits)) {
  180.             foreach ($this->mCoinherits as $coinherit{
  181.                 if (isset($coinherit->{$nm})) {
  182.                     return $coinherit->{$nm};
  183.                 }
  184.             }
  185.         }
  186.  
  187.         // echo dp_text("Invalid __get, %s not defined.\n", $nm);
  188.         // Should throw error in future.
  189.         return NULL;
  190.     }
  191.  
  192.     /**
  193.      * Determines if a property is defined in this object using PHP member overloading
  194.      *
  195.      * @access     private
  196.      * @param      string    $nm        name of property
  197.      * @return     boolean   TRUE if property exists and not NULL, FALSE otherwise
  198.      */
  199.     public function __isset($nm)
  200.     {
  201.         //echo "__isset($nm) called...";
  202.  
  203.         // Only find dp properties in main object, ordinary members are found
  204.         // without using this method:
  205.         if (isset($this->mProperties[$nm])) {
  206.             //echo "Found $nm\n";
  207.             return TRUE;
  208.         }
  209.  
  210.         // Find both dp properties and ordinary members in coinherits:
  211.         if (!is_null($this->mCoinherits)) {
  212.             foreach ($this->mCoinherits as $coinherit{
  213.                 if (isset($coinherit->{$nm})) {
  214.                     //echo "Found $nm in coinherit\n";
  215.                     return TRUE;
  216.                 }
  217.             }
  218.         }
  219.         //echo "NOT FOUND!\n";
  220.         return FALSE;
  221.     }
  222.  
  223.     /**
  224.      * Unsets the given DutchPIPE property using PHP member overloading
  225.      *
  226.      * @access     private
  227.      * @param      string    $nm        name of property
  228.      */
  229.     public function __unset($nm)
  230.     {
  231.         //echo "__unset($nm) called\n";
  232.  
  233.         // Only find dp properties in main object, ordinary members are found
  234.         // without using this method:
  235.         if (isset($this->mProperties[$nm])
  236.                 && FALSE !== $this->mProperties[$nm][1]{
  237.             unset($this->mProperties[$nm]);
  238.             return;
  239.         }
  240.  
  241.         // Find both dp properties and ordinary members in coinherits:
  242.         if (!is_null($this->mCoinherits)) {
  243.             foreach ($this->mCoinherits as $coinherit{
  244.                 if (isset($coinherit->{$nm})) {
  245.                     unset($coinherit->{$nm});
  246.                     return;
  247.                 }
  248.             }
  249.         }
  250.     }
  251.  
  252.     /**
  253.      * Handles set and get methods for properties using PHP member overloading
  254.      *
  255.      * @access     private
  256.      * @param      string    $nm        name of property
  257.      */
  258.     public function __call($name$params)
  259.     {
  260.         //echo "__call($name, $params) called\n";
  261.         //echo "params:\n"; print_r($params);
  262.         if (dp_strlen($name3{
  263.             $part1 dp_substr($name03);
  264.             $part2 dp_strtolower(dp_substr($name31))
  265.                 . (dp_strlen($name== '' dp_substr($name4));
  266.  
  267.                 //echo $part1 . '---' . $part2 . "\n";
  268.  
  269.             if (isset($this->mProperties[$part2])) {
  270.                 if ('set' === $part1{
  271.                     if (count($params<= 1{
  272.                         return $this->__set(dp_strtolower(dp_substr($name3,
  273.                             1)) dp_substr($name4)array_pop($params));
  274.                     }
  275.                     call_user_func_array(array(&$this'__set'),
  276.                         array_merge(array(dp_strtolower(dp_substr($name31))
  277.                         . dp_substr($name4))$params));
  278.                     return;
  279.                 }
  280.                 if ('get' === $part1{
  281.                     if (empty($params)) {
  282.                         return $this->__get(dp_strtolower(dp_substr($name3,
  283.                             1)) dp_substr($name4));
  284.                     }
  285.                     return call_user_func_array(array(&$this'__get'),
  286.                         array_merge(array(dp_strtolower(dp_substr($name31))
  287.                         . dp_substr($name4))$params));
  288.                 }
  289.             }
  290.         }
  291.  
  292.         // Find both dp properties and ordinary members in coinherits:
  293.         if (!is_null($this->mCoinherits)) {
  294.             foreach ($this->mCoinherits as $coinherit{
  295.                 if ((isset($part1)
  296.                         && method_exists($coinherit'isDpProperty')
  297.                         && $coinherit->isDpProperty($part2))
  298.                         || method_exists($coinherit$name)) {
  299.                     return call_user_func_array(array(&$coinherit$name)$params);
  300.                 }
  301.             }
  302.         }
  303.  
  304.         //echo dp_text("Invalid __call, method %s does not exist.\n", $name);
  305.         return NULL;
  306.     }
  307.  
  308.     /**
  309.      * Determines if a property is defined in this object
  310.      *
  311.      * Same as isset($ob->{$nm}), except that this method returns TRUE
  312.      * for properties set to NULL.
  313.      *
  314.      * @param      string    $nm        name of property
  315.      * @return     boolean   TRUE if property exists, FALSE otherwise
  316.      */
  317.     final function isDpProperty($nm)
  318.     {
  319.           // First look for property in main object:
  320.         if (isset($this->mProperties[$nm])) {
  321.             return TRUE;
  322.         }
  323.  
  324.         // ... then search for property in coinherits:
  325.         if (!is_null($this->mCoinherits)) {
  326.             foreach ($this->mCoinherits as $coinherit{
  327.                 if (method_exists($coinherit'isDpProperty')
  328.                         && $coinherit->isDpProperty($nm)) {
  329.                     return TRUE;
  330.                 }
  331.             }
  332.         }
  333.         return FALSE;
  334.     }
  335.  
  336.     /**
  337.      * Directly set the value of an existing DutchPIPE property
  338.      *
  339.      * @param      string    $nm        name of property
  340.      * @param      string    $val       value of property
  341.      */
  342.     protected function setDpProperty($nm$val)
  343.     {
  344.         if (isset($this->mProperties[$nm])) {
  345.             $this->mProperties[$nm][0$val;
  346.         }
  347.     }
  348.  
  349.     /**
  350.      * Directly retrieve the value of an existing DutchPIPE property
  351.      *
  352.      * @param      string    $nm        name of property
  353.      * @return     mixed     value of property
  354.      */
  355.     protected function getDpProperty($nm)
  356.     {
  357.         return !isset($this->mProperties[$nm]NULL
  358.             : $this->mProperties[$nm][0];
  359.     }
  360.  
  361.     /**
  362.      * "Coinherit" a class located at the given pathname
  363.      *
  364.      * @param      string    $pathname  path to code from universe base path
  365.      */
  366.     function coinherit($pathname)
  367.     {
  368.         if (is_null($this->mCoinherits)) {
  369.             $this->mCoinherits array();
  370.         elseif (isset($this->mCoinherit[$pathname])) {
  371.             return;
  372.         }
  373.         require_once(DPUNIVERSE_PREFIX_PATH $pathname);
  374.         $classname =  explode("/"$pathname);
  375.         $classname ucfirst(!dp_strlen($classname[sizeof($classname1])
  376.             ? 'index' dp_substr($classname[sizeof($classname1]0-4));
  377.         $object new $classname($this);
  378.  
  379.         $this->mCoinherits[$pathname=$object;
  380.     }
  381.  
  382.     /**
  383.      * Removes properties and coinherits
  384.      *
  385.      * Called by DpObject::removeDpObject, unsets all properties and coinherits.
  386.      * This makes sure all object pointers are removed and object can be removed
  387.      * from memory by PHP's cleanup mechanism.
  388.      *
  389.      * @access     private
  390.      * @see        DpObject::removeDpObject
  391.      */
  392.     protected function removeDpProperties()
  393.     {
  394.         if (!is_null($this->mCoinherits)) {
  395.             for ($i 0$sz count($this->mCoinherits)$i $sz$i++{
  396.                 $this->mCoinherits[$iNULL;
  397.                 unset($this->mCoinherits[$i]);
  398.             }
  399.         }
  400.         for ($i 0$sz count($this->mProperties)$i $sz$i++{
  401.             $this->mProperties[$iNULL;
  402.             unset($this->mProperties[$i]);
  403.         }
  404.         $this->mCoinherits NULL;
  405.         unset($this->mCoinherits);
  406.     }
  407. }

Documentation generated on Mon, 03 Sep 2007 22:20:33 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#216
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.