PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ProniconShorty/Model/Trim.php

https://bitbucket.org/nicohofmann/proniconshorty
PHP | 79 lines | 63 code | 16 blank | 0 comment | 4 complexity | 4837d44c527bc29399fc9e2a45729751 MD5 | raw file
  1. <?php
  2. namespace ProniconShorty\Model;
  3. use Zend\Db\TableGateway\AbstractTableGateway;
  4. use Zend\Db\Adapter\Adapter;
  5. use Zend\Db\ResultSet\HydratingResultSet;
  6. use Zend\Stdlib\Hydrator\HydratorInterface as Hydrator;
  7. class Trim extends AbstractTableGateway
  8. {
  9. private $entityHydrator;
  10. private $entity;
  11. public function setDbAdapter(Adapter $adapter)
  12. {
  13. $this->adapter = $adapter;
  14. }
  15. public function setTableName ($table)
  16. {
  17. $this->table = $table;
  18. }
  19. public function setEntityHydrator( Hydrator $entityHydrator)
  20. {
  21. $this->entityHydrator = $entityHydrator;
  22. }
  23. public function save(\ProniconShorty\Entity\Trim $entity)
  24. {
  25. $this->entity = $entity;
  26. if (!$this->entityHydrator)
  27. {
  28. throw new \Exception('Hydrator for entity is not set');
  29. }
  30. $set = $this->entityHydrator->extract($entity);
  31. return parent::insert($set);
  32. }
  33. public function setResultSetPrototype(\ProniconShorty\Entity\Trim $entity)
  34. {
  35. if (!$this->entityHydrator)
  36. {
  37. throw new \Exception('Hydrator for entity is not set');
  38. }
  39. $this->entity = $entity;
  40. $this->resultSetPrototype = new HydratingResultSet(
  41. $this->entityHydrator,
  42. $entity
  43. );
  44. }
  45. public function fetchAll ()
  46. {
  47. return $this->select();
  48. }
  49. public function getOrigUriByTrimPath($trimPath)
  50. {
  51. $rowset = $this->select(
  52. array(
  53. 'trim_path' => $trimPath,
  54. )
  55. );
  56. $entity = $rowset->current();
  57. if(!$entity)
  58. {
  59. throw new \Exception("Could not find row for trim path [$trimPath]");
  60. }
  61. return $entity->getOrigUrl();
  62. }
  63. }