Answer the question
In order to leave comments, you need to log in
Is this solution of injection normal from an architectural point of view?
I'm just getting started with OOP. Can you please let me know if this is normal or is it different?
Here I have a repository class for products on the site
class ProductRepository
{
private $product; // Сюда попадает App\Entities\Product
public function __construct($product)
{
$this->product = $product;
}
public function get($id)
{
$data = DB::selectOne('SELECT * FROM products WHERE id = ?', [$id]);
if ($data) {
$data = $this->joinDependencies($data);
return new $this->product($data); // Тут я создаю новый объект сущности, заполненный данными и отдаю
}
return null;
}
}
$this->app->singleton(ProductRepository::class, function () {
return new ProductRepository(Product::class);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question