PHP code example of thedomeffm / sapphire

1. Go to this page and download the library: Download thedomeffm/sapphire library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thedomeffm / sapphire example snippets




use Symfony\Component\Uid\UuidV4;
use TheDomeFfm\Sapphire\Attribute\DynamoClass;
use TheDomeFfm\Sapphire\Attribute\DynamoField;

#[DynamoClass('products')]
class Product
{
    #[DynamoField]
    private ?string $id;
    
    #[DynamoField]
    private ?string $name;
    
    #[DynamoField]
    private ?float $price;
    
    public function __construct() {
        $this->id = (string) UuidV4::v4();
    }
}



// ...

$product = new Product();
$product->name = $form['name'];
$product->prive = $form['price'];

$dm = new DynamoManager();

$putItem = $dm->preparePutAction($product);
$dynamoDbClient->putItem($putItem);



// ...

$dm = new DynamoManager();

$getItem = [
    'TableName' => $dm->getTableName(Product::class),
    'Key' => [
        'id' => ['S' => $id]
    ]
];

$product = $dynamoDbClient->getItem($getItem)->getItem();

$product = $dm->getObject($product, Product::class);

#[DynamoClass('CustomerDataSet')]
class Example {
    #[DynamoField]
    private ?string $id;

    #[DynamoField(arrayType: 'string')]
    private array $stringArray = [
        'one', 'two', 'five'
    ];

    #[DynamoField(arrayType: 'mixed')]
    private array $mixedArray = [
        'one', 2.5, 'eight'
    ];

    #[DynamoField(arrayType: 'number')]
    private array $numberArray = [
        1, 2.5, 3.01
    ];

    #[DynamoField(arrayType: 'binary')]
    private array $binArray = [
        1337, 'i like cheesecake', null, 'potato'
    ];

    public function __construct()
    {
        $this->id = (string) UuidV4::v4();
    }
    
    // ...
}

#[DynamoEmbeddedClass]
class Category
{
    #[DynamoField]
    private string $id;

    #[DynamoField]
    private ?string $name = null;

    public function __construct()
    {
        $this->id = (string) UuidV4::v4();
    }
}

#[DynamoClass('products')]
class Product
{
    #[DynamoField]
    private ?string $id;
    
    #[DynamoField]
    private ?string $name;
    
    #[DynamoField]
    private ?float $price;
    
    #[DynamoField]
    private ?Category $category;
    
    public function __construct() {
        $this->id = (string) UuidV4::v4();
    }
}

#[DynamoClass('customers')]
class Customer
{
    // ...
    
    #[DynamoField(isBinary: true)]
    public ?string $icon = null;
    
    // ...
}


$customer = new Customer();
// ...
$customer->icon = file_get_contents('user_icon.png');