SHOW:
|
|
- or go back to the newest paste.
| 1 | namespace Application\Model; | |
| 2 | ||
| 3 | interface ProductManagerInterface | |
| 4 | {
| |
| 5 | public function findOneBy($field, $value); | |
| 6 | - | public function findProductsByUserId($id); |
| 6 | + | public function findDeletedProducts(); |
| 7 | } | |
| 8 | ||
| 9 | namespace Application\Entity; | |
| 10 | ||
| 11 | use Application\Model\ProductManagerInterface; | |
| 12 | ||
| 13 | class ProductManager implements ProductManagerInterface | |
| 14 | {
| |
| 15 | protected $em; | |
| 16 | protected $class; | |
| 17 | protected $repository; | |
| 18 | ||
| 19 | public function __construct(EntityManager $em, $class) | |
| 20 | {
| |
| 21 | $this->em = $em; | |
| 22 | $this->class = $class; | |
| 23 | } | |
| 24 | ||
| 25 | public function findOneBy($field, $value) | |
| 26 | {
| |
| 27 | return $this->getRepository()->findOneBy($field, $value); | |
| 28 | } | |
| 29 | ||
| 30 | public function findDeletedProducts() | |
| 31 | {
| |
| 32 | return $this->getRepository()->findDeletedProducts(); | |
| 33 | } | |
| 34 | ||
| 35 | public function getRepository() | |
| 36 | {
| |
| 37 | return $this->em->getRepository($this->class); | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | namespace Application\Entity\Repository; | |
| 42 | ||
| 43 | use Doctrine\ORM\EntityRepository; | |
| 44 | ||
| 45 | class ProductRepository extends EntityRepository | |
| 46 | {
| |
| 47 | public function findDeletedProducts() | |
| 48 | {
| |
| 49 | return $this->_em->createQuery('SELECT p FROM Application\Entity\Product p WHERE p.deleted = true');
| |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | namespace Application\Controller; | |
| 54 | ||
| 55 | class ProductController extends Controller | |
| 56 | {
| |
| 57 | public function showAction() | |
| 58 | {
| |
| 59 | //DiC container, encargado de ensamblar el manager inyectando las dependencias | |
| 60 | $product = $this->get('product_manager')->findOneBy('slug', 'my-custom-product');
| |
| 61 | return array('product' => $product);
| |
| 62 | } | |
| 63 | } |