zerobin_db.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.15
  11. */
  12. /**
  13. * zerobin_db
  14. *
  15. * Model for DB access, implemented as a singleton.
  16. */
  17. class zerobin_db
  18. {
  19. /*
  20. * @access private
  21. * @static
  22. * @var PDO instance of database connection
  23. */
  24. private static $_db;
  25. /**
  26. * singleton instance
  27. *
  28. * @access private
  29. * @static
  30. * @var zerobin
  31. */
  32. private static $_instance = null;
  33. /**
  34. * enforce singleton, disable constructor
  35. *
  36. * Instantiate using {@link getInstance()}, zerobin is a singleton object.
  37. *
  38. * @access protected
  39. */
  40. protected function __construct() {}
  41. /**
  42. * enforce singleton, disable cloning
  43. *
  44. * Instantiate using {@link getInstance()}, zerobin is a singleton object.
  45. *
  46. * @access private
  47. */
  48. private function __clone() {}
  49. /**
  50. * get instance of singleton
  51. *
  52. * @access public
  53. * @static
  54. * @return zerobin
  55. */
  56. public static function getInstance($options)
  57. {
  58. // if needed initialize the singleton
  59. if(null === self::$_instance) {
  60. self::$_instance = new self;
  61. self::_init();
  62. }
  63. if (
  64. is_array($options) &&
  65. array_key_exists('dsn', $options) &&
  66. array_key_exists('usr', $options) &&
  67. array_key_exists('pwd', $options) &&
  68. array_key_exists('opt', $options)
  69. ) self::$_db = new PDO(
  70. $options['dsn'],
  71. $options['usr'],
  72. $options['pwd'],
  73. $options['opt']
  74. );
  75. return self::$_instance;
  76. }
  77. /**
  78. * Create a paste.
  79. *
  80. * @access public
  81. * @param string $pasteid
  82. * @param array $paste
  83. * @return int|false
  84. */
  85. public function create($pasteid, $paste)
  86. {
  87. }
  88. /**
  89. * Read a paste.
  90. *
  91. * @access public
  92. * @param string $pasteid
  93. * @return string
  94. */
  95. public function read($pasteid)
  96. {
  97. }
  98. /**
  99. * Delete a paste and its discussion.
  100. *
  101. * @access public
  102. * @param string $pasteid
  103. * @return void
  104. */
  105. public function delete($pasteid)
  106. {
  107. }
  108. /**
  109. * Test if a paste exists.
  110. *
  111. * @access public
  112. * @param string $dataid
  113. * @return void
  114. */
  115. public function exists($pasteid)
  116. {
  117. }
  118. /**
  119. * Create a comment in a paste.
  120. *
  121. * @access public
  122. * @param string $pasteid
  123. * @param string $parentid
  124. * @param string $commentid
  125. * @param array $comment
  126. * @return int|false
  127. */
  128. public function createComment($pasteid, $parentid, $commentid, $comment)
  129. {
  130. }
  131. /**
  132. * Read all comments of paste.
  133. *
  134. * @access public
  135. * @param string $pasteid
  136. * @return array
  137. */
  138. public function readComments($pasteid)
  139. {
  140. }
  141. /**
  142. * Test if a comment exists.
  143. *
  144. * @access public
  145. * @param string $dataid
  146. * @param string $parentid
  147. * @param string $commentid
  148. * @return void
  149. */
  150. public function existsComment($pasteid, $parentid, $commentid)
  151. {
  152. }
  153. /**
  154. * initialize zerobin
  155. *
  156. * @access private
  157. * @static
  158. * @return void
  159. */
  160. private static function _init()
  161. {
  162. }
  163. }