Object maps

ObjectMappings will hold a key-based map of objects of a given class. These objects are not limited to encapsulations. You can choose any class you want.

Use inheritance

use Dustin\Encapsulation\AbstractObjectMapping;

class ProductMapping extends AbstractObjectMapping {

    protected function getType(): string {
        return Product::class;
    }
    
}

or a flexible class

use Dustin\Encapsulation\ObjectMapping;

$productMapping = ObjectMapping::create(Product::class);

Now you can create a map of Product-objects.

$productMapping = new ProductMapping();
// or
$productMapping = ObjectMapping::create(Product::class);

$productMapping->set('My1004', new Product()); // is ok
$productMapping->set('CU1005', new Customer()); // will throw an exception

Last updated