Source for file TableEntity.php
Documentation is available at TableEntity.php
* Copyright (c) 2009 - 2011, RealDolmen
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of RealDolmen nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @package Microsoft_WindowsAzure
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
* @license http://phpazure.codeplex.com/license
* @version $Id: BlobInstance.php 14561 2009-05-07 08:05:12Z unknown $
* @see Microsoft_AutoLoader
require_once dirname(__FILE__ ) . '/../../AutoLoader.php';
* @package Microsoft_WindowsAzure
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
* @license http://phpazure.codeplex.com/license
* @param string $partitionKey Partition key
* @param string $rowKey Row key
public function __construct($partitionKey = '', $rowKey = '')
* @azure Timestamp Edm.DateTime
* @azure Timestamp Edm.DateTime
public function setEtag($value = '')
$accessors = self::getAzureAccessors(get_class($this));
// Loop accessors and retrieve values
foreach ($accessors as $accessor) {
if ($accessor->EntityType == 'ReflectionProperty') {
$property = $accessor->EntityAccessor;
$returnValue[] = (object) array(
'Name' => $accessor->AzurePropertyName,
'Type' => $accessor->AzurePropertyType,
'Value' => $this->$property,
} else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'get') {
$method = $accessor->EntityAccessor;
$returnValue[] = (object) array(
'Name' => $accessor->AzurePropertyName,
'Type' => $accessor->AzurePropertyType,
'Value' => $this->$method(),
* @param boolean $throwOnError Throw Microsoft_WindowsAzure_Exception when a property is not specified in $values?
* @throws Microsoft_WindowsAzure_Exception
public function setAzureValues($values = array(), $throwOnError = false)
$accessors = self::getAzureAccessors(get_class($this));
// Loop accessors and set values
foreach ($accessors as $accessor) {
if (isset ($values[$accessor->AzurePropertyName])) {
if ($accessor->AzurePropertyType != '') {
switch (strtolower($accessor->AzurePropertyType)) {
$values[$accessor->AzurePropertyName] = intval($values[$accessor->AzurePropertyName]); break;
if ($values[$accessor->AzurePropertyName] == 'true' || $values[$accessor->AzurePropertyName] == '1')
$values[$accessor->AzurePropertyName] = true;
$values[$accessor->AzurePropertyName] = false;
$values[$accessor->AzurePropertyName] = floatval($values[$accessor->AzurePropertyName]); break;
$values[$accessor->AzurePropertyName] = $this->_convertToDateTime($values[$accessor->AzurePropertyName]); break;
if ($accessor->EntityType == 'ReflectionProperty') {
$property = $accessor->EntityAccessor;
$this->$property = $values[$accessor->AzurePropertyName];
} else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'set') {
$method = $accessor->EntityAccessor;
$this->$method($values[$accessor->AzurePropertyName]);
} else if ($throwOnError) {
* Get Azure accessors from class
* @param string $className Class to get accessors for
$azureAccessors = array();
$type = new ReflectionClass($className);
$properties = $type->getProperties();
foreach ($properties as $property) {
$accessor = self::getAzureAccessor($property);
$azureAccessors[] = $accessor;
$methods = $type->getMethods();
foreach ($methods as $method) {
$accessor = self::getAzureAccessor($method);
$azureAccessors[] = $accessor;
* Get Azure accessor from reflection member
* @param ReflectionProperty|ReflectionMethod$member
$docComment = $member->getDocComment();
// Check for Azure comment
if (strpos($docComment, '@azure') === false)
// Search for @azure contents
$commentLines = explode("\n", $docComment);
foreach ($commentLines as $commentLine) {
if (strpos($commentLine, '@azure') !== false) {
while (strpos($azureComment, ' ') !== false) {
// Fetch @azure properties
$azureProperties = explode(' ', $azureComment);
'EntityAccessor' => $member->getName(),
'AzurePropertyName' => $azureProperties[0],
'AzurePropertyType' => isset ($azureProperties[1]) ? $azureProperties[1] : ''
* Converts a string to a DateTime object. Returns false on failure.
* @param string $value The string value to parse
* @return DateTime|boolean
if ($value instanceof DateTime) {
if (substr($value, - 1) == 'Z') {
return new DateTime($value, new DateTimeZone('UTC'));
|