Answer the question
In order to leave comments, you need to log in
Is it the right way to design an application in symfony 3?
Previously, I spent a very long time on Yii2, then migrated to Laravel5, now I need to start comprehending a new zen.
The question will be regarding the approach to application design (we do not consider DDD).
I organized a certain repository, which will be a wrapper over the Doctrine repository:
<?php
namespace AppBundle\Contract\Repository;
use AppBundle\Entity\Product;
/**
* Interface Product Repository
* @package AppBundle\Contract\Repository
*/
interface ProductRepository
{
public function findById($id);
public function findAll();
public function save(Product $product);
public function delete(Product $product);
}
<?php
namespace AppBundle\Repository;
use AppBundle\Contract\Repository\ProductRepository as ProductRepositoryInterface;
use AppBundle\Entity\Product;
class ProductRepository implements ProductRepositoryInterface
{
public function findById($id)
{
return 'findById';
}
public function findAll()
{
return 'findAll';
}
public function save(Product $product)
{
return 'save Product';
}
public function delete(Product $product)
{
return 'delete Product';
}
}
<?php
namespace AppBundle\Contract\Handler;
use AppBundle\Entity\Product;
interface ProductCreateHandler
{
public function process(Product $product);
}
<?php
namespace AppBundle\Services\Hendler;
use AppBundle\Contract\Handler\ProductCreateHandler as ProductCreateHandlerInterface;
use AppBundle\Contract\Repository\ProductRepository;
use AppBundle\Entity\Product;
class ProductCreateHandler implements ProductCreateHandlerInterface
{
protected $productRepository;
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
public function process(Product $product)
{
return 'Создать товар: ' . $product->getName();
}
}
services:
...
# Репозитории
app.product.repository:
class: AppBundle\Repository\TestProductRepository
# Сервисы
app.product.create.handler:
class: AppBundle\Services\Hendler\ProductCreateHandler
arguments: ['@app.product.repository']
Answer the question
In order to leave comments, you need to log in
services:
app.product_repository:
class: AppBundle\Repository\ProductRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments:
- AppBundle\Entity\Product
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question