sathyashrayan

BlogMapperZendDbSqlRepository.php

Jul 3rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. // In module/Blog/src/Mapper/ZendDbSqlRepository.php:
  3.  
  4. namespace Blog\Mapper; //path changed
  5.  
  6. use InvalidArgumentException;
  7. use RuntimeException;
  8. use Zend\Db\Adapter\AdapterInterface;
  9. use Zend\Db\Sql\Sql;
  10.  
  11.  
  12. class ZendDbSqlRepository implements PostRepositoryInterface
  13. {
  14.     /**
  15.      * {@inheritDoc}
  16.      */
  17.    
  18.     private $db;
  19.    
  20.     public function __construct(AdapterInterface $db)
  21.     {
  22.         $this->db = $db;
  23.     }
  24.    
  25.     public function findAllPosts()
  26.     {
  27.         $sql    = new Sql($this->db); //changed from $this->dbAdapter
  28.         $select = $sql->select('posts');
  29.         $stmt   = $sql->prepareStatementForSqlObject($select);
  30.         $result = $stmt->execute();
  31.         return $result;
  32.     }
  33.  
  34.     /**
  35.      * {@inheritDoc}
  36.      * @throws InvalidArgumentException
  37.      * @throws RuntimeException
  38.      */
  39.     public function findPost($id)
  40.     {
  41.     }
  42. }
  43.  
  44. /*
  45. // In module/Blog/src/Model/ZendDbSqlRepository.php:
  46. namespace Blog\Mapper;
  47.  
  48. use InvalidArgumentException;
  49. use RuntimeException;
  50. use Zend\Db\Adapter\AdapterInterface;
  51. use Zend\Db\Sql\Sql;
  52. use Blog\Model\PostRepositoryInterface;
  53.  
  54. class ZendDbSqlRepository implements PostRepositoryInterface
  55. {
  56.     /**
  57.      * {@inheritDoc}
  58.      */
  59.    
  60.     private $db;
  61.    
  62.     public function __construct(AdapterInterface $db)
  63.     {
  64.         $this->db = $db;
  65.     }
  66.    
  67.     public function findAllPosts()
  68.     {
  69.         $sql    = new Sql($this->dbAdapter);
  70.         $select = $sql->select('posts');
  71.         $stmt   = $sql->prepareStatementForSqlObject($select);
  72.         $result = $stmt->execute();
  73.         return $result;
  74.     }
  75.  
  76.     /**
  77.      * {@inheritDoc}
  78.      * @throws InvalidArgumentException
  79.      * @throws RuntimeException
  80.      */
  81.     public function findPost($id)
  82.     {
  83.     }
  84. }*/
Add Comment
Please, Sign In to add comment