Services_Ebay
[ class tree: Services_Ebay ] [ index: Services_Ebay ] [ all elements ]

Source for file Model.php

Documentation is available at Model.php

  1. <?PHP
  2. /**
  3.  * Base class for all models
  4.  *
  5.  * $Id: Model.php,v 1.2 2004/11/07 12:14:37 schst Exp $
  6.  *
  7.  * The base class provides __set() and __get()
  8.  * as well as some other helper methods.
  9.  *
  10.  * @package Services_Ebay
  11.  * @author  Stephan Schmidt <schst@php.net>
  12.  */
  13. class Services_Ebay_Model implements ArrayAccess
  14. {
  15.    /**
  16.     * properties of the model
  17.     *
  18.     * @var  array 
  19.     */
  20.     protected $properties = array();
  21.  
  22.    /**
  23.     * properties that are stored in eBay's database
  24.     *
  25.     * These are stored to check, which fields have been modified
  26.     * in the item
  27.     *
  28.     * @var  array 
  29.     */
  30.     protected $eBayProperties = array();
  31.  
  32.    /**
  33.     * optional session, used to send API calls
  34.     *
  35.     * @var  object Services_Ebay_Session 
  36.     */
  37.     protected $session;
  38.     
  39.    /**
  40.     * property that stores the unique identifier (=pk) of the model
  41.     *
  42.     * @var string 
  43.     */
  44.     protected $primaryKey = null;
  45.     
  46.     /**
  47.     * create new model
  48.     *
  49.     * @param    array   properties
  50.     */
  51.     public function __construct($props$session = null)
  52.     {
  53.         if (is_array($props)) {
  54.             $this->properties = $props;
  55.         elseif ($this->primaryKey !== null{
  56.             $this->properties[$this->primaryKey$props;
  57.         }
  58.         if$session instanceof Services_Ebay_Session{
  59.             $this->session = $session;
  60.         }
  61.         $this->eBayProperties = $this->properties;
  62.     }
  63.     
  64.    /**
  65.     * set the session
  66.     *
  67.     * @param    object Services_Ebay_Session 
  68.     */
  69.     public function setSession(Services_Ebay_Session $session)
  70.     {
  71.         $this->session = $session;
  72.     }
  73.     
  74.    /**
  75.     * get a property
  76.     *
  77.     * @param    string   property name
  78.     * @return   mixed    property value
  79.     */
  80.     public function __get($prop)
  81.     {
  82.         if (isset($this->properties[$prop])) {
  83.             return $this->properties[$prop];
  84.         }
  85.     }
  86.     
  87.    /**
  88.     * set a property
  89.     *
  90.     * @param    string   property name
  91.     * @param    mixed    property value
  92.     */
  93.     public function __set($prop$value)
  94.     {
  95.         $this->properties[$prop$value;
  96.     }
  97.     
  98.    /**
  99.     * return all properties of the user
  100.     *
  101.     * @return   array 
  102.     */
  103.     public function toArray()
  104.     {
  105.         return $this->properties;
  106.     }
  107.  
  108.    /**
  109.     * get the properties that have been modified,
  110.     * since the item has been fetched the last
  111.     * time.
  112.     *
  113.     * This does not involve an API-call
  114.     *
  115.     * @return   array 
  116.     */
  117.     public function GetModifiedProperties()
  118.     {
  119.         $modified = array();
  120.         foreach ($this->properties as $key => $value{
  121.             if (!isset($this->eBayProperties[$key])) {
  122.                 $modified[$key$value;
  123.                 continue;
  124.             }
  125.             if ($this->eBayProperties[$key=== $value{
  126.                 continue;
  127.             }
  128.             $modified[$key$value;
  129.         }
  130.         return $modified;
  131.     }
  132.  
  133.    /**
  134.     * check, whether a property exists
  135.     *
  136.     * This is needed to implement the ArrayAccess interface
  137.     *
  138.     * @param    string    property
  139.     */
  140.     public function offsetExists($offset)
  141.     {
  142.         if (isset($this->properties[$offset])) {
  143.             return true;
  144.         }
  145.         return false;
  146.     }
  147.  
  148.    /**
  149.     * get a property
  150.     *
  151.     * This is needed to implement the ArrayAccess interface
  152.     *
  153.     * @param    string    property
  154.     */
  155.     public function offsetGet($offset)
  156.     {
  157.         return $this->properties[$offset];
  158.     }
  159.  
  160.    /**
  161.     * set a property
  162.     *
  163.     * This is needed to implement the ArrayAccess interface
  164.     *
  165.     * @param    string    property
  166.     * @param    mixed    value
  167.     */
  168.     public function offsetSet($offset$value)
  169.     {
  170.         $this->properties[$offset$value;
  171.     }
  172.  
  173.    /**
  174.     * unset a property
  175.     *
  176.     * This is needed to implement the ArrayAccess interface
  177.     *
  178.     * @param    string    property
  179.     */
  180.     public function offsetUnset($offset)
  181.     {
  182.         unset($this->properties[$offset]);
  183.     }
  184. }
  185. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.