Example #1
0
 /**
  * Create an item from a simplified array
  *
  * @param array  $attributes Array of attributes
  * @param string $tableName  Name of the table associated with the item
  *
  * @return self
  */
 public static function fromArray(array $attributes, $tableName = null)
 {
     foreach ($attributes as &$value) {
         $value = Attribute::factory($value);
     }
     return new self($attributes, $tableName);
 }
Example #2
0
 /**
  * Formats a value as a DynamoDB attribute.
  *
  * @param mixed  $value  The value to format for DynamoDB.
  * @param string $format The type of format (e.g. put, update).
  *
  * @return array The formatted value.
  */
 public function formatValue($value, $format = Attribute::FORMAT_PUT)
 {
     return Attribute::factory($value)->getFormatted($format);
 }
Example #3
0
 public function testFactoryUsesValueIfAlreadyAttribute()
 {
     $a = Attribute::factory(array('foo' => 'bar'));
     $this->assertSame($a, Attribute::factory($a));
 }
 public function testCanConvertToArray()
 {
     $key = array('HashKeyElement' => Attribute::factory('foo'), 'RangeKeyElement' => Attribute::factory(123));
     $deleteRequest = new DeleteRequest($key, 'table');
     $this->assertEquals(array('DeleteRequest' => array('Key' => array('HashKeyElement' => array('S' => 'foo'), 'RangeKeyElement' => array('N' => '123')))), $deleteRequest->toArray());
 }
 /**
  * Formats an array of attributes to the SDK's native data structure.
  *
  * @param string $entityClass
  * @param array $attributes
  * @param string $format
  *
  * @return array
  *
  * @throws \InvalidArgumentException
  *
  * @see \Aws\DynamoDb\DynamoDbClient::formatAttributes()
  */
 protected function formatAttributes($entityClass, array $attributes, $format = Attribute::FORMAT_PUT)
 {
     $entityClass = $this->getEntityClass($entityClass);
     $formatted = array();
     $mappings = $entityClass::getDataTypeMappings();
     foreach ($attributes as $attribute => $value) {
         if (isset($mappings[$attribute])) {
             $dataType = $mappings[$attribute];
             if (Attribute::FORMAT_PUT == $format) {
                 $formatted[$attribute] = array($dataType => $value);
             } else {
                 $formatted[$attribute] = array('Value' => array($dataType => $value));
             }
         } else {
             $formatted[$attribute] = Attribute::factory($value)->getFormatted($format);
         }
     }
     return $formatted;
 }