Source for file DomainObject.php

Documentation is available at DomainObject.php

  1. <?php
  2.     /**
  3.      * Domain object interface and classes
  4.      * @copyright Copyright (c) 2007 Mirchev Ideas Ltd. All rights reserved.
  5.      * @package MIPHPF
  6.      */
  7.  
  8.     /**
  9.      * Domain object interface
  10.      * 
  11.      * @copyright Copyright (c) 2007 Mirchev Ideas Ltd. All rights reserved.
  12.      * @package MIPHPF
  13.      */
  14.     interface miDomainObject {
  15.         public function read($pkValue);
  16.         public function insert();
  17.         public function update();
  18.         public function delete($pkValue null);
  19.     }
  20.     
  21.     /**
  22.      * Default domain object class
  23.      *
  24.      * @copyright Copyright (c) 2007 Mirchev Ideas Ltd. All rights reserved.
  25.      * @package MIPHPF
  26.      */
  27.     class miDefaultDomainObject implements miDomainObject {
  28.         protected $_record;
  29.         
  30.         public function __construct($record)
  31.         {
  32.             $this->_record = $record;
  33.         }
  34.         
  35.         /**
  36.          * Return the name of the primary key of the underlying SQLRecord
  37.          * Used by miDefaultView
  38.          * 
  39.          * @return string the name of the primary key
  40.          */
  41.         public function getPKName()
  42.         {
  43.             return $this->_record->getPrimaryKeyColumn();
  44.         }
  45.         
  46.         /**
  47.          * Get domain object value
  48.          *
  49.          * @param string $name 
  50.          * @return mixed 
  51.          */
  52.         public function get($name)
  53.         {
  54.             return $this->_record->get($name);
  55.         }
  56.  
  57.         /**
  58.          * Get all domain object values
  59.          *
  60.          * @return array 
  61.          */
  62.         public function getRow()
  63.         {
  64.             return $this->_record->getRow();
  65.         }
  66.         
  67.         /**
  68.          * Set all domain object values
  69.          * 
  70.          * @param array $row 
  71.          * @return void 
  72.          */
  73.         public function setRow(array $row)
  74.         {
  75.             $this->_record->setRow($row);
  76.         }
  77.         
  78.         /**
  79.          * Set domain object value
  80.          *
  81.          * @param string $name 
  82.          * @param mixed $value 
  83.          */
  84.         public function set($name$value)
  85.         {
  86.             // Do not update the primary key
  87.             if ($this->_record->getPrimaryKeyColumn(== $name)
  88.                 return;
  89.             $this->_record->set($name$value);
  90.         }
  91.         
  92.         /**
  93.          * Read the domain object
  94.          *
  95.          * @param mixed $pkValue 
  96.          */
  97.         public function read($pkValue)
  98.         {
  99.             $this->_record->readPK($pkValue);
  100.         }
  101.         
  102.         /**
  103.          * Insert the domain object as new record
  104.          */
  105.         public function insert()
  106.         {
  107.             $this->validate();
  108.             $this->validateOnInsert();
  109.             return $this->_record->insert();
  110.         }
  111.         
  112.         /**
  113.          * Update the domain object
  114.          */
  115.         public function update()
  116.         {
  117.             $this->validate();
  118.             $this->validateOnUpdate();
  119.             return $this->_record->update();
  120.         }
  121.         
  122.         /**
  123.          * Delete the domain object
  124.          */
  125.         public function delete($pkValue null)
  126.         {
  127.             if ($pkValue !== null)
  128.                 $this->_record->set($this->_record->getPrimaryKeyColumn()$pkValue);
  129.             return $this->_record->delete();
  130.         }
  131.         
  132.         /**
  133.          * Validates the object
  134.          *
  135.          * @throws miException
  136.          */
  137.         public function validate()
  138.         {
  139.             
  140.         }
  141.         
  142.         /**
  143.          * Validates the object for insert operation
  144.          *
  145.          * @throws miException
  146.          */
  147.         public function validateOnInsert()
  148.         {
  149.             
  150.         }
  151.         
  152.         /**
  153.          * Validates the object for update operation
  154.          *
  155.          * @throws miException
  156.          */
  157.         public function validateOnUpdate()
  158.         {
  159.             
  160.         }
  161.     }
  162. ?>

Documentation generated on Thu, 08 May 2008 16:57:26 +0300 by phpDocumentor 1.4.1