model.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * ZeroBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 0.22
  11. */
  12. /**
  13. * model
  14. *
  15. * Factory of ZeroBin instance models.
  16. */
  17. class model
  18. {
  19. /**
  20. * Configuration.
  21. *
  22. * @var configuration
  23. */
  24. private $_conf;
  25. /**
  26. * Data storage.
  27. *
  28. * @var zerobin_abstract
  29. */
  30. private $_store = null;
  31. /**
  32. * Factory constructor.
  33. *
  34. * @param configuration $conf
  35. */
  36. public function __construct(configuration $conf)
  37. {
  38. $this->_conf = $conf;
  39. }
  40. /**
  41. * Get a paste, optionally a specific instance.
  42. *
  43. * @param string $pasteId
  44. * @return model_paste
  45. */
  46. public function getPaste($pasteId = null)
  47. {
  48. $paste = new model_paste($this->_conf, $this->_getStore());
  49. if ($pasteId !== null) $paste->setId($pasteId);
  50. return $paste;
  51. }
  52. /**
  53. * Gets, and creates if neccessary, a store object
  54. */
  55. private function _getStore()
  56. {
  57. if ($this->_store === null)
  58. {
  59. $this->_store = forward_static_call(
  60. array($this->_conf->getKey('class', 'model'), 'getInstance'),
  61. $this->_conf->getSection('model_options')
  62. );
  63. }
  64. return $this->_store;
  65. }
  66. }