Advanced
Allow specific fields only
use Dustin\Encapsulation\ArrayEncapsulation;
class Product extends ArrayEncapsulation {
public function getAllowedFields(): ?array {
return ['name', 'stock', 'price', 'description'];
}
}$product = new Product();
$product->set('price', 12.34);
// Field 'price' is allowed
$product->set('metaTitle', 'My cool product');
// Will throw a NotAllowedFieldException since the field 'metaTitle' is not allowed.Nest encapsulations
Allow objects only in containers
Last updated