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 - 2011, 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 - 2011, 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_AutoLoader
  39.  */
  40. require_once dirname(__FILE__'/../../AutoLoader.php';
  41.  
  42.  
  43. /**
  44.  * @category   Microsoft
  45.  * @package    Microsoft_WindowsAzure
  46.  * @subpackage Storage
  47.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  48.  * @license    http://phpazure.codeplex.com/license
  49.  */
  50. {   
  51.     /**
  52.      * Dynamic properties
  53.      * 
  54.      * @var array 
  55.      */
  56.     protected $_dynamicProperties = array();
  57.     
  58.     /**
  59.      * Magic overload for setting properties
  60.      * 
  61.      * @param string $name     Name of the property
  62.      * @param string $value    Value to set
  63.      */
  64.     public function __set($name$value{      
  65.         $this->setAzureProperty($name$valuenull);
  66.     }
  67.  
  68.     /**
  69.      * Magic overload for getting properties
  70.      * 
  71.      * @param string $name     Name of the property
  72.      */
  73.     public function __get($name{
  74.         return $this->getAzureProperty($name);
  75.     }
  76.     
  77.     /**
  78.      * Set an Azure property
  79.      * 
  80.      * @param string $name Property name
  81.      * @param mixed $value Property value
  82.      * @param string $type Property type (Edm.xxxx)
  83.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  84.      */
  85.     public function setAzureProperty($name$value ''$type null)
  86.     {
  87.         if (strtolower($name== 'partitionkey'{
  88.             $this->setPartitionKey($value);
  89.         else if (strtolower($name== 'rowkey'{
  90.             $this->setRowKey($value);
  91.         else if (strtolower($name== 'etag'{
  92.             $this->setEtag($value);
  93.         else {
  94.             if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  95.                 // Determine type?
  96.                 if (is_null($type)) {
  97.                     $type 'Edm.String';
  98.                     if (is_int($value)) {
  99.                         $type 'Edm.Int32';
  100.                     else if (is_float($value)) {
  101.                         $type 'Edm.Double';
  102.                     else if (is_bool($value)) {
  103.                         $type 'Edm.Boolean';
  104.                     else if ($value instanceof DateTime || $this->_convertToDateTime($value!== false{
  105.                         if (!$value instanceof DateTime{
  106.                             $value $this->_convertToDateTime($value);
  107.                         }
  108.                         $type 'Edm.DateTime';
  109.                     }
  110.                 }
  111.                 
  112.                 // Set dynamic property
  113.                 $this->_dynamicProperties[strtolower($name)= (object)array(
  114.                         'Name'  => $name,
  115.                         'Type'  => $type,
  116.                         'Value' => $value,
  117.                     );
  118.             }
  119.             
  120.             // Set type?
  121.             if (!is_null($type)) {
  122.                 $this->_dynamicProperties[strtolower($name)]->Type $type;
  123.                 
  124.                 // Try to convert the type
  125.                 if ($type == 'Edm.Int32' || $type == 'Edm.Int64'{
  126.                     $value intval($value);
  127.                 else if ($type == 'Edm.Double'{
  128.                     $value floatval($value);
  129.                 else if ($type == 'Edm.Boolean'{
  130.                     if (!is_bool($value)) {
  131.                         $value strtolower($value== 'true';
  132.                     }
  133.                 else if ($type == 'Edm.DateTime'{
  134.                     if (!$value instanceof DateTime{
  135.                         $value $this->_convertToDateTime($value);
  136.                     }
  137.                 }
  138.             }
  139.        
  140.             // Set value
  141.             $this->_dynamicProperties[strtolower($name)]->Value $value;
  142.         }
  143.         return $this;
  144.     }
  145.     
  146.     /**
  147.      * Set an Azure property type
  148.      * 
  149.      * @param string $name Property name
  150.      * @param string $type Property type (Edm.xxxx)
  151.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  152.      */
  153.     public function setAzurePropertyType($name$type 'Edm.String')
  154.     {
  155.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  156.             $this->setAzureProperty($name''$type);            
  157.         else {
  158.             $this->_dynamicProperties[strtolower($name)]->Type $type;   
  159.         }
  160.         return $this;
  161.     }
  162.     
  163.     /**
  164.      * Get an Azure property
  165.      * 
  166.      * @param string $name Property name
  167.      * @param mixed $value Property value
  168.      * @param string $type Property type (Edm.xxxx)
  169.      * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity 
  170.      */
  171.     public function getAzureProperty($name)
  172.     {
  173.         if (strtolower($name== 'partitionkey'{
  174.             return $this->getPartitionKey();
  175.         }
  176.         if (strtolower($name== 'rowkey'{
  177.             return $this->getRowKey();
  178.         }
  179.         if (strtolower($name== 'etag'{
  180.             return $this->getEtag();
  181.         }
  182.  
  183.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  184.             $this->setAzureProperty($name);            
  185.         }
  186.  
  187.         return $this->_dynamicProperties[strtolower($name)]->Value;
  188.     }
  189.     
  190.     /**
  191.      * Get an Azure property type
  192.      * 
  193.      * @param string $name Property name
  194.      * @return string Property type (Edm.xxxx)
  195.      */
  196.     public function getAzurePropertyType($name)
  197.     {
  198.         if (!array_key_exists(strtolower($name)$this->_dynamicProperties)) {
  199.             $this->setAzureProperty($name''$type);            
  200.         }
  201.         
  202.         return $this->_dynamicProperties[strtolower($name)]->Type;
  203.     }
  204.     
  205.     /**
  206.      * Get Azure values
  207.      * 
  208.      * @return array 
  209.      */
  210.     public function getAzureValues()
  211.     {
  212.         return array_merge(array_values($this->_dynamicProperties)parent::getAzureValues());
  213.     }
  214.     
  215.     /**
  216.      * Set Azure values
  217.      * 
  218.      * @param array $values 
  219.      * @param boolean $throwOnError Throw Microsoft_WindowsAzure_Exception when a property is not specified in $values?
  220.      * @throws Microsoft_WindowsAzure_Exception
  221.      */
  222.     public function setAzureValues($values array()$throwOnError false)
  223.     {
  224.         // Set parent values
  225.         parent::setAzureValues($valuesfalse);
  226.         
  227.         // Set current values
  228.         foreach ($values as $key => $value
  229.         {
  230.             $this->$key $value;
  231.         }
  232.     }
  233. }

Documentation generated on Wed, 18 May 2011 12:06:31 +0200 by phpDocumentor 1.4.3