Exemplo n.º 1
0
 public function getLocalSecondaryIndices()
 {
     $description = $this->describe();
     $lsiDefs = isset($description['LocalSecondaryIndexes']) ? $description['LocalSecondaryIndexes'] : null;
     if (!$lsiDefs) {
         return [];
     }
     $attrDefs = [];
     foreach ($description['AttributeDefinitions'] as $attributeDefinition) {
         $attrDefs[$attributeDefinition['AttributeName']] = $attributeDefinition['AttributeType'];
     }
     $lsis = [];
     foreach ($lsiDefs as $lsiDef) {
         $hashKey = null;
         $hashKeyType = null;
         $rangeKey = null;
         $rangeKeyType = null;
         foreach ($lsiDef['KeySchema'] as $keySchema) {
             switch ($keySchema['KeyType']) {
                 case "HASH":
                     $hashKey = $keySchema['AttributeName'];
                     $hashKeyType = $attrDefs[$hashKey];
                     break;
                 case "RANGE":
                     $rangeKey = $keySchema['AttributeName'];
                     $rangeKeyType = $attrDefs[$rangeKey];
                     break;
             }
         }
         $projectionType = $lsiDef['Projection']['ProjectionType'];
         $projectedAttributes = isset($lsiDef['Projection']['NonKeyAttributes']) ? $lsiDef['Projection']['NonKeyAttributes'] : [];
         $lsi = new DynamoDbIndex($hashKey, $hashKeyType, $rangeKey, $rangeKeyType, $projectionType, $projectedAttributes);
         $lsi->setName($lsiDef['IndexName']);
         $lsis[$lsi->getName()] = $lsi;
     }
     return $lsis;
 }