<?php
namespace App\Factory\Products;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Products\Product;
class ProductFactory
{
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
public function create(array $defaults = array()): Product
{
// Create instance
$product = new Product();
// Loop defaults
foreach($defaults AS $k => $v)
{
// Format setter method
$setterName = "set" . ucfirst($k);
// If the setter method exists
if(method_exists($product, $setterName))
$product->$setterName($v);
}
return $product;
}
public function canBeDeleted(Product $product): bool
{
return !$product->getIsSpecial();
}
}