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

Source for file DynamicTableEntity.php

Documentation is available at DynamicTableEntity.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2009, RealDolmen
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *     * Redistributions of source code must retain the above copyright
  9.  *       notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above copyright
  11.  *       notice, this list of conditions and the following disclaimer in the
  12.  *       documentation and/or other materials provided with the distribution.
  13.  *     * Neither the name of RealDolmen nor the
  14.  *       names of its contributors may be used to endorse or promote products
  15.  *       derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Microsoft
  29.  * @package    Microsoft_WindowsAzure
  30.  * @subpackage Storage
  31.  * @copyright  Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  32.  * @license    http://phpazure.codeplex.com/license
  33.  * @version    $Id: BlobInstance.php 14561 2009-05-07 08:05:12Z unknown $
  34.  */
  35.  
  36.  
  37. /**
  38.  * @see Microsoft_WindowsAzure_Exception
  39.  */
  40. require_once 'Microsoft/WindowsAzure/Exception.php';
  41.  
  42. /**
  43.  * @see Microsoft_WindowsAzure_Storage_TableEntity
  44.  */
  45. require_once 'Microsoft/WindowsAzure/Storage/TableEntity.php';
  46.  
  47.  
  48. /**
  49.  * @category   Microsoft
  50.  * @package    Microsoft_WindowsAzure
  51.  * @subpackage Storage
  52.  * @copyright  Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  53.  * @license    http://phpazure.codeplex.com/license
  54.  */
  55. {   
  56.     /**
  57.      * Dynamic properties
  58.      * 
  59.      * @var array 
  60.      */
  61.     protected $_dynamicProperties = array();
  62.     
  63.     /**
  64.      * Magic overload for setting properties
  65.      * 
  66.      * @param string $name     Name of the property
  67.      * @param string $value    Value to set
  68.      */
  69.     public function __set($name$value{      
  70.         $this->setAzureProperty($name$valuenull);
  71.     }
  72.  
  73.     /**
  74.      * Magic overload for getting properties
  75.      * 
  76.      * @param string $name     Name of the property
  77.      */
  78.     public function __get($name{
  79.         return $this->getAzureProperty($name);
  80.     }
  81.     
  82.     /**
  83.      * Set an Azure property
  84.      * 
  85.      * @param string $name Property name
  86.      * @param mixed $value Property value
  87.      * @param string $type Property type (Edm.xxxx)
  88.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  89.      */
  90.     public function setAzureProperty($name$value ''$type null)
  91.     {
  92.         if (strtolower($name== 'partitionkey')
  93.         {
  94.             $this->setPartitionKey($value);
  95.         }
  96.         else if (strtolower($name== 'rowkey')
  97.         {
  98.             $this->setRowKey($value);
  99.         }
  100.         else if (strtolower($name== 'etag')
  101.         {
  102.             $this->setEtag($value);
  103.         }
  104.         else
  105.         {
  106.             if (!array_key_exists(strtolower($name)$this->_dynamicProperties))
  107.             {
  108.                 // Determine type?
  109.                 if (is_null($type))
  110.                 {
  111.                     $type 'Edm.String';
  112.                     if (is_int($value))
  113.                         $type 'Edm.Int32';
  114.                     else if (is_float($value))
  115.                         $type 'Edm.Double';
  116.                     else if (is_bool($value))
  117.                         $type 'Edm.Boolean';
  118.                 }
  119.                 
  120.                 // Set dynamic property
  121.                 $this->_dynamicProperties[strtolower($name)= (object)array(
  122.                         'Name'  => $name,
  123.                         'Type'  => $type,
  124.                         'Value' => $value,
  125.                     );
  126.             }
  127.     
  128.             $this->_dynamicProperties[strtolower($name)]->Value $value;
  129.         }
  130.         return $this;
  131.     }
  132.     
  133.     /**
  134.      * Set an Azure property type
  135.      * 
  136.      * @param string $name Property name
  137.      * @param string $type Property type (Edm.xxxx)
  138.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  139.      */
  140.     public function setAzurePropertyType($name$type 'Edm.String')
  141.     {
  142.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  143.             $this->setAzureProperty($name''$type);            
  144.         }
  145.         else 
  146.         {
  147.             $this->_dynamicProperties[strtolower($name)]->Type $type;   
  148.         }
  149.         return $this;
  150.     }
  151.     
  152.     /**
  153.      * Get an Azure property
  154.      * 
  155.      * @param string $name Property name
  156.      * @param mixed $value Property value
  157.      * @param string $type Property type (Edm.xxxx)
  158.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  159.      */
  160.     public function getAzureProperty($name)
  161.     {
  162.         if (strtolower($name== 'partitionkey')
  163.             return $this->getPartitionKey();
  164.         if (strtolower($name== 'rowkey')
  165.             return $this->getRowKey();
  166.         if (strtolower($name== 'etag')
  167.             return $this->getEtag();
  168.  
  169.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties))
  170.         {
  171.             $this->setAzureProperty($name);            
  172.         }
  173.  
  174.         return $this->_dynamicProperties[strtolower($name)]->Value;
  175.     }
  176.     
  177.     /**
  178.      * Get an Azure property type
  179.      * 
  180.      * @param string $name Property name
  181.      * @return string Property type (Edm.xxxx)
  182.      */
  183.     public function getAzurePropertyType($name)
  184.     {
  185.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  186.             $this->setAzureProperty($name''$type);            
  187.         }
  188.         
  189.         return $this->_dynamicProperties[strtolower($name)]->Type;
  190.     }
  191.     
  192.     /**
  193.      * Get Azure values
  194.      * 
  195.      * @return array 
  196.      */
  197.     public function getAzureValues()
  198.     {
  199.         return array_merge(array_values($this->_dynamicProperties)parent::getAzureValues());
  200.     }
  201.     
  202.     /**
  203.      * Set Azure values
  204.      * 
  205.      * @param array $values 
  206.      * @param boolean $throwOnError Throw Microsoft_WindowsAzure_Exception when a property is not specified in $values?
  207.      * @throws Microsoft_WindowsAzure_Exception
  208.      */
  209.     public function setAzureValues($values array()$throwOnError false)
  210.     {
  211.         // Set parent values
  212.         parent::setAzureValues($valuesfalse);
  213.         
  214.         // Set current values
  215.         foreach ($values as $key => $value
  216.         {
  217.             $this->$key $value;
  218.         }
  219.     }
  220. }

Documentation generated on Thu, 26 Nov 2009 08:04:54 +0100 by phpDocumentor 1.4.3