コード例 #1
0
ファイル: Item.php プロジェクト: cstuder/nagios-plugins
 /**
  * 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);
 }
コード例 #2
0
ファイル: DynamoDbClient.php プロジェクト: noahkim/kowop
 /**
  * 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);
 }
コード例 #3
0
 public function testFactoryUsesValueIfAlreadyAttribute()
 {
     $a = Attribute::factory(array('foo' => 'bar'));
     $this->assertSame($a, Attribute::factory($a));
 }
コード例 #4
0
 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());
 }
コード例 #5
0
 /**
  * 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;
 }