xpdodriver.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. * Copyright 2010-2015 by MODX, LLC.
  4. *
  5. * This file is part of xPDO.
  6. *
  7. * xPDO is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * xPDO is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * xPDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  18. * Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. /**
  21. * The xPDODriver class provides the baseline driver specific abstraction.
  22. *
  23. * @package xpdo
  24. * @subpackage om
  25. */
  26. /**
  27. * Provides driver specific members and methods for an xPDO instance.
  28. *
  29. * These are baseline members and methods that need to be loaded every
  30. * time an xPDO instance makes a connection. xPDODriver class implementations
  31. * are specific to a database driver and should include this base class in order
  32. * to extend it.
  33. *
  34. * @abstract
  35. * @package xpdo
  36. * @subpackage om
  37. */
  38. abstract class xPDODriver {
  39. /**
  40. * @var xPDO A reference to the XPDO instance using this manager.
  41. * @access public
  42. */
  43. public $xpdo= null;
  44. /**
  45. * @var array Describes the physical database types.
  46. */
  47. public $dbtypes= array ();
  48. /**
  49. * An array of DB constants/functions that represent timestamp values.
  50. * @var array
  51. */
  52. public $_currentTimestamps= array();
  53. /**
  54. * An array of DB constants/functions that represent date values.
  55. * @var array
  56. */
  57. public $_currentDates= array();
  58. /**
  59. * An array of DB constants/functions that represent time values.
  60. * @var array
  61. */
  62. public $_currentTimes= array();
  63. public $quoteChar = '';
  64. public $escapeOpenChar = '';
  65. public $escapeCloseChar = '';
  66. /**
  67. * Get an xPDODriver instance.
  68. *
  69. * @param xPDO $xpdo A reference to a specific xPDO instance.
  70. */
  71. public function __construct(xPDO &$xpdo) {
  72. if ($xpdo !== null && $xpdo instanceof xPDO) {
  73. $this->xpdo= & $xpdo;
  74. $this->xpdo->_quoteChar= $this->quoteChar;
  75. $this->xpdo->_escapeCharOpen= $this->escapeOpenChar;
  76. $this->xpdo->_escapeCharClose= $this->escapeCloseChar;
  77. }
  78. }
  79. /**
  80. * Gets the PHP field type based upon the specified database type.
  81. *
  82. * @access public
  83. * @param string $dbtype The database field type to convert.
  84. * @return string The associated PHP type
  85. */
  86. public function getPhpType($dbtype) {
  87. $phptype = 'string';
  88. if ($dbtype !== null) {
  89. foreach ($this->dbtypes as $type => $patterns) {
  90. foreach ($patterns as $pattern) {
  91. if (preg_match($pattern, $dbtype)) {
  92. $phptype = $type;
  93. break 2;
  94. }
  95. }
  96. }
  97. }
  98. return $phptype;
  99. }
  100. }