Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Application\Model;
- interface ProductManagerInterface
- {
- public function findOneBy($field, $value);
- public function findDeletedProducts();
- }
- namespace Application\Entity;
- use Application\Model\ProductManagerInterface;
- class ProductManager implements ProductManagerInterface
- {
- protected $em;
- protected $class;
- protected $repository;
- public function __construct(EntityManager $em, $class)
- {
- $this->em = $em;
- $this->class = $class;
- }
- public function findOneBy($field, $value)
- {
- return $this->getRepository()->findOneBy($field, $value);
- }
- public function findDeletedProducts()
- {
- return $this->getRepository()->findDeletedProducts();
- }
- public function getRepository()
- {
- return $this->em->getRepository($this->class);
- }
- }
- namespace Application\Entity\Repository;
- use Doctrine\ORM\EntityRepository;
- class ProductRepository extends EntityRepository
- {
- public function findDeletedProducts()
- {
- return $this->_em->createQuery('SELECT p FROM Application\Entity\Product p WHERE p.deleted = true');
- }
- }
- namespace Application\Controller;
- class ProductController extends Controller
- {
- public function showAction()
- {
- //DiC container, encargado de ensamblar el manager inyectando las dependencias
- $product = $this->get('product_manager')->findOneBy('slug', 'my-custom-product');
- return array('product' => $product);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement