示例#1
0
 /**
  * Constructor
  *
  * Do not call the constructor directly; see {@link xPDO::newObject()}.
  *
  * All derivatives of xPDOObject must redeclare this method, and must call
  * the parent method explicitly before any additional logic is executed, e.g.
  *
  * <code>
  * protected function __construct(& $xpdo) {
  *     parent  :: __construct($xpdo);
  *     // Any additional constructor tasks here
  * }
  * </code>
  *
  * @access public
  * @param xPDO &$xpdo A reference to a valid xPDO instance.
  * @return xPDOObject
  */
 public function __construct(xPDO &$xpdo)
 {
     $this->container = $xpdo->config['dbname'];
     $this->_class = get_class($this);
     $pos = strrpos($this->_class, '_');
     if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) {
         $this->_class = substr($this->_class, 0, $pos);
     }
     $this->_package = $xpdo->getPackage($this->_class);
     $this->_alias = $this->_class;
     $this->_table = $xpdo->getTableName($this->_class);
     $this->_tableMeta = $xpdo->getTableMeta($this->_class);
     $this->_fields = $xpdo->getFields($this->_class);
     $this->_fieldMeta = $xpdo->getFieldMeta($this->_class);
     $this->_aggregates = $xpdo->getAggregates($this->_class);
     $this->_composites = $xpdo->getComposites($this->_class);
     $this->_options[xPDO::OPT_CALLBACK_ON_REMOVE] = isset($xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE]) && !empty($xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE]) ? $xpdo->config[xPDO::OPT_CALLBACK_ON_REMOVE] : null;
     $this->_options[xPDO::OPT_CALLBACK_ON_SAVE] = isset($xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE]) && !empty($xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE]) ? $xpdo->config[xPDO::OPT_CALLBACK_ON_SAVE] : null;
     $this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS] = isset($xpdo->config[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) && $xpdo->config[xPDO::OPT_HYDRATE_RELATED_OBJECTS];
     $this->_options[xPDO::OPT_HYDRATE_ADHOC_FIELDS] = isset($xpdo->config[xPDO::OPT_HYDRATE_ADHOC_FIELDS]) && $xpdo->config[xPDO::OPT_HYDRATE_ADHOC_FIELDS];
     $this->_options[xPDO::OPT_HYDRATE_FIELDS] = isset($xpdo->config[xPDO::OPT_HYDRATE_FIELDS]) && $xpdo->config[xPDO::OPT_HYDRATE_FIELDS];
     $this->_options[xPDO::OPT_ON_SET_STRIPSLASHES] = isset($xpdo->config[xPDO::OPT_ON_SET_STRIPSLASHES]) && $xpdo->config[xPDO::OPT_ON_SET_STRIPSLASHES];
     $this->_options[xPDO::OPT_VALIDATE_ON_SAVE] = isset($xpdo->config[xPDO::OPT_VALIDATE_ON_SAVE]) && $xpdo->config[xPDO::OPT_VALIDATE_ON_SAVE];
     $this->_options[xPDO::OPT_VALIDATOR_CLASS] = isset($xpdo->config[xPDO::OPT_VALIDATOR_CLASS]) ? $xpdo->config[xPDO::OPT_VALIDATOR_CLASS] : '';
     $classVars = array();
     if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) {
         if ($this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) {
             $classVars = get_object_vars($this);
         }
         foreach ($relatedObjs as $aAlias => $aMeta) {
             if (!array_key_exists($aAlias, $this->_relatedObjects)) {
                 if ($aMeta['cardinality'] == 'many') {
                     $this->_relatedObjects[$aAlias] = array();
                 } else {
                     $this->_relatedObjects[$aAlias] = null;
                 }
             }
             if ($this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS] && !array_key_exists($aAlias, $classVars)) {
                 $this->{$aAlias} =& $this->_relatedObjects[$aAlias];
                 $classVars[$aAlias] = 1;
             }
         }
     }
     if ($this->_options[xPDO::OPT_HYDRATE_FIELDS]) {
         if (!$this->_options[xPDO::OPT_HYDRATE_RELATED_OBJECTS]) {
             $classVars = get_object_vars($this);
         }
         foreach ($this->_fields as $fldKey => $fldVal) {
             if (!array_key_exists($fldKey, $classVars)) {
                 $this->{$fldKey} =& $this->_fields[$fldKey];
             }
         }
     }
     $this->setDirty();
     $this->xpdo =& $xpdo;
 }
示例#2
0
 /**
  * Constructor
  *
  * Do not call the constructor directly; see {@link xPDO::newObject()}.
  *
  * All derivatives of xPDOObject must redeclare this method, and must call
  * the parent method explicitly before any additional logic is executed, e.g.
  *
  * <code>
  * public function __construct(xPDO & $xpdo) {
  *     parent  :: __construct($xpdo);
  *     // Any additional constructor tasks here
  * }
  * </code>
  *
  * @access public
  * @param xPDO &$xpdo A reference to a valid xPDO instance.
  * @return xPDOObject
  */
 public function __construct(xPDO &$xpdo)
 {
     $this->xpdo =& $xpdo;
     $this->container = $xpdo->config['dbname'];
     $this->_class = get_class($this);
     $pos = strrpos($this->_class, '_');
     if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) {
         $this->_class = substr($this->_class, 0, $pos);
     }
     $this->_package = $xpdo->getPackage($this->_class);
     $this->_alias = $this->_class;
     $this->_table = $xpdo->getTableName($this->_class);
     $this->_tableMeta = $xpdo->getTableMeta($this->_class);
     $this->_fields = $xpdo->getFields($this->_class);
     $this->_fieldMeta = $xpdo->getFieldMeta($this->_class);
     $this->_fieldAliases = $xpdo->getFieldAliases($this->_class);
     $this->_aggregates = $xpdo->getAggregates($this->_class);
     $this->_composites = $xpdo->getComposites($this->_class);
     if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) {
         foreach ($relatedObjs as $aAlias => $aMeta) {
             if (!array_key_exists($aAlias, $this->_relatedObjects)) {
                 if ($aMeta['cardinality'] == 'many') {
                     $this->_relatedObjects[$aAlias] = array();
                 } else {
                     $this->_relatedObjects[$aAlias] = null;
                 }
             }
         }
     }
     foreach ($this->_fieldAliases as $fieldAlias => $field) {
         $this->addFieldAlias($field, $fieldAlias);
     }
     $this->setDirty();
 }
 /**
  * Constructor
  *
  * Do not call the constructor directly; see {@link xPDO::newObject()}.
  *
  * All derivatives of xPDOObject must redeclare this method, and must call
  * the parent method explicitly before any additional logic is executed, e.g.
  *
  * <code>
  * public function __construct(xPDO & $xpdo) {
  *     parent  :: __construct($xpdo);
  *     // Any additional constructor tasks here
  * }
  * </code>
  *
  * @access public
  * @param xPDO &$xpdo A reference to a valid xPDO instance.
  * @return xPDOObject
  */
 public function __construct(xPDO &$xpdo)
 {
     $this->xpdo =& $xpdo;
     $this->container = $xpdo->config['dbname'];
     $this->_class = get_class($this);
     $pos = strrpos($this->_class, '_');
     if ($pos !== false && substr($this->_class, $pos + 1) == $xpdo->config['dbtype']) {
         $this->_class = substr($this->_class, 0, $pos);
     }
     $this->_package = $xpdo->getPackage($this->_class);
     $this->_alias = $this->_class;
     $this->_table = $xpdo->getTableName($this->_class);
     $this->_tableMeta = $xpdo->getTableMeta($this->_class);
     $this->_fields = $xpdo->getFields($this->_class);
     $this->_fieldMeta = $xpdo->getFieldMeta($this->_class);
     $this->_fieldAliases = $xpdo->getFieldAliases($this->_class);
     $this->_aggregates = $xpdo->getAggregates($this->_class);
     $this->_composites = $xpdo->getComposites($this->_class);
     $classVars = array();
     if ($relatedObjs = array_merge($this->_aggregates, $this->_composites)) {
         if ($this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS)) {
             $classVars = get_object_vars($this);
         }
         foreach ($relatedObjs as $aAlias => $aMeta) {
             if (!array_key_exists($aAlias, $this->_relatedObjects)) {
                 if ($aMeta['cardinality'] == 'many') {
                     $this->_relatedObjects[$aAlias] = array();
                 } else {
                     $this->_relatedObjects[$aAlias] = null;
                 }
             }
             if ($this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS) && !array_key_exists($aAlias, $classVars)) {
                 $this->{$aAlias} =& $this->_relatedObjects[$aAlias];
                 $classVars[$aAlias] = 1;
             }
         }
     }
     if ($this->getOption(xPDO::OPT_HYDRATE_FIELDS)) {
         if (!$this->getOption(xPDO::OPT_HYDRATE_RELATED_OBJECTS)) {
             $classVars = get_object_vars($this);
         }
         foreach ($this->_fields as $fldKey => $fldVal) {
             if (!array_key_exists($fldKey, $classVars)) {
                 $this->{$fldKey} =& $this->_fields[$fldKey];
             }
         }
     }
     foreach ($this->_fieldAliases as $fieldAlias => $field) {
         $this->addFieldAlias($field, $fieldAlias);
     }
     $this->setDirty();
 }